📄 main.s
字号:
; //delay_nus(16); //14.92us
; temp=wb>>i;
mov R16,R10
mov R17,R20
xcall lsr8
mov R22,R16
.dbline 96
; temp&=0x01;
andi R22,1
.dbline 97
; if(temp)
breq L54
X12:
.dbline 98
; SET_DS18B20; //释放总线
sbi 0x3,2
xjmp L55
L54:
.dbline 100
; else
; CLR_DS18B20; //强制拉低
cbi 0x3,2
L55:
.dbline 101
; Delay_Us(50); //30.38us
ldi R16,50
ldi R17,0
xcall _Delay_Us
.dbline 103
; //RLS_DS18B20; //释放总线
; SET_DS18B20; //释放总线
sbi 0x3,2
.dbline 104
; Delay_Us(4); //2.71us(大于1us就行了)
ldi R16,4
ldi R17,0
xcall _Delay_Us
.dbline 106
;
; }
L51:
.dbline 88
inc R20
L53:
.dbline 88
cpi R20,8
brlo L50
X13:
.dbline -2
L49:
.dbline 0 ; func end
xjmp pop_xgsetF00C
.dbsym r temp 22 c
.dbsym r i 20 c
.dbsym r wb 10 c
.dbend
.dbfunc e readTempDS18B20 _readTempDS18B20 fi
; x -> R10,R11
; tempH -> R12
; tempL -> R10
.even
_readTempDS18B20::
xcall push_xgset003C
.dbline -1
.dbline 114
; }
;
; /**********************************************************************
; functionName: unsigned int readTempDS18B20(void)
; description :读DS18B20温度
; **********************************************************************/
; unsigned int readTempDS18B20(void)
; {
.dbline 120
; unsigned char tempL,tempH;
; unsigned int x;
; //resetDS18B20();
; //writeByteDS18B20(0xcc); //跳过ROM
; //writeByteDS18B20(0x44); //启动温度转换
; Delay_Ms(1); //等待1ms
ldi R16,1
ldi R17,0
xcall _Delay_Ms
.dbline 121
; resetDS18B20();
xcall _resetDS18B20
.dbline 122
; writeByteDS18B20(0xcc); //跳过ROM
ldi R16,204
xcall _writeByteDS18B20
.dbline 123
; writeByteDS18B20(0xbe); //读数据
ldi R16,190
xcall _writeByteDS18B20
.dbline 124
; tempL=readByteDS18B20();
xcall _readByteDS18B20
mov R10,R16
.dbline 125
; tempH=readByteDS18B20();
xcall _readByteDS18B20
mov R12,R16
.dbline 126
; x=(tempH<<8)|tempL;
mov R11,R12
.dbline 127
; resetDS18B20();
xcall _resetDS18B20
.dbline 128
; writeByteDS18B20(0xcc); //跳过ROM
ldi R16,204
xcall _writeByteDS18B20
.dbline 129
; writeByteDS18B20(0x44); //启动温度转换
ldi R16,68
xcall _writeByteDS18B20
.dbline 130
; return(x);
movw R16,R10
.dbline -2
L56:
.dbline 0 ; func end
xjmp pop_xgset003C
.dbsym r x 10 i
.dbsym r tempH 12 c
.dbsym r tempL 10 c
.dbend
.dbfile H:\mega128开发板rev1.1\开发板程序\ds18b20温度+数码管显示程序\MAIN.C
.dbfunc e timer0_init _timer0_init fV
.even
_timer0_init::
.dbline -1
.dbline 20
; // Target : M128
; // Crystal: 8.0000Mhz
;
; #include <iom128v.h>
; #include <macros.h>
; #include "define.h"
; #include "delay.h"
; #include "initrialm128.h"
; #include "ds18b20.h"
;
; //#include
; void Coding_led(void);//8位数码管译码程序
;
;
; //TIMER0 initialize - prescale:1024
; // WGM: Normal
; // desired value: 3mSec
; // actual value: 2.976mSec (0.2%)
; void timer0_init(void)
; {
.dbline 21
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline 22
; ASSR = 0x00; //set async mode
out 0x30,R2
.dbline 23
; TCNT0 = 0xA3; //set count
ldi R24,163
out 0x32,R24
.dbline 24
; OCR0 = 0x1F;
ldi R24,31
out 0x31,R24
.dbline 25
; TCCR0 = 0x06; //start timer
ldi R24,6
out 0x33,R24
.dbline 26
; TIMSK |= 0x01; //timer interrupt sources
in R24,0x37
ori R24,1
out 0x37,R24
.dbline -2
L57:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 64
jmp _timer0_ovf_isr
.area text(rom, con, rel)
.dbfile H:\mega128开发板rev1.1\开发板程序\ds18b20温度+数码管显示程序\MAIN.C
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
st -y,R2
st -y,R3
st -y,R16
st -y,R17
st -y,R24
st -y,R25
st -y,R30
st -y,R31
in R2,0x3f
st -y,R2
.dbline -1
.dbline 31
; }
;
; #pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
; void timer0_ovf_isr(void)
; {
.dbline 32
; TCNT0 = 0xA3; //reload counter value
ldi R24,163
out 0x32,R24
.dbline 33
; if(sbit_led == 8)
lds R24,_sbit_led
cpi R24,8
brne L59
X14:
.dbline 34
; {
.dbline 35
; sbit_led = 0;
clr R2
sts _sbit_led,R2
.dbline 36
; }
L59:
.dbline 37
; SMG_PORT = 0XFF;
ldi R24,255
out 0x1b,R24
.dbline 38
; SMG_BIT_PORT = 0xff;
out 0x15,R24
.dbline 39
; SMG_BIT_PORT &=~ BIT(sbit_led);
lds R17,_sbit_led
ldi R16,1
xcall lsl8
mov R2,R16
com R2
in R3,0x15
and R3,R2
out 0x15,R3
.dbline 40
; SMG_PORT = led_disbuf[sbit_led];
ldi R24,<_led_disbuf
ldi R25,>_led_disbuf
lds R30,_sbit_led
clr R31
add R30,R24
adc R31,R25
ldd R2,z+0
out 0x1b,R2
.dbline 41
; sbit_led ++;
lds R24,_sbit_led
subi R24,255 ; addi 1
sts _sbit_led,R24
.dbline -2
L58:
.dbline 0 ; func end
ld R2,y+
out 0x3f,R2
ld R31,y+
ld R30,y+
ld R25,y+
ld R24,y+
ld R17,y+
ld R16,y+
ld R3,y+
ld R2,y+
reti
.dbend
.dbfunc e main _main fV
; n -> <dead>
.even
_main::
.dbline -1
.dbline 46
; }
;
;
; void main(void)
; {
.dbline 48
; unsigned char n;
; Init_Devices();
xcall _Init_Devices
.dbline 49
; timer0_init();
xcall _timer0_init
.dbline 50
; BELL_OFF();
sbi 0x3,4
xjmp L63
L62:
.dbline 53
;
; while(1)
; {
.dbline 54
; temperture = readTempDS18B20();
xcall _readTempDS18B20
xcall uint2fp
sts _temperture+1,R17
sts _temperture,R16
sts _temperture+2+1,R19
sts _temperture+2,R18
.dbline 55
; temperture = temperture * 0.0625*10;
ldi R16,<L65
ldi R17,>L65
xcall elpm32
movw R2,R16
movw R4,R18
ldi R16,<L66
ldi R17,>L66
xcall elpm32
ldi R24,<_temperture
ldi R25,>_temperture
st -y,R25
st -y,R24
xcall fpmule1x
movw R16,R2
movw R18,R4
xcall fpmule2
sts _temperture+1,R17
sts _temperture,R16
sts _temperture+2+1,R19
sts _temperture+2,R18
.dbline 56
; if(temperture < 1000)//ds18b20由于进中断后干扰时序,最好加上校验数据
movw R2,R16
movw R4,R18
ldi R16,<L69
ldi R17,>L69
xcall elpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R16,R2
movw R18,R4
xcall fpcmp2
brlt X24
xjmp L67
X24:
X15:
.dbline 57
; {
.dbline 58
; led_buf[0] = (int)temperture/10000000%10;
ldi R20,128
ldi R21,150
ldi R22,152
ldi R23,0
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
clr R18
sbrc R17,7
com R18
clr R19
sbrc R18,7
com R19
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32s
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall mod32s
sts _led_buf,R16
.dbline 59
; led_buf[1] = (int)temperture/1000000%10;
ldi R20,64
ldi R21,66
ldi R22,15
ldi R23,0
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
clr R18
sbrc R17,7
com R18
clr R19
sbrc R18,7
com R19
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32s
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall mod32s
sts _led_buf+1,R16
.dbline 60
; led_buf[2] = (int)temperture/100000%10;
ldi R20,160
ldi R21,134
ldi R22,1
ldi R23,0
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
clr R18
sbrc R17,7
com R18
clr R19
sbrc R18,7
com R19
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32s
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall mod32s
sts _led_buf+2,R16
.dbline 61
; led_buf[3] = (int)temperture/10000%10;
ldi R24,10000
ldi R25,39
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
movw R18,R24
xcall div16s
ldi R18,10
ldi R19,0
xcall mod16s
sts _led_buf+3,R16
.dbline 62
; led_buf[4] = (int)temperture/1000%10;
ldi R24,1000
ldi R25,3
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
movw R18,R24
xcall div16s
ldi R18,10
ldi R19,0
xcall mod16s
sts _led_buf+4,R16
.dbline 63
; led_buf[5] = (int)temperture/100%10;
ldi R24,100
ldi R25,0
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
movw R18,R24
xcall div16s
ldi R18,10
ldi R19,0
xcall mod16s
sts _led_buf+5,R16
.dbline 64
; led_buf[6] = (int)temperture/10%10;
ldi R24,10
ldi R25,0
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
movw R18,R24
xcall div16s
ldi R18,10
ldi R19,0
xcall mod16s
sts _led_buf+6,R16
.dbline 65
; led_buf[7] = (int)temperture%10;
ldi R24,10
ldi R25,0
lds R18,_temperture+2
lds R19,_temperture+2+1
lds R16,_temperture
lds R17,_temperture+1
xcall fpint
movw R18,R24
xcall mod16s
sts _led_buf+7,R16
.dbline 66
; }
L67:
.dbline 68
;
; if(led_buf[0] == 0)
lds R2,_led_buf
tst R2
brne L77
X16:
.dbline 69
; {
.dbline 70
; led_buf[0] = 25;
ldi R24,25
sts _led_buf,R24
.dbline 71
; if(led_buf[1] == 0)
lds R2,_led_buf+1
tst R2
brne L79
X17:
.dbline 72
; {
.dbline 73
; led_buf[1] = 25;
sts _led_buf+1,R24
.dbline 74
; if(led_buf[2] == 0)
lds R2,_led_buf+2
tst R2
brne L83
X18:
.dbline 75
; {
.dbline 76
; led_buf[2] = 25;
sts _led_buf+2,R24
.dbline 77
; if(led_buf[3] == 0)
lds R2,_led_buf+3
tst R2
brne L87
X19:
.dbline 78
; {
.dbline 79
; led_buf[3] = 25;
sts _led_buf+3,R24
.dbline 80
; if(led_buf[4] == 0)
lds R2,_led_buf+4
tst R2
brne L91
X20:
.dbline 81
; {
.dbline 82
; led_buf[4] = 25;
sts _led_buf+4,R24
.dbline 83
; if(led_buf[5] == 0)
lds R2,_led_buf+5
tst R2
brne L95
X21:
.dbline 84
; {
.dbline 85
; led_buf[5] = 25;
sts _led_buf+5,R24
.dbline 86
; if(led_buf[6] == 0)
lds R2,_led_buf+6
tst R2
brne L99
X22:
.dbline 87
; {
.dbline 88
; led_buf[6] = 25;
sts _led_buf+6,R24
.dbline 89
; }
L99:
.dbline 90
; }
L95:
.dbline 91
; }
L91:
.dbline 92
; }
L87:
.dbline 93
; }
L83:
.dbline 94
; }
L79:
.dbline 95
; }
L77:
.dbline 96
; Coding_led();
xcall _Coding_led
.dbline 97
; led_disbuf[6] &=~ BIT(7);
lds R24,_led_disbuf+6
andi R24,127
sts _led_disbuf+6,R24
.dbline 98
; }
L63:
.dbline 52
xjmp L62
X23:
.dbline -2
L61:
.dbline 0 ; func end
ret
.dbsym l n 1 c
.dbend
.dbfunc e Coding_led _Coding_led fV
; i -> R16
.even
_Coding_led::
.dbline -1
.dbline 104
;
; }
;
;
; void Coding_led(void)//8位数码管译码程序
; {
.dbline 106
; unsigned char i;
; for(i=0;i<8;i++)
clr R16
xjmp L108
L105:
.dbline 107
; {
.dbline 108
; led_disbuf[i] = led_table[led_buf[i]];
ldi R24,<_led_buf
ldi R25,>_led_buf
mov R30,R16
clr R31
add R30,R24
adc R31,R25
ldd R30,z+0
clr R31
ldi R24,<_led_table
ldi R25,>_led_table
add R30,R24
adc R31,R25
ldd R2,z+0
ldi R24,<_led_disbuf
ldi R25,>_led_disbuf
mov R30,R16
clr R31
add R30,R24
adc R31,R25
std z+0,R2
.dbline 109
; }
L106:
.dbline 106
inc R16
L108:
.dbline 106
cpi R16,8
brlo L105
X25:
.dbline -2
L104:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.area bss(ram, con, rel)
.dbfile H:\mega128开发板rev1.1\开发板程序\ds18b20温度+数码管显示程序\MAIN.C
_temperture::
.blkb 4
.dbfile H:\mega128开发板rev1.1\开发板程序\ds18b20温度+数码管显示程序\define.h
.dbsym e temperture _temperture D
_t0_ovfnum::
.blkb 1
.dbsym e t0_ovfnum _t0_ovfnum c
_led_buf::
.blkb 8
.dbsym e led_buf _led_buf A[8:8]c
_led_disbuf::
.blkb 8
.dbsym e led_disbuf _led_disbuf A[8:8]c
_sbit_led::
.blkb 1
.dbsym e sbit_led _sbit_led c
_s_wtemp::
.blkb 2
.dbsym e s_wtemp _s_wtemp I
_u_btemp::
.blkb 1
.dbsym e u_btemp _u_btemp c
_u_wtemp::
.blkb 2
.dbsym e u_wtemp _u_wtemp i
_u_ltemp::
.blkb 4
.dbsym e u_ltemp _u_ltemp l
.area lit(rom, con, rel)
L69:
.word 0x0,0x447a
L66:
.word 0x0,0x3d80
L65:
.word 0x0,0x4120
; }
;
;
;
;
;
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -