📄 1.s
字号:
.module _1.c
.area data(ram, con, rel)
_disp_table::
.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 'w,124
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 57,94
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'y,'q
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\18b20\1.c
.dbsym e disp_table _disp_table A[16:16]c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\18b20\1.c
.dbfunc e delay_1us _delay_1us fV
.even
_delay_1us::
.dbline -1
.dbline 44
; /* m818b20.c 2004-11-19
; 本程序为采用mega8 和18b20的温度采集程序
; 选用mega8内部8M RC震荡,18b20 数据线接pd6,数据线和vcc间接一4.7k上拉电阻
; 感谢dfgeoff 嗜血蜗牛提供的资料*/
;
; #include <iom16v.h> //和单片机类型相对应的头文件,选择Atmega8做实验;
; #include <macros.h>
; #define uchar unsigned char
; #define uint unsigned int
; void init_1820();
; write_1820(uchar x);
; uchar read_1820();
; void send_byte(uchar x);
; void delay(uint x);
; void disp_led(uchar buffer,uchar control);
; uchar disp_table[16] = {
; 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
; 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
; uchar dp;
; long count;
; #define LCD_EN_PORT PORTA //以下2个要设为同一个口
; #define LCD_EN_DDR DDRA
; #define LCD_RS_PORT PORTA //以下2个要设为同一个口
; #define LCD_RS_DDR DDRA
; #define LCD_DATA_PORT PORTA //以下3个要设为同一个口
; #define LCD_DATA_DDR DDRA //一定要用高4位
; #define LCD_DATA_PIN PINA
; #define LCD_RS (1<<0) // port0 out
; #define LCD_EN (1<<1) // port1 out
; #define LCD_DATA ((1<<4)|(1<<5)|(1<<6)|(1<<7)) //0xf0
; /*函数说明
; ------------------------------------------------------------------------------*/
; 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 delay_1us(void) //1us延时函数
; {
.dbline 45
; 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 49
; }
;
; void delay_nus(unsigned int n) //N us延时函数
; {
.dbline 50
; unsigned int i=0;
clr R20
clr R21
.dbline 51
; for (i=0;i<n;i++)
xjmp L6
L3:
.dbline 52
xcall _delay_1us
L4:
.dbline 51
subi R20,255 ; offset = 1
sbci R21,255
L6:
.dbline 51
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 56
; delay_1us();
; }
;
; void delay_1ms(void) //1ms延时函数
; {
.dbline 58
clr R16
clr R17
xjmp L11
L8:
.dbline 58
L9:
.dbline 58
subi R16,255 ; offset = 1
sbci R17,255
L11:
.dbline 58
; 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 62
; }
;
; void delay_nms(unsigned int n) //N ms延时函数
; {
.dbline 63
; unsigned int i=0;
clr R20
clr R21
.dbline 64
; for (i=0;i<n;i++)
xjmp L16
L13:
.dbline 65
xcall _delay_1ms
L14:
.dbline 64
subi R20,255 ; offset = 1
sbci R21,255
L16:
.dbline 64
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 LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 71
; delay_1ms();
; }
;
;
; /*----------------------------------------------------------------------------*/
; void LCD_init(void) //液晶初始化
; {
.dbline 72
; LCD_DATA_DDR|=LCD_DATA; //数据口方向为输出
in R24,0x1a
ori R24,240
out 0x1a,R24
.dbline 73
; LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
sbi 0x1a,1
.dbline 74
; LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
sbi 0x1a,0
.dbline 75
; LCD_write_command(0x28);
ldi R16,40
xcall _LCD_write_command
.dbline 76
; LCD_en_write();
xcall _LCD_en_write
.dbline 77
; delay_nus(40);
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline 78
; LCD_write_command(0x28); //4位显示
ldi R16,40
xcall _LCD_write_command
.dbline 79
; LCD_write_command(0x0c); //显示开
ldi R16,12
xcall _LCD_write_command
.dbline 80
; LCD_write_command(0x01); //清屏
ldi R16,1
xcall _LCD_write_command
.dbline 81
; delay_nms(2);
ldi R16,2
ldi R17,0
xcall _delay_nms
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 86
; }
;
; /*----------------------------------------------------------------------------*/
; void LCD_en_write(void) //液晶使能
; {
.dbline 87
; LCD_EN_PORT|=LCD_EN;
sbi 0x1b,1
.dbline 88
; delay_nus(1);
ldi R16,1
ldi R17,0
xcall _delay_nus
.dbline 89
; LCD_EN_PORT&=~LCD_EN;
cbi 0x1b,1
.dbline -2
L18:
.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 94
; }
;
; /*----------------------------------------------------------------------------*/
; void LCD_write_command(unsigned char command) //写指令
; {
.dbline 95
; delay_nus(16);
ldi R16,16
ldi R17,0
xcall _delay_nus
.dbline 96
; LCD_RS_PORT&=~LCD_RS; //RS=0
cbi 0x1b,0
.dbline 97
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 98
; LCD_DATA_PORT|=command&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 99
; LCD_en_write();
xcall _LCD_en_write
.dbline 100
; command=command<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 101
; LCD_DATA_PORT&=0x0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 102
; LCD_DATA_PORT|=command&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 103
; LCD_en_write();
xcall _LCD_en_write
.dbline -2
L19:
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 108
;
; }
; /*----------------------------------------------------------------------------*/
; void LCD_write_data(unsigned char data) //写数据
; {
.dbline 109
; delay_nus(16);
ldi R16,16
ldi R17,0
xcall _delay_nus
.dbline 110
; LCD_RS_PORT|=LCD_RS; //RS=1
sbi 0x1b,0
.dbline 111
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 112
; LCD_DATA_PORT|=data&0xf0; //写高四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 113
; LCD_en_write();
xcall _LCD_en_write
.dbline 114
; data=data<<4; //低四位移到高四位
mov R24,R20
andi R24,#0x0F
swap R24
mov R20,R24
.dbline 115
; LCD_DATA_PORT&=0X0f; //清高四位
in R24,0x1b
andi R24,15
out 0x1b,R24
.dbline 116
; LCD_DATA_PORT|=data&0xf0; //写低四位
mov R24,R20
andi R24,240
in R2,0x1b
or R2,R24
out 0x1b,R2
.dbline 117
; LCD_en_write();
xcall _LCD_en_write
.dbline -2
L20:
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 121
; }
; /*----------------------------------------------------------------------------*/
; void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
; {
.dbline 123
; unsigned char address;
; if (y == 0) address = 0x80 + x;
tst R20
brne L22
.dbline 123
mov R20,R22
subi R20,128 ; addi 128
xjmp L23
L22:
.dbline 124
; else address = 0xc0 + x;
mov R20,R22
subi R20,64 ; addi 192
L23:
.dbline 125
; LCD_write_command( address);
mov R16,R20
xcall _LCD_write_command
.dbline -2
L21:
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 129
; }
; /*----------------------------------------------------------------------------*/
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1
; {
.dbline 130
; LCD_set_xy( X, Y ); //写地址
mov R18,R10
mov R16,R22
xcall _LCD_set_xy
xjmp L26
L25:
.dbline 132
.dbline 133
movw R30,R20
ldd R16,z+0
xcall _LCD_write_data
.dbline 134
subi R20,255 ; offset = 1
sbci R21,255
.dbline 135
L26:
.dbline 131
; while (*s) // 写显示字符
movw R30,R20
ldd R2,z+0
tst R2
brne L25
.dbline -2
L24:
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 141
; {
; 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 142
; LCD_set_xy( X, Y ); //写地址
mov R18,R22
mov R16,R20
xcall _LCD_set_xy
.dbline 143
; LCD_write_data( data);
ldd R16,y+4
xcall _LCD_write_data
.dbline -2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -