📄 ds18b20.s
字号:
.module ds18b20.c
.area data(ram, con, rel)
_led_7::
.blkb 2
.area idata
.byte 63,6
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 91,'O
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'f,'m
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 125,7
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 127,'o
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 64,0
.area data(ram, con, rel)
.dbfile G:\ds18b20\ds18b20.c
.dbsym e led_7 _led_7 A[12:12]c
_position::
.blkb 2
.area idata
.byte 7,11
.area data(ram, con, rel)
.dbfile G:\ds18b20\ds18b20.c
.blkb 2
.area idata
.byte 13,14
.area data(ram, con, rel)
.dbfile G:\ds18b20\ds18b20.c
.dbsym e position _position A[4:4]c
_led_buf::
.blkb 2
.area idata
.byte 0,0
.area data(ram, con, rel)
.dbfile G:\ds18b20\ds18b20.c
.blkb 2
.area idata
.byte 0,0
.area data(ram, con, rel)
.dbfile G:\ds18b20\ds18b20.c
.dbsym e led_buf _led_buf A[4:4]c
.area text(rom, con, rel)
.dbfile G:\ds18b20\ds18b20.c
.dbfunc e delay_1us _delay_1us fV
.even
_delay_1us::
.dbline -1
.dbline 18
; #include <iom16v.h>
; #include <macros.h>
;
; #define DQ_IN DDRA &= ~(1 << PA7) /*设置输入*/
; #define DQ_OUT DDRA |= (1 << PA7) /*设置输出*/
; #define DQ_CLR PORTA &= ~(1 << PA7) /*置低电平*/
; #define DQ_SET PORTA |= (1 << PA7) /*置高电平*/
; #define DQ_R PINA & (1 << PA7) /*读了电平*/
; unsigned char led_7[] = {0X3f,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0x40,0x00,};
; unsigned char flag; /*中断标志缓存*/
; unsigned char position[4]={0X07,0X0B,0X0D,0X0E};
; //unsigned char time[2];//显示时,分,
; unsigned char dis_buff[4]; // 显示缓冲区
; unsigned char posit;
; unsigned char led_buf[] = {0,0,0,0,}; /*显示信息*/
; /*********************delay function********************/
; void delay_1us(void) //1us延时函数
; {
.dbline 19
; asm("nop");
nop
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay_nus _delay_nus fV
; i -> R20,R21
; n -> R22,R23
.even
_delay_nus::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 23
; }
;
; void delay_nus(unsigned int n) //N us延时函数
; {
.dbline 24
; unsigned int i=0;
clr R20
clr R21
.dbline 25
; for (i=0;i<n;i++)
xjmp L6
L3:
.dbline 26
xcall _delay_1us
L4:
.dbline 25
subi R20,255 ; offset = 1
sbci R21,255
L6:
.dbline 25
cp R20,R22
cpc R21,R23
brlo L3
.dbline -2
L2:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 22 i
.dbend
.dbfunc e delay_1ms _delay_1ms fV
; i -> R16,R17
.even
_delay_1ms::
.dbline -1
.dbline 30
; delay_1us();
; }
;
; void delay_1ms(void) //1ms延时函数
; {
.dbline 32
clr R16
clr R17
xjmp L11
L8:
.dbline 32
L9:
.dbline 32
subi R16,255 ; offset = 1
sbci R17,255
L11:
.dbline 32
; unsigned int i;
; for (i=0;i<1140;i++);
cpi R16,116
ldi R30,4
cpc R17,R30
brlo L8
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e delay_nms _delay_nms fV
; i -> R20,R21
; n -> R22,R23
.even
_delay_nms::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 36
; }
;
; void delay_nms(unsigned int n) //N ms延时函数
; {
.dbline 37
; unsigned int i=0;
clr R20
clr R21
.dbline 38
; for (i=0;i<n;i++)
xjmp L16
L13:
.dbline 39
xcall _delay_1ms
L14:
.dbline 38
subi R20,255 ; offset = 1
sbci R21,255
L16:
.dbline 38
cp R20,R22
cpc R21,R23
brlo L13
.dbline -2
L12:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 22 i
.dbend
.dbfunc e ds1820_reset _ds1820_reset fc
; i -> R20
.even
_ds1820_reset::
xcall push_gset1
.dbline -1
.dbline 43
; delay_1ms();
; }
;
; /*DS18B20复位函数*/
; unsigned char ds1820_reset(void) {
.dbline 46
;
; unsigned char i;
; flag = SREG; /*中断保护*/
in R2,0x3f
sts _flag,R2
.dbline 47
; CLI(); /*关中断*/
cli
.dbline 48
; DQ_OUT;
sbi 0x1a,7
.dbline 49
; DQ_CLR;
cbi 0x1b,7
.dbline 50
; delay_nus(500); /*延时500uS(480-960)*/
ldi R16,500
ldi R17,1
xcall _delay_nus
.dbline 51
; DQ_SET;
sbi 0x1b,7
.dbline 52
; DQ_IN;
cbi 0x1a,7
.dbline 53
; delay_nus(80); /*延时80uS*/
ldi R16,80
ldi R17,0
xcall _delay_nus
.dbline 54
; i = DQ_R;
in R20,0x19
andi R20,128
.dbline 55
; delay_nus(490); /*延时500uS(保持>480uS)*/
ldi R16,490
ldi R17,1
xcall _delay_nus
.dbline 56
; if (flag & 0x80) { /*恢复中断状态*/
lds R2,_flag
sbrs R2,7
rjmp L18
.dbline 56
.dbline 57
; SEI();
sei
.dbline 58
; }
L18:
.dbline 59
; if (i) {
tst R20
breq L20
.dbline 59
.dbline 60
; return 0x00;
clr R16
xjmp L17
L20:
.dbline 62
; }
; else {
.dbline 63
; return 0x01;
ldi R16,1
.dbline -2
L17:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.dbfunc e ds1820_read_byte _ds1820_read_byte fc
; value -> R20
; i -> R22
.even
_ds1820_read_byte::
xcall push_gset2
.dbline -1
.dbline 68
; }
; }
;
; /*DS18B20字节读取函数*/
; unsigned char ds1820_read_byte(void) {
.dbline 71
;
; unsigned char i;
; unsigned char value = 0;
clr R20
.dbline 72
; flag = SREG; /*中断保护*/
in R2,0x3f
sts _flag,R2
.dbline 73
; CLI(); /*关中断*/
cli
.dbline 74
ldi R22,8
xjmp L26
L23:
.dbline 74
; for (i = 8; i != 0; i--) {
.dbline 75
; value >>= 1;
lsr R20
.dbline 76
; DQ_OUT;
sbi 0x1a,7
.dbline 77
; DQ_CLR;
cbi 0x1b,7
.dbline 78
; delay_nus(10);
ldi R16,10
ldi R17,0
xcall _delay_nus
.dbline 79
; DQ_SET;
sbi 0x1b,7
.dbline 80
; DQ_IN;
cbi 0x1a,7
.dbline 81
; delay_nus(10);
ldi R16,10
ldi R17,0
xcall _delay_nus
.dbline 82
; if (DQ_R) {
sbis 0x19,7
rjmp L27
.dbline 82
.dbline 83
; value|=0x80;
ori R20,128
.dbline 84
; }
L27:
.dbline 85
ldi R16,60
ldi R17,0
xcall _delay_nus
.dbline 86
L24:
.dbline 74
dec R22
L26:
.dbline 74
tst R22
brne L23
.dbline 87
; delay_nus(60); /*延时60uS*/
; }
; if (flag & 0x80) { /*恢复中断状态*/
lds R2,_flag
sbrs R2,7
rjmp L29
.dbline 87
.dbline 88
; SEI();
sei
.dbline 89
; }
L29:
.dbline 90
; return(value);
mov R16,R20
.dbline -2
L22:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r value 20 c
.dbsym r i 22 c
.dbend
.dbfunc e ds1820_write_byte _ds1820_write_byte fV
; i -> R20
; value -> R22
.even
_ds1820_write_byte::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 94
; }
;
; /*DS18B20字节写入函数*/
; void ds1820_write_byte(unsigned char value) {
.dbline 97
;
; unsigned char i;
; flag = SREG; /*中断保护*/
in R2,0x3f
sts _flag,R2
.dbline 98
; CLI(); /*关中断*/
cli
.dbline 99
ldi R20,8
xjmp L35
L32:
.dbline 99
; for (i = 8; i != 0; i--) {
.dbline 100
; DQ_OUT;
sbi 0x1a,7
.dbline 101
; DQ_CLR;
cbi 0x1b,7
.dbline 102
; delay_nus(4);
ldi R16,4
ldi R17,0
xcall _delay_nus
.dbline 103
; if (value & 0x01) {
sbrc R22,0
.dbline 103
.dbline 104
; DQ_SET;
sbi 0x1b,7
.dbline 105
; }
L36:
.dbline 106
ldi R16,80
ldi R17,0
xcall _delay_nus
.dbline 107
sbi 0x1b,7
.dbline 108
lsr R22
.dbline 109
L33:
.dbline 99
dec R20
L35:
.dbline 99
tst R20
brne L32
.dbline 110
lds R2,_flag
sbrs R2,7
rjmp L38
.dbline 110
.dbline 111
sei
.dbline 112
L38:
.dbline -2
L31:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r value 22 c
.dbend
.dbfunc e ds1820_start _ds1820_start fV
.even
_ds1820_start::
.dbline -1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -