|
楼主 |
发表于 2009-10-23 16:35:58
|
显示全部楼层
//***************测温******************
.DSEG
r_tested_h: .byte 1
r_tested_l: .byte 1
ts: .byte 1 ;tempreture0~120 of -20~100
tem: .byte 1 ;温度
td: .byte 1 ;小数部分
.CSEG
TEMP_UPDATE:
in temp,DDRB ;SETTING ICP1
andi temp,0xFE
out DDRB,temp
sbi PORTB,0
lds temp,ACSR
andi temp,~(1<<ACIC)
ldi temp,0 ;禁止t2,adc中断
sts TIMSK2,temp
;ini_t1:
clr temp
sts TCCR1A,temp
sts TCCR1B,temp
lds temp,TIMSK1
ori temp,1<<TOIE1|1<<ICIE1
sts TIMSK1,temp
clr temp
sts TCNT1H,temp
sts TCNT1L,temp
cbr FLAG,1<<t1_ovf ;清中断发生标记
cbr FLAG,1<<ac_comp_out
ldi temp,1<<ICES1|1<<CS10
sts TCCR1B,temp
sbi PORTC,CE
wait_cap: ;等待中断
wdr
sbrc FLAG,t1_ovf
ret
sbrs FLAG,ac_comp_out
rjmp wait_cap
cli
cbi PORTC,CE
in temp,DDRB
ori temp,0x01
out DDRB,temp
cbi PORTB,0
ldi temp,1<<TOIE2
sts TIMSK2,temp
ldi temp,0x00
sts TIMSK1,temp
clr r1 ;数字滤波
mov r2,xh
mov r3,xl
lsr r2
ror r3
lsr r2
ror r3
lds yh,r_tested_h
lds yl,r_tested_l
lsr yh
ror yl
lsr yh
ror yl
lds xh,r_tested_h
lds xl,r_tested_l
sub xl,yl
sbc xh,yh
add xl,r3
adc xh,r2
sts r_tested_h,xh
sts r_tested_l,xl
lds r2,temp_factor_h ;乘系数(<1)校准,电容选用比标准值偏大一点
lds r3,temp_factor_l
rcall MUL16
ldiw z,(2*t_r_table) ;查表
lds temp,ts
dec temp
ldi temp3,2
mul temp,temp3
add zl,r0
adc zh,r1
dec temp
find_match:
inc temp
lpm r7,z+
lpm r6,z+
mov r2,xh
mov r3,xl
sub r3,r7
sbc r2,r6
brlo find_match
dec temp ;插值计算
sts ts,temp
sbiw z,4
lpm r5,z+
lpm r4,z+
mov r0,r4
mov r1,r5
sub r1,xl
sbc r0,xh
clr r2
clr r3
sub r5,r7
sbc r4,r6
rcall DIV16 ;计算小数部分值
lds temp,ts
cpi temp,20
brsh plus_d ;正负调整
clr r0
clr r1
sub r1,r3
sbc r0,r2
mov r2,r0
mov r3,r1
plus_d:
rcall CONV3 ;二/十进制转换
sts td,r4
lds temp,ts
ldi temp3,20
sub temp,temp3
brmi negtive
rjmp plus
negtive:
com temp
plus:
mov r3,temp
clr r1
clr r2
rcall CONV1 ;二/十进制转换
sts tem,r7
ret
t_r_table:
.dw 65535,65535,65535,65535,65535,64271,60922,57771,54806,52014
.dw 49383,46904,44567,42363,40283,38319,36465,34713,33057,31491
.dw 30011,28610,27284,26028,24839,23711,22643,21629,20669,19757
.dw 18891,18069,17288,16546,15840,15170,14632,13925,13347,12797
.dw 12273,11774,11298,10845,10412,10000,9607,9231,8873,8530
.dw 8203,7891,7592,7307,7034,6773,6523,6284,6055,5836
.dw 5626,5425,5232,5048,4871,4700,4538,4382,4232,4088
.dw 3950,3817,3689,3567,3449,3336,3227,3123,3022,2926
.dw 2832,2743,2656,2573,2493,2416,2342,2270,2201,2135
.dw 2071,2009,1949,1892,1836,1783,1731,1681,1633,1586
.dw 1541,1498,1456,1415,1376,1338,1301,1266,1231,1198
.dw 1166,1135,1104,1075,1047,1020,993,968,943,918
.dw 895,872,850,829,809,788,0
//******************************* |
|