📄 162.s
字号:
.module _162.c
.area text(rom, con, rel)
.dbfile D:\时钟芯片\1302\1302-162\162.c
.dbfunc e delay_ms _delay_ms fV
; a -> R20
; b -> R22
; n -> R16
.even
_delay_ms::
rcall push_gset2
.dbline -1
.dbline 5
; #include <io8515v.h>
; #include <macros.h>
; #include <162-1302.h>
; void delay_ms(unsigned char n)
; {
.dbline 7
; unsigned char a, b;
; for (a = 1; a<n; a++)
ldi R20,1
rjmp L5
L2:
.dbline 8
; for (b = 1; b; b++)
ldi R22,1
rjmp L9
L6:
.dbline 9
L7:
.dbline 8
inc R22
L9:
.dbline 8
tst R22
brne L6
L3:
.dbline 7
inc R20
L5:
.dbline 7
cp R20,R16
brlo L2
.dbline -2
L1:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r a 20 c
.dbsym r b 22 c
.dbsym r n 16 c
.dbend
.dbfunc e delay_us _delay_us fV
; b -> R20
; n -> R16,R17
.even
_delay_us::
rcall push_gset1
.dbline -1
.dbline 12
; ;
; }
; void delay_us(unsigned int n)
; {
.dbline 14
; unsigned char b;
; for (b = 1; b<n; b++)
ldi R20,1
rjmp L14
L11:
.dbline 15
L12:
.dbline 14
inc R20
L14:
.dbline 14
mov R2,R20
clr R3
cp R2,R16
cpc R3,R17
brlo L11
.dbline -2
L10:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r b 20 c
.dbsym r n 16 i
.dbend
.dbfunc e LCD_wait _LCD_wait fV
.even
_LCD_wait::
.dbline -1
.dbline 19
; ;
; }
;
; void LCD_wait(void) //等待LCD空闲
; {
.dbline 20
; LCD_DATA_PORT&=~BIT(7);
cbi 0x1b,7
.dbline 21
; PORTB&=~BIT(0);
cbi 0x18,0
.dbline 22
; PORTB|=BIT(1);
sbi 0x18,1
.dbline 23
; PORTB|=BIT(2);
sbi 0x18,2
L16:
.dbline 24
L17:
.dbline 24
; while(!(LCD_DATA_PIN &0x80)==0);
in R24,0x19
andi R24,128
brne L19
ldi R16,1
ldi R17,0
rjmp L20
L19:
clr R16
clr R17
L20:
cpi R16,0
cpc R16,R17
breq L16
X0:
.dbline 25
; LCD_DATA_DDR|=0xFF;
in R24,0x1a
ori R24,255
out 0x1a,R24
.dbline 26
; PORTB&=~BIT(2);
cbi 0x18,2
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e command_enable _command_enable fV
.even
_command_enable::
.dbline -1
.dbline 30
; }
;
; void command_enable() //写指令使能
; {
.dbline 31
; PORTB&=~(BIT(0)|BIT(1));
in R24,0x18
andi R24,252
out 0x18,R24
.dbline 32
; PORTB|=BIT(2);
sbi 0x18,2
.dbline 33
; asm("nop");
nop
.dbline 34
; PORTB&=~BIT(2);
cbi 0x18,2
.dbline -2
L21:
.dbline 0 ; func end
ret
.dbend
.dbfunc e data_enable _data_enable fV
.even
_data_enable::
.dbline -1
.dbline 37
; }
; void data_enable() //写数据使能
; {
.dbline 38
; PORTB|=BIT(0);
sbi 0x18,0
.dbline 39
; PORTB&=~BIT(1);
cbi 0x18,1
.dbline 40
; PORTB|=BIT(2);
sbi 0x18,2
.dbline 41
; asm("nop");
nop
.dbline 42
; PORTB&=~BIT(2);
cbi 0x18,2
.dbline -2
L22:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_set_xy _LCD_set_xy fV
; address -> R20
; y -> R20
; x -> R22
.even
_LCD_set_xy::
rcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 50
; }
;
; /*设置LCD显示的起始位置输入参数:x、y
; 显示字符串的位置,X:0-15,Y:0-1
; LCD第一行显示寄存器地址:0X80-0X8F
; LCD第一行显示寄存器地址:0XC0-0XCF*/
; void LCD_set_xy( unsigned char x, unsigned char y )
; {
.dbline 52
; unsigned char address;
; if (y==0)
tst R20
brne L24
.dbline 53
; address=0x80+x;
mov R20,R22
subi R20,128 ; addi 128
rjmp L25
L24:
.dbline 55
; else
; address=0xC0+x;
mov R20,R22
subi R20,64 ; addi 192
L25:
.dbline 56
; LCD_DATA_PORT=address; //输入开始显示地址
out 0x1b,R20
.dbline 57
; command_enable();
rcall _command_enable
.dbline 58
; delay_ms(10);
ldi R16,10
rcall _delay_ms
.dbline -2
L23:
rcall 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_char _LCD_write_char fV
; data -> R20
.even
_LCD_write_char::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 62
; }
; //写一个字符
; void LCD_write_char(unsigned char data)
; {
.dbline 63
; LCD_DATA_PORT=data;
out 0x1b,R20
.dbline 64
; data_enable();
rcall _data_enable
.dbline 65
; delay_ms(10);
ldi R16,10
rcall _delay_ms
.dbline -2
L26:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e LCD_write_string _LCD_write_string fV
; s -> R20,R21
; y -> R10
; x -> R22
.even
_LCD_write_string::
rcall push_gset3
mov R10,R18
mov R22,R16
ldd R20,y+6
ldd R21,y+7
.dbline -1
.dbline 69
; }
; //写一字符串
; void LCD_write_string(unsigned char x, unsigned char y,unsigned char *s)
; {
.dbline 70
; LCD_set_xy(x,y);
mov R18,R10
mov R16,R22
rcall _LCD_set_xy
rjmp L29
L28:
.dbline 72
.dbline 73
mov R30,R20
mov R31,R21
ldd R16,z+0
rcall _LCD_write_char
.dbline 74
subi R20,255 ; offset = 1
sbci R21,255
.dbline 75
L29:
.dbline 71
; while(*s)
mov R30,R20
mov R31,R21
ldd R2,z+0
tst R2
brne L28
.dbline -2
L27:
rcall 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 init_lcd _init_lcd fV
.even
_init_lcd::
.dbline -1
.dbline 80
; {
; LCD_write_char(*s);
; s++;
; }
;
; }
;
; void init_lcd() //初始化
; {
.dbline 81
; delay_ms(180); //等待30ms以上
ldi R16,180
rcall _delay_ms
.dbline 82
; LCD_DATA_PORT=0x38; //8位2行5×7点阵
ldi R24,56
out 0x1b,R24
.dbline 83
; command_enable();
rcall _command_enable
.dbline 84
; delay_us(100); //等待39us以上
ldi R16,100
ldi R17,0
rcall _delay_us
.dbline 85
; LCD_DATA_PORT=0x0C; //显示器开、光标开、闪烁关
ldi R24,12
out 0x1b,R24
.dbline 86
; command_enable();
rcall _command_enable
.dbline 87
; delay_us(100); //等待39us以上
ldi R16,100
ldi R17,0
rcall _delay_us
.dbline 88
; LCD_DATA_PORT=0x01; //清屏
ldi R24,1
out 0x1b,R24
.dbline 89
; command_enable();
rcall _command_enable
.dbline 90
; delay_ms(10); //等待1.53ms以上
ldi R16,10
rcall _delay_ms
.dbline 91
; LCD_DATA_PORT=0x06; //输入方式
ldi R24,6
out 0x1b,R24
.dbline 92
; command_enable();
rcall _command_enable
.dbline 93
; delay_ms(180); //初始化完毕
ldi R16,180
rcall _delay_ms
.dbline -2
L31:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -