📄 1820.s
字号:
.module _1820.c
.area text(rom, con, rel)
.dbfile E:\单片机\AVR程序\温度传感器\1820.c
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 42
;
; #include <iom16v.h>
; #include <macros.h>
;
; #define LCD_RS_PORT PORTA //以下2个要设为同一个口,4脚
; #define LCD_RS_DDR DDRA
; #define LCD_RW_PORT PORTA //以下2个要设为同一个口,5脚
; #define LCD_RW_DDR DDRA
; #define LCD_EN_PORT PORTA //以下2个要设为同一个口,6脚
; #define LCD_EN_DDR DDRA
;
;
; #define LCD_DATA_PORT PORTA //以下3个要设为同一个口
; #define LCD_DATA_DDR DDRA //一定要用高4位
; #define LCD_DATA_PIN PINA
;
;
; #define LCD_RS (1<<PA1) //
; #define LCD_RW (1<<PA2)
; #define LCD_EN (1<<PA3) //
; #define LCD_DATA ((1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7)) //
;
;
; /*--------------------------------------------------------------------------------------------------
; 液晶函数说明
; --------------------------------------------------------------------------------------------------*/
; void LCD_init(void);
; void LCD_en_write(void);
; void LCD_write_command(unsigned char command) ;
; void LCD_write_data(unsigned char data);
; void LCD_set_xy (unsigned char x, unsigned char y);
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
; void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data);
; void delay_nus(unsigned int n);
; void delay_nms(unsigned int n);
;
; /*--------------------------------------------------------------------------------------------------
; 液晶驱动程序
; --------------------------------------------------------------------------------------------------*/
;
; void LCD_init(void) //液晶初始化
; {
.dbline 43
; LCD_DATA_DDR|=LCD_DATA; //数据口方向为输出
in R24,0x1a
ori R24,240
out 0x1a,R24
.dbline 44
; LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
sbi 0x1a,3
.dbline 45
; LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
sbi 0x1a,1
.dbline 47
;
; LCD_RW_DDR|=LCD_RW;////////////////////////////////////
sbi 0x1a,2
.dbline 48
; LCD_RW_PORT&=~LCD_RW;/////////////////////////////////
cbi 0x1b,2
.dbline 50
;
; LCD_write_command(0x28);
ldi R16,40
xcall _LCD_write_command
.dbline 51
; LCD_en_write();
xcall _LCD_en_write
.dbline 52
; delay_nus(40);
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline 53
; LCD_write_command(0x28); //4位显示
ldi R16,40
xcall _LCD_write_command
.dbline 54
; LCD_write_command(0x0c); //显示开
ldi R16,12
xcall _LCD_write_command
.dbline 55
; LCD_write_command(0x01); //清屏
ldi R16,1
xcall _LCD_write_command
.dbline 56
; delay_nms(10);
ldi R16,10
ldi R17,0
xcall _delay_nms
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 61
;
; }
;
; void LCD_en_write(void) //液晶使能
; {
.dbline 62
; LCD_EN_PORT|=LCD_EN;
sbi 0x1b,3
.dbline 63
; delay_nus(1);
ldi R16,1
ldi R17,0
xcall _delay_nus
.dbline 64
; LCD_EN_PORT&=~LCD_EN;
cbi 0x1b,3
.dbline 65
; delay_nus(1);
ldi R16,1
ldi R17,0
xcall _delay_nus
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_write_command _LCD_write_command fV
; command -> R20
.even
_LCD_write_command::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 74
;
; }
;
; void LCD_write_command(unsigned char command)
; //_write_command(0x0b)不显示
; //LCD_write_command(0x0c)开显示
; //LCD_write_command(0x0d)开显示闪且闪
; //LCD_write_command(0x0e)开显示闪且不闪
; {
.dbline 75
; delay_nus(16);
ldi R16,16
ldi R17,0
xcall _delay_nus
.dbline 76
; LCD_RS_PORT&=~LCD_RS; //RS=0
cbi 0x1b,1
.dbline 77
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 78
; LCD_DATA_PORT|=command&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 79
; LCD_en_write();
xcall _LCD_en_write
.dbline 80
; command=command<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 81
; LCD_DATA_PORT&=0x0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 82
; LCD_DATA_PORT|=command&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 83
; LCD_en_write();
xcall _LCD_en_write
.dbline -2
L3:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r command 20 c
.dbend
.dbfunc e LCD_write_data _LCD_write_data fV
; data -> R20
.even
_LCD_write_data::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 88
;
; }
;
; void LCD_write_data(unsigned char data) //写数据
; {
.dbline 89
; delay_nus(16);
ldi R16,16
ldi R17,0
xcall _delay_nus
.dbline 90
; LCD_RS_PORT|=LCD_RS; //RS=1
sbi 0x1b,1
.dbline 91
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 92
; LCD_DATA_PORT|=data&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 93
; LCD_en_write();
xcall _LCD_en_write
.dbline 94
; data=data<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 95
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 96
; LCD_DATA_PORT|=data&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 97
; LCD_en_write();
xcall _LCD_en_write
.dbline -2
L4:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e LCD_set_xy _LCD_set_xy fV
; address -> R20
; y -> R20
; x -> R22
.even
_LCD_set_xy::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 103
;
; }
;
;
; void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
; {
.dbline 105
; unsigned char address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L6
.dbline 105
mov R20,R22
subi R20,128 ; addi 128
xjmp L7
L6:
.dbline 106
; else address = 0xc0 + x;
mov R20,R22
subi R20,64 ; addi 192
L7:
.dbline 107
; LCD_write_command( address);
mov R16,R20
xcall _LCD_write_command
.dbline -2
L5:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r address 20 c
.dbsym r y 20 c
.dbsym r x 22 c
.dbend
.dbfunc e LCD_write_string _LCD_write_string fV
; s -> R20,R21
; Y -> R10
; X -> R22
.even
_LCD_write_string::
xcall push_gset3
mov R10,R18
mov R22,R16
ldd R20,y+6
ldd R21,y+7
.dbline -1
.dbline 112
;
; }
;
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1
; {
.dbline 113
; LCD_set_xy( X, Y ); //写地址
mov R18,R10
mov R16,R22
xcall _LCD_set_xy
xjmp L10
L9:
.dbline 115
.dbline 116
movw R30,R20
ldd R16,z+0
xcall _LCD_write_data
.dbline 117
subi R20,255 ; offset = 1
sbci R21,255
.dbline 118
L10:
.dbline 114
; while (*s) // 写显示字符
movw R30,R20
ldd R2,z+0
tst R2
brne L9
.dbline -2
L8:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r s 20 pc
.dbsym r Y 10 c
.dbsym r X 22 c
.dbend
.dbfunc e LCD_write_char _LCD_write_char fV
; data -> y+4
; Y -> R22
; X -> R20
.even
_LCD_write_char::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 123
; {
; LCD_write_data( *s );
; s ++;
; }
;
; }
;
; void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) //列x=0~15,行y=0,1
; {
.dbline 124
; LCD_set_xy( X, Y ); //写地址
mov R18,R22
mov R16,R20
xcall _LCD_set_xy
.dbline 125
; LCD_write_data( data);
ldd R16,y+4
xcall _LCD_write_data
.dbline -2
L12:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l data 4 c
.dbsym r Y 22 c
.dbsym r X 20 c
.dbend
.dbfunc e delayUs _delayUs fV
; temp -> R16
.even
_delayUs::
.dbline -1
.dbline 191
;
; }
;
; /*--------------------------------------------------------------------------------------------------
; 液晶驱动程序
; --------------------------------------------------------------------------------------------------*/
;
;
;
;
;
;
;
; #define uchar unsigned char
; #define uint unsigned int
; #define ulong unsigned long
; /******************************************************************************
; //全局变量
; ******************************************************************************/
;
;
;
; /******************************************************************************
; DS18B20驱动程序
; ******************************************************************************/
;
; /********************************************************************************/
; // 下面为DS18B20温度传感模块 //
; /********************************************************************************/
; /********************************************************************************
; 位变量操作宏定义
; ********************************************************************************/
; #define BIT_SET(a,b) a|=BIT(b)
; #define BIT_CLR(a,b) a&=~BIT(b)
; #define BIT_INV(a,b) a^=BIT(b)
; #define BIT_STATUS(a,b) a&BIT(b)
; /********************************************************************************
; DS18B20操作定义
; ********************************************************************************/
; #define CLR_DS18B20 BIT_CLR(PORTB,PB1) //数据线强制拉低
; #define SET_DS18B20 BIT_SET(PORTB,PB1) //数据线强制拉高,上拉
; #define HLD_DS18B20 BIT_SET(DDRB,PB1) //Mega16控制总线
; #define RLS_DS18B20 BIT_CLR(DDRB,PB1) //释放总线
; #define STU_DS18B20 BIT_STATUS(PINB,PB1) //数据线的状态
;
;
; /**********************************************************************
; functionName: void delayUs(BYTE temp)
; description :延时函数 晶振频率:7.3728MHZ
; delayUs(1); //2.71us
; delayUs(2); //3.53us
; delayUs(4); //5.15us
; delayUs(8); //8.41us
; delayUs(16); //14.92us
; delayUs(32); //27.94us
; delayUs(64); //53.98us
; delayUs(128); //106.07us
; delayUs(255); //209.42us
; delayUs(18); //16.55us
; delayUs(34); //29.57us
; delayUs(35); //30.38us
; delayUs(100); //83.28
; _NOP(); //0.14us
; **********************************************************************/
; void delayUs(unsigned char temp)
; {
L14:
.dbline 192
L15:
.dbline 192
; while(temp--);
mov R2,R16
clr R3
subi R16,1
tst R2
brne L14
.dbline -2
L13:
.dbline 0 ; func end
ret
.dbsym r temp 16 c
.dbend
.dbfunc e resetDS18B20 _resetDS18B20 fc
; errTime -> R20
.even
_resetDS18B20::
xcall push_gset1
.dbline -1
.dbline 200
; }
;
; /**********************************************************************
; functionName: BYTE resetDS18B20(void)
; description :DS18B20初始化1
; **********************************************************************/
; unsigned char resetDS18B20(void)
; {
.dbline 201
; unsigned char errTime=0;
clr R20
.dbline 202
; RLS_DS18B20; //释放总线
cbi 0x17,1
.dbline 203
; _NOP();
nop
.dbline 204
; HLD_DS18B20; //Maga16控制总线
sbi 0x17,1
.dbline 205
; CLR_DS18B20; //强制拉低
cbi 0x18,1
.dbline 206
; delayUs(255); //209.42us
ldi R16,255
xcall _delayUs
.dbline 207
; delayUs(255); //209.42us
ldi R16,255
xcall _delayUs
.dbline 208
; delayUs(255); //83.28us
ldi R16,255
xcall _delayUs
.dbline 210
; //以上的三个延时大于480us
; RLS_DS18B20; //释放总线,总线自动上拉
cbi 0x17,1
.dbline 211
; _NOP();
nop
xjmp L19
L18:
.dbline 213
; while(STU_DS18B20)
; {
.dbline 214
; delayUs(5); //5.15us
ldi R16,5
xcall _delayUs
.dbline 215
; errTime++;
inc R20
.dbline 216
; if(errTime>20)
ldi R24,20
cp R24,R20
brsh L21
.dbline 217
; return(0x00); //如果等带大于约 5.15us*20就返回0x00,报告复位失败(实际上只要等待15-60us)
clr R16
xjmp L17
L21:
.dbline 218
L19:
.dbline 212
sbic 0x16,1
rjmp L18
.dbline 219
; }
; errTime=0;
clr R20
xjmp L24
L23:
.dbline 221
; while(!(STU_DS18B20))
; {
.dbline 222
; delayUs(5); //5.15us
ldi R16,5
xcall _delayUs
.dbline 223
; errTime++;
inc R20
.dbline 224
; if(errTime>50)
ldi R24,50
cp R24,R20
brsh L26
.dbline 225
; return(0x00); //如果等带大于约 5.15us*50就返回0x00,报告复位失败(实际上只要等待60-240us)
clr R16
xjmp L17
L26:
.dbline 226
L24:
.dbline 220
sbis 0x16,1
rjmp L23
.dbline 227
; }
; return(0xff);
ldi R16,255
.dbline -2
L17:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r errTime 20 c
.dbend
.dbfunc e readByteDS18B20 _readByteDS18B20 fc
; retVal -> R20
; i -> R22
.even
_readByteDS18B20::
xcall push_gset2
.dbline -1
.dbline 236
; }
;
;
; /**********************************************************************
; functionName: BYTE readByteDS18B20(void)
; description :读DS18B20一个字节2
; **********************************************************************/
; unsigned char readByteDS18B20(void)
; {
.dbline 238
; unsigned char i;
; unsigned char retVal=0;
clr R20
.dbline 239
; RLS_DS18B20; //释放总线
cbi 0x17,1
.dbline 240
; for(i=8;i>0;i--)
ldi R22,8
xjmp L32
L29:
.dbline 241
; {
.dbline 242
; retVal>>=1;
lsr R20
.dbline 243
; HLD_DS18B20; //Maga16控制总线
sbi 0x17,1
.dbline 244
; CLR_DS18B20; //强制拉低
cbi 0x18,1
.dbline 245
; NOP();
nop
.dbline 246
; NOP();
nop
.dbline 247
; NOP();
nop
.dbline 248
; NOP();
nop
.dbline 249
; NOP();
nop
.dbline 250
; NOP();
nop
.dbline 251
; NOP();
nop
.dbline 252
; NOP(); //延时大于1us
nop
.dbline 253
; RLS_DS18B20; //释放总线,DS18B20会将总线强制拉低
cbi 0x17,1
.dbline 254
; NOP();
nop
.dbline 255
; NOP();
nop
.dbline 256
; NOP();
nop
.dbline 257
; if(STU_DS18B20)
sbis 0x16,1
rjmp L33
.dbline 258
; retVal|=0x80;
ori R20,128
L33:
.dbline 261
ldi R16,20
xcall _delayUs
.dbline 262
ldi R16,30
xcall _delayUs
.dbline 263
cbi 0x17,1
.dbline 264
ldi R16,45
xcall _delayUs
.dbline 266
L30:
.dbline 240
dec R22
L32:
.dbline 240
clr R2
cp R2,R22
brlo L29
.dbline 267
;
;
; delayUs(20); //14.92us
; delayUs(30); //14.92us
; RLS_DS18B20; //释放总线
; delayUs(45); //30.38us
;
; }
; delayUs(1); //2.71us(大于1us就行了)
ldi R16,1
xcall _delayUs
.dbline 268
; return(retVal);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -