📄 12864.s
字号:
.module _12864.c
.area text(rom, con, rel)
.dbfile G:\test\lcd\3\12864.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 25
; //ICC-AVR application builder : 2005-7-21 15:31:35
; // Target : M32
; // Crystal: internal RC:1.0000Mhz
;
; //description:液晶横放显示汉字
;
; #include <iom16v.h>
; #include <macros.h>
;
; /* lcd port define: connect to PORTB of MEGA32L */
; #define RS 0
; #define RW 1
; #define E 2
; #define CSA 3
; #define CSB 4
; #define RST 5
;
; /******************************************************************** */
; #define SETBIT(x,y) (x|=(1<<y)) //set bit y in byte x
; #define CLRBIT(x,y) (x&=(~(1<<y))) //clear bit y in byte x
; #define CHKBIT(x,y) (x&(1<<y)) //check bit y in byte x
; /******************************************************************** */
;
; void port_init(void)
; {
.dbline 26
; PORTA = 0xFF;
ldi R24,255
out 0x1b,R24
.dbline 27
; DDRA = 0xFF;
out 0x1a,R24
.dbline 28
; PORTB = 0xFF;
out 0x18,R24
.dbline 29
; DDRB = 0xFF;
out 0x17,R24
.dbline 30
; PORTC = 0xFF;
out 0x15,R24
.dbline 31
; DDRC = 0xFF;
out 0x14,R24
.dbline 32
; PORTD = 0xFF;
out 0x12,R24
.dbline 33
; DDRD = 0xFF;
out 0x11,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 38
; }
;
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
.dbline 40
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 41
; port_init();
xcall _port_init
.dbline 43
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 44
; GICR = 0x00;
out 0x3b,R2
.dbline 45
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 46
; SEI(); //re-enable interrupts
sei
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e CheckState _CheckState fV
; dat -> <dead>
.even
_CheckState::
.dbline -1
.dbline 54
; //all peripherals are now initialised
; }
;
; /*-----------------------------------------------------
; 状态检查函数,判断是否处于忙状态
; -------------------------------------------------------*/
; void CheckState()
; {
.dbline 56
; unsigned char dat;
; CLRBIT(PORTB,RS); //RS=0
cbi 0x18,0
.dbline 57
; SETBIT(PORTB,RW); //RW=1
sbi 0x18,1
.dbline 58
; DDRA=0x00; // portA as input
clr R2
out 0x1a,R2
L4:
.dbline 60
; do
; {
.dbline 61
; SETBIT(PORTB,E);
sbi 0x18,2
.dbline 62
; CLRBIT(PORTB,E);
cbi 0x18,2
.dbline 63
; }
L5:
.dbline 64
; while (PINA&0x80);
sbic 0x19,7
rjmp L4
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym l dat 1 c
.dbend
.dbfunc e WriteByte _WriteByte fV
; dat -> R20
.even
_WriteByte::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 72
; }
;
; /*----------------------------------------------
; 写显示数据
; 形参dat:显示数据
; -------------------------------------------------*/
; void WriteByte(unsigned char dat)
; {
.dbline 73
; CheckState();
xcall _CheckState
.dbline 74
; SETBIT(PORTB,RS);
sbi 0x18,0
.dbline 75
; CLRBIT(PORTB,RW);
cbi 0x18,1
.dbline 76
; DDRA=0xff; //portA as output
ldi R24,255
out 0x1a,R24
.dbline 77
; PORTA=dat;
out 0x1b,R20
.dbline 78
; SETBIT(PORTB,E);
sbi 0x18,2
.dbline 79
; CLRBIT(PORTB,E);
cbi 0x18,2
.dbline -2
L7:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dat 20 c
.dbend
.dbfunc e SendCommandToLCD _SendCommandToLCD fV
; command -> R20
.even
_SendCommandToLCD::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 88
; }
;
;
; /*-------------------------------------------------
; 向LCD发送命令
; 形参command :命令
; --------------------------------------------------*/
; void SendCommandToLCD(unsigned char command)
; {
.dbline 89
; CheckState();
xcall _CheckState
.dbline 90
; PORTB&=0xfc; //RS=0,RW=0
in R24,0x18
andi R24,252
out 0x18,R24
.dbline 91
; DDRA=0xff; //portA as output
ldi R24,255
out 0x1a,R24
.dbline 92
; PORTA=command;
out 0x1b,R20
.dbline 93
; SETBIT(PORTB,E);
sbi 0x18,2
.dbline 94
; CLRBIT(PORTB,E);
cbi 0x18,2
.dbline -2
L8:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r command 20 c
.dbend
.dbfunc e SetLine _SetLine fV
; line -> R20
.even
_SetLine::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 100
; }
;
; /*-------------------------------------------------*/
; //设定行地址(页)--X 0-7
; void SetLine(unsigned char line)
; {
.dbline 101
; line=line & 0x07; // 0<=line<=7
andi R20,7
.dbline 102
; line=line|0xb8; //1011 1xxx
ori R20,184
.dbline 103
; SendCommandToLCD(line);
mov R16,R20
xcall _SendCommandToLCD
.dbline -2
L9:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r line 20 c
.dbend
.dbfunc e SetColumn _SetColumn fV
; column -> R20
.even
_SetColumn::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 107
; }
; //设定列地址--Y 0-63
; void SetColumn(unsigned char column)
; {
.dbline 108
; column=column &0x3f; // 0=<column<=63
andi R20,63
.dbline 109
; column=column | 0x40; //01xx xxxx
ori R20,64
.dbline 110
; SendCommandToLCD(column);
mov R16,R20
xcall _SendCommandToLCD
.dbline -2
L10:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r column 20 c
.dbend
.dbfunc e SetStartLine _SetStartLine fV
; startline -> R20
.even
_SetStartLine::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 115
; }
;
; //设定显示开始行--XX
; void SetStartLine(unsigned char startline) //0--63
; {
.dbline 116
; startline=startline & 0x07; //??0x3f
andi R20,7
.dbline 117
; startline=startline|0xc0; //1100 0000
ori R20,192
.dbline 118
; SendCommandToLCD(startline);
mov R16,R20
xcall _SendCommandToLCD
.dbline -2
L11:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r startline 20 c
.dbend
.dbfunc e SetOnOff _SetOnOff fV
; onoff -> R20
.even
_SetOnOff::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 122
; }
; //开关显示
; void SetOnOff(unsigned char onoff)
; {
.dbline 123
; onoff=0x3e | onoff; //0011 111x
ori R20,62
.dbline 124
; SendCommandToLCD(onoff);
mov R16,R20
xcall _SendCommandToLCD
.dbline -2
L12:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r onoff 20 c
.dbend
.dbfunc e Clr_Scr _Clr_Scr fV
; k -> R20
; j -> R22
.even
_Clr_Scr::
xcall push_gset2
.dbline -1
.dbline 129
; }
;
; /*------------------清除内存---------------*/
; void Clr_Scr()
; {
.dbline 131
; unsigned char j,k;
; PORTB|=0x18; //CSA=1,CSB=1
in R24,0x18
ori R24,24
out 0x18,R24
.dbline 132
; SetLine(0);
clr R16
xcall _SetLine
.dbline 133
; SetColumn(0);
clr R16
xcall _SetColumn
.dbline 134
; for(k=0;k<8;k++)
clr R20
xjmp L17
L14:
.dbline 135
; {
.dbline 136
; SetLine(k); //第K页
mov R16,R20
xcall _SetLine
.dbline 137
; for(j=0;j<64;j++)
clr R22
xjmp L21
L18:
.dbline 138
clr R16
xcall _WriteByte
L19:
.dbline 137
inc R22
L21:
.dbline 137
cpi R22,64
brlo L18
.dbline 139
L15:
.dbline 134
inc R20
L17:
.dbline 134
cpi R20,8
brlo L14
.dbline -2
L13:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r k 20 c
.dbsym r j 22 c
.dbend
.dbfunc e init_lcd _init_lcd fV
.even
_init_lcd::
.dbline -1
.dbline 144
; WriteByte(0x00);
; }
; }
;
; /*------------------初始化LCD屏--------------------------*/
; void init_lcd()
; {
.dbline 145
; CLRBIT(PORTB,RST);
cbi 0x18,5
.dbline 146
; SETBIT(PORTB,RST);
sbi 0x18,5
.dbline 147
; PORTB|=0x18; //CSA=1,CSB=1
in R24,0x18
ori R24,24
out 0x18,R24
.dbline 148
; SetOnOff(0x3e); //关显示
ldi R16,62
xcall _SetOnOff
.dbline 149
; SetLine(0x00); // 设定页
clr R16
xcall _SetLine
.dbline 150
; SetStartLine(0x00);
clr R16
xcall _SetStartLine
.dbline 151
; SetColumn(0x00);
clr R16
xcall _SetColumn
.dbline 152
; SetOnOff(0x3f); //开显示
ldi R16,63
xcall _SetOnOff
.dbline -2
L22:
.dbline 0 ; func end
ret
.dbend
.dbfunc e word_disp _word_disp fV
; k -> R20
; j -> R22
; i -> R10
; hzk -> R12,R13
; row -> R14
; pag -> y+10
.even
_word_disp::
xcall push_arg4
xcall push_gset5
mov R14,R18
ldd R12,y+14
ldd R13,y+15
.dbline -1
.dbline 160
; }
; /*----------------------------------------------------------------------
; 说明:12864液晶横放,汉字按正常方式显示,pag:0~7(从上到下);
; row:0~7(从左到右,水平行,一行可显示8个汉字)
; 功能:指定位置显示汉字16*16
; ------------------------------------------------------------------------*/
; void word_disp(unsigned char pag,unsigned char row, unsigned flash char *hzk)
; {
.dbline 161
; unsigned char j=0,i=0,k=0;
clr R22
.dbline 161
clr R10
.dbline 161
clr R20
.dbline 162
; for(j=0;j<2;j++)
xjmp L27
L24:
.dbline 163
; {
.dbline 164
; if (row <4)
mov R24,R14
cpi R24,4
brsh L28
.dbline 165
; {
.dbline 166
; k=row;
mov R20,R24
.dbline 167
; SETBIT(PORTB,CSA); //CSA=1,CSB=0,select leftwindow
sbi 0x18,3
.dbline 168
; CLRBIT(PORTB,CSB);
cbi 0x18,4
.dbline 169
; }
xjmp L29
L28:
.dbline 171
; else
; {
.dbline 172
; k = row-4;
mov R20,R14
subi R20,4
.dbline 173
; CLRBIT(PORTB,CSA); //CSA=0,CSB=1,select rightwindow
cbi 0x18,3
.dbline 174
; SETBIT(PORTB,CSB);
sbi 0x18,4
.dbline 175
; }
L29:
.dbline 176
; SetLine(pag+j);
ldd R16,y+10
add R16,R22
xcall _SetLine
.dbline 177
; SetColumn(k*16);
ldi R24,16
mul R24,R20
mov R16,R0
xcall _SetColumn
.dbline 178
; for(i=0;i<16;i++)
clr R10
xjmp L33
L30:
.dbline 179
.dbline 180
ldi R24,16
mul R24,R22
movw R30,R0
mov R2,R10
clr R3
add R30,R2
adc R31,R3
add R30,R12
adc R31,R13
lpm R16,Z
xcall _WriteByte
.dbline 181
L31:
.dbline 178
inc R10
L33:
.dbline 178
mov R24,R10
cpi R24,16
brlo L30
.dbline 182
L25:
.dbline 162
inc R22
L27:
.dbline 162
cpi R22,2
brlo L24
.dbline -2
L23:
xcall pop_gset5
adiw R28,4
.dbline 0 ; func end
ret
.dbsym r k 20 c
.dbsym r j 22 c
.dbsym r i 10 c
.dbsym r hzk 12 pkc
.dbsym r row 14 c
.dbsym l pag 10 c
.dbend
.dbfunc e byte_disp _byte_disp fV
; k -> R20
; j -> R22
; i -> R10
; bytek -> R12,R13
; row -> R14
; pag -> y+10
.even
_byte_disp::
xcall push_arg4
xcall push_gset5
mov R14,R18
ldd R12,y+14
ldd R13,y+15
.dbline -1
.dbline 191
; {
; WriteByte(hzk[16*j+i]);
; }
; }
; }
;
; /*----------------------------------------------------------------------
; 说明:12864液晶横放,字符按正常方式显示,pag:0~7(从上到下);
; row:0~15(从左到右,水平行,一行可显示16个字符)
; 功能:指定位置显示字符8*16
; ------------------------------------------------------------------------*/
; void byte_disp(unsigned char pag, unsigned char row, unsigned flash char *bytek)
; {
.dbline 192
; unsigned char j=0,i=0,k=0;
clr R22
.dbline 192
clr R10
.dbline 192
clr R20
.dbline 193
; for(j=0;j<2;j++)
xjmp L38
L35:
.dbline 194
; {
.dbline 195
; if (row < 8)
mov R24,R14
cpi R24,8
brsh L39
.dbline 196
; {
.dbline 197
; k=row;
mov R20,R24
.dbline 198
; SETBIT(PORTB,CSA); //CSA=1,CSB=0,select leftwindow
sbi 0x18,3
.dbline 199
; CLRBIT(PORTB,CSB);
cbi 0x18,4
.dbline 200
; }
xjmp L40
L39:
.dbline 202
; else
; {
.dbline 203
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -