📄 lcd.s
字号:
.module lcd.c
.area data(ram, con, rel)
_init_tab:
.blkb 2
.area idata
.byte 56,1
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 8,14
.area data(ram, con, rel)
.blkb 1
.area idata
.byte 1
.area data(ram, con, rel)
.dbfile E:\work\avr\icc\cpld\stklcd\lcd.c
.dbsym s init_tab _init_tab A[5:5]c
.area text(rom, con, rel)
.dbfile E:\work\avr\icc\cpld\stklcd\lcd.c
.dbfunc e LCD_init _LCD_init fV
; i -> R20
.even
_LCD_init::
rcall push_gset1
.dbline -1
.dbline 73
; //
; // File Name: lcd.c
; //
; // Title: LCD interface implementation
; //
; // Description: Interface implementation file for the Hitachi HD44780U.
; // This driver is for the STK200.
; // STK200 port information
; // DATA = PORTA
; // RS = PORTC BIT 6
; // R/W = PORTD BIT 6
; // E = PORTC BIT 7
; //
; // Creation Date: 2/2/00 11:49:37 PM
; //
; // By: A.C. Verbeck
; //
; // This file is subject to the terms and conditions of the GNU General Public
; // License. See the file COPYING in the main directory of this archive
; // for more details.
; //
;
; #include <io8515v.h>
; #include <stdio.h>
;
; #include "Basetype.h"
; #include "t0.h"
;
; #include "lcd.h"
;
; //
; // Local defines
; //
; #define FUNCTION_SET 0x38
; #define CMD 0x00
; #define DATA 0x01
; #define CMD_IO (PUInt8)0x8000
; #define DATA_IO (PUInt8)0xC000
;
; //
; // Local data
; //
; static UInt8 init_tab[] = {
; FUNCTION_SET,
; LCD_CLEAR,
; LCD_OFF,
; LCD_ON,
; LCD_CLEAR
; };
;
; //
; // Local functions
; //
; static void LCD_write(UInt8 val, UInt8 sel);
; static UInt8 LCD_read(UInt8 sel);
; static void LCD_busy_test(void);
; static void delay(UInt16 dly);
;
; //
; // Function Name:
; // LCD_init
; //
; // Description:
; // Initialize the LCD.
; //
; // Parameters:
; // (none)
; //
; // Returns:
; // (nothing)
; //
; void LCD_init(void)
; {
.dbline 76
clr R20
rjmp L5
L2:
.dbline 76
.dbline 77
rcall _LCD_busy_test
.dbline 78
clr R18
ldi R24,<_init_tab
ldi R25,>_init_tab
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
rcall _LCD_write
.dbline 79
L3:
.dbline 76
inc R20
L5:
.dbline 76
; UInt8 i;
;
; for (i=0; i<5; i++) {
cpi R20,5
brlo L2
.dbline -2
.dbline 80
; LCD_busy_test();
; LCD_write(init_tab[i], CMD);
; }
; }
L1:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.dbfunc e LCD_clear _LCD_clear fV
.even
_LCD_clear::
.dbline -1
.dbline 96
;
; //
; // Function Name:
; // LCD_clear
; //
; // Description:
; // Clear the LCD.
; //
; // Parameters:
; // (none)
; //
; // Returns:
; // (nothing)
; //
; void LCD_clear(void)
; {
.dbline 97
; LCD_command(LCD_CLEAR);
ldi R16,1
.dbline -2
.dbline 98
; }
L6:
.dbline 0 ; func end
rjmp _LCD_command
.dbend
.dbfunc e LCD_reset _LCD_reset fV
.even
_LCD_reset::
.dbline -1
.dbline 114
;
; //
; // Function Name:
; // LCD_reset
; //
; // Description:
; // Reset the LCD.
; //
; // Parameters:
; // (none)
; //
; // Returns:
; // (nothing)
; //
; void LCD_reset(void)
; {
.dbline 115
; T0_sleep(15); // Hitachi says wait 15mS before writing the LCD
ldi R16,15
ldi R17,0
rcall _T0_sleep
.dbline 116
; LCD_write(0x30, CMD); // Write the init (first time)
clr R18
ldi R16,48
rcall _LCD_write
.dbline 117
; T0_sleep(5); // Then, wait 4.1mS
ldi R16,5
ldi R17,0
rcall _T0_sleep
.dbline 118
; LCD_write(0x30, CMD); // Write the init again (second time)
clr R18
ldi R16,48
rcall _LCD_write
.dbline 119
; T0_sleep(1); // Then, wait 100uS
ldi R16,1
ldi R17,0
rcall _T0_sleep
.dbline 120
; LCD_write(0x30, CMD); // Write the init again (last time)
clr R18
ldi R16,48
.dbline -2
.dbline 121
; }
L7:
.dbline 0 ; func end
rjmp _LCD_write
.dbend
.dbfunc e LCD_command _LCD_command fV
; data -> R20
.even
_LCD_command::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 124
;
; void LCD_command(UInt8 data)
; {
.dbline 125
; LCD_busy_test();
rcall _LCD_busy_test
.dbline 126
; LCD_write(data, CMD);
clr R18
mov R16,R20
rcall _LCD_write
.dbline -2
.dbline 127
; }
L8:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e LCD_putc _LCD_putc fV
; c -> R20
.even
_LCD_putc::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 130
;
; void LCD_putc(Char c)
; {
.dbline 131
; LCD_busy_test();
rcall _LCD_busy_test
.dbline 132
; if (c == '\n')
cpi R20,10
brne L10
.dbline 133
; LCD_command(LCD_NEW_LINE);
ldi R16,192
rcall _LCD_command
rjmp L11
L10:
.dbline 135
ldi R18,1
mov R16,R20
rcall _LCD_write
L11:
.dbline -2
.dbline 136
; else
; LCD_write(c, DATA);
; }
L9:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r c 20 c
.dbend
.dbfunc e LCD_puts _LCD_puts fV
; s -> R20,R21
.even
_LCD_puts::
rcall push_gset1
mov R20,R16
mov R21,R17
.dbline -1
.dbline 139
;
; void LCD_puts(String s)
; {
rjmp L14
L13:
.dbline 140
; while (*s) {
.dbline 141
; LCD_busy_test();
rcall _LCD_busy_test
.dbline 142
; if (*s == '\n')
mov R30,R20
mov R31,R21
ldd R24,z+0
cpi R24,10
brne L16
.dbline 143
; LCD_command(LCD_NEW_LINE);
ldi R16,192
rcall _LCD_command
rjmp L17
L16:
.dbline 145
; else
; LCD_write(*s, DATA);
ldi R18,1
mov R30,R20
mov R31,R21
ldd R16,z+0
rcall _LCD_write
L17:
.dbline 146
subi R20,255 ; offset = 1
sbci R21,255
.dbline 147
L14:
.dbline 140
mov R30,R20
mov R31,R21
ldd R2,z+0
tst R2
brne L13
.dbline -2
.dbline 148
; ++s;
; }
; }
L12:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r s 20 pc
.dbend
.dbfunc s LCD_write _LCD_write fV
; sel -> R18
; val -> R16
.even
_LCD_write:
rcall push_gset1
.dbline -1
.dbline 168
;
;
; //
; // Function Name:
; // LCD_write
; //
; // Description:
; // Write data or cmd to HD44780U
; //
; // Parameters:
; // val = data value to be written to HD44780U
; // sel = data / cmd
; // 0 - cmd write
; // 1 - data write is selected
; //
; // Returns:
; // (nothing)
; //
; static void LCD_write(UInt8 val, UInt8 sel)
; {
.dbline 169
; MCUCR = 0xC0;
ldi R24,192
out 0x35,R24
.dbline 170
mov R20,R18
clr R21
cpi R20,0
cpc R20,R21
breq L22
X0:
cpi R20,1
ldi R30,0
cpc R21,R30
breq L23
rjmp L19
X1:
.dbline 170
; switch (sel) {
L22:
.dbline 171
; case CMD: *CMD_IO = val; break;
sts 32768,R16
.dbline 171
rjmp L20
L23:
.dbline 172
; case DATA: *DATA_IO = val; break;
sts 49152,R16
.dbline 172
L19:
L20:
.dbline -2
.dbline 174
; }
; }
L18:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r sel 18 c
.dbsym r val 16 c
.dbend
.dbfunc s LCD_read _LCD_read fc
; rVal -> R20
; sel -> R16
.even
_LCD_read:
rcall push_gset1
.dbline -1
.dbline 192
;
; //
; // Function Name:
; // LCD_read
; //
; // Description:
; // Read data or cmd to HD44780U
; //
; // Parameters:
; // sel = data / cmd
; // 0 - cmd read
; // 1 - data read
; //
; // Returns:
; // data read from LCD
; //
; static UInt8 LCD_read(UInt8 sel)
; {
.dbline 194
; UInt8 rVal;
; MCUCR = 0xC0;
ldi R24,192
out 0x35,R24
.dbline 195
mov R20,R16
clr R21
cpi R20,0
cpc R20,R21
breq L28
X2:
cpi R20,1
ldi R30,0
cpc R21,R30
breq L29
rjmp L25
X3:
.dbline 195
; switch (sel) {
L28:
.dbline 196
; case CMD: rVal = *CMD_IO; break;
lds R20,32768
.dbline 196
rjmp L26
L29:
.dbline 197
; case DATA: rVal = *DATA_IO; break;
lds R20,49152
.dbline 197
L25:
L26:
.dbline 199
; }
; return rVal;
mov R16,R20
.dbline -2
L24:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r rVal 20 c
.dbsym r sel 16 c
.dbend
.dbfunc s LCD_busy_test _LCD_busy_test fV
.even
_LCD_busy_test:
.dbline -1
.dbline 216
; }
;
; //
; // Function Name:
; // LCD_busy_test
; //
; // Description:
; // Test if the LCD is busy or not
; //
; // Parameters:
; // (none)
; //
; // Returns:
; // (nothing)
; //
; static void LCD_busy_test(void)
; {
L31:
.dbline 217
L32:
.dbline 217
; while (LCD_read(CMD) & 0x80);
clr R16
rcall _LCD_read
sbrc R16,7
rjmp L31
.dbline -2
.dbline 218
; }
L30:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -