📄 p18lcd.lst
字号:
MPASM 5.20 P18LCD.ASM 5-28-2008 15:51:07 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 ;************************************************************************
00002 ;* Microchip Technology Inc. 2002 *
00003 ;* Assembler version: 2.0000 *
00004 ;* Filename: *
00005 ;* p18lcd.asm (main routine) *
00006 ;* Dependents: *
00007 ;* p18demo.asm *
00008 ;* p18math.asm *
00009 ;* 16f877.lkr *
00010 ;* March 14,2002 *
00011 ;* PICDEM 2 PLUS DEMO code. The following functions are included *
00012 ;* with this code: *
00013 ;* 1. Voltmeter *
00014 ;* The center tap of R16 is connected to RA0, the *
00015 ;* A/D converter converts this analog voltage and *
00016 ;* the result is displayed on the LCD in a range *
00017 ;* from 0.00V - 5.00V. *
00018 ;* 2. Buzzer *
00019 ;* The Piezo buzzer is connected to RC2 and is *
00020 ;* driven by the CCP1 module. The period and duty *
00021 ;* cycle are adjustable on the fly through the LCD *
00022 ;* and push-buttons. *
00023 ;* 3. Temperature *
00024 ;* A TC74 Serial Digital Thermal Sensor is used to *
00025 ;* measure ambient temperature. The PIC and TC74 *
00026 ;* communicate using the MSSP module. The TC74 is *
00027 ;* connected to the SDA & SCL I/O pins of the PIC *
00028 ;* and functions as a slave. *
00029 ;* 4. Clock *
00030 ;* This function is a real-time clock. When the *
00031 ;* mode is entered, time begins at 00:00:00. The *
00032 ;* user can set the time if desired. *
00033 ;************************************************************************
00034
00035 list p=18f452
00036 #include p18f452.inc
00001 LIST
00002 ; P18F452.INC Standard Header File, Version 1.4 Microchip Technology, Inc.
00983 LIST
00037
00038
00039 #define LCD_D4 PORTD, 0 ; LCD data bits
00040 #define LCD_D5 PORTD, 1
00041 #define LCD_D6 PORTD, 2
00042 #define LCD_D7 PORTD, 3
00043
00044 #define LCD_D4_DIR TRISD, 0 ; LCD data bits
00045 #define LCD_D5_DIR TRISD, 1
00046 #define LCD_D6_DIR TRISD, 2
00047 #define LCD_D7_DIR TRISD, 3
00048
00049 #define LCD_E PORTA, 1 ; LCD E clock
00050 #define LCD_RW PORTA, 2 ; LCD read/write line
MPASM 5.20 P18LCD.ASM 5-28-2008 15:51:07 PAGE 2
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00051 #define LCD_RS PORTA, 3 ; LCD register select line
00052
00053 #define LCD_E_DIR TRISA, 1
00054 #define LCD_RW_DIR TRISA, 2
00055 #define LCD_RS_DIR TRISA, 3
00056
00057 #define LCD_INS 0
00058 #define LCD_DATA 1
00059
00060 D_LCD_DATA UDATA
000000 00061 COUNTER res 1
000001 00062 delay res 1
000002 00063 temp_wr res 1
000003 00064 temp_rd res 1
00065
0000 00066 GLOBAL temp_wr
00067
00068 PROG1 CODE
00069
00070
00071 ;***************************************************************************
00072
000000 00073 LCDLine_1
000000 0E80 00074 movlw 0x80
000002 6E?? 00075 movwf temp_wr
000004 D??? 00076 rcall i_write
000006 0012 00077 return
0000 00078 GLOBAL LCDLine_1
00079
000008 00080 LCDLine_2
000008 0EC0 00081 movlw 0xC0
00000A 6E?? 00082 movwf temp_wr
00000C D??? 00083 rcall i_write
00000E 0012 00084 return
0000 00085 GLOBAL LCDLine_2
00086
00087 ;write data
000010 00088 d_write
000010 C??? FFAD 00089 movff temp_wr,TXREG
000014 A2AC 00090 btfss TXSTA,TRMT
000016 EF?? F??? 00091 goto $-2
00001A D??? 00092 rcall LCDBusy
00001C 80D8 00093 bsf STATUS, C
00001E D??? 00094 rcall LCDWrite
000020 0012 00095 return
0000 00096 GLOBAL d_write
00097
00098 ;write instruction
000022 00099 i_write
000022 D??? 00100 rcall LCDBusy
000024 90D8 00101 bcf STATUS, C
000026 D??? 00102 rcall LCDWrite
000028 0012 00103 return
MPASM 5.20 P18LCD.ASM 5-28-2008 15:51:07 PAGE 3
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0000 00104 GLOBAL i_write
00105
00106
00107 rlcd macro MYREGISTER
00108 IF MYREGISTER == 1
00109 bsf STATUS, C
00110 rcall LCDRead
00111 ELSE
00112 bcf STATUS, C
00113 rcall LCDRead
00114 ENDIF
00115 endm
00116 ;****************************************************************************
00117
00118
00119
00120
00121 ; *******************************************************************
00002A 00122 LCDInit
00002A 6A80 00123 clrf PORTA
00124
00002C 9292 00125 bcf LCD_E_DIR ;configure control lines
00002E 9492 00126 bcf LCD_RW_DIR
000030 9692 00127 bcf LCD_RS_DIR
00128
000032 0E0E 00129 movlw b'00001110'
000034 6EC1 00130 movwf ADCON1
00131
000036 0EFF 00132 movlw 0xff ; Wait ~15ms @ 20 MHz
000038 6E?? 00133 movwf COUNTER
00003A 00134 lil1
00003A 0EFF 00135 movlw 0xFF
00003C 6E?? 00136 movwf delay
00003E D??? 00137 rcall DelayXCycles
000040 2E?? 00138 decfsz COUNTER,F
000042 D??? 00139 bra lil1
00140
000044 0E30 00141 movlw b'00110000' ;#1 Send control sequence
000046 6E?? 00142 movwf temp_wr
000048 90D8 00143 bcf STATUS,C
00004A D??? 00144 rcall LCDWriteNibble
00145
00004C 0EFF 00146 movlw 0xff ;Wait ~4ms @ 20 MHz
00004E 6E?? 00147 movwf COUNTER
000050 00148 lil2
000050 0EFF 00149 movlw 0xFF
000052 6E?? 00150 movwf delay
000054 D??? 00151 rcall DelayXCycles
000056 2E?? 00152 decfsz COUNTER,F
000058 D??? 00153 bra lil2
00154
00005A 0E30 00155 movlw b'00110000' ;#2 Send control sequence
00005C 6E?? 00156 movwf temp_wr
MPASM 5.20 P18LCD.ASM 5-28-2008 15:51:07 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00005E 90D8 00157 bcf STATUS,C
000060 D??? 00158 rcall LCDWriteNibble
00159
000062 0EFF 00160 movlw 0xFF ;Wait ~100us @ 20 MHz
000064 6E?? 00161 movwf delay
000066 D??? 00162 rcall DelayXCycles
00163
000068 0E18 00164 movlw b'0011000' ;#3 Send control sequence
00006A 6E?? 00165 movwf temp_wr
00006C 90D8 00166 bcf STATUS,C
00006E D??? 00167 rcall LCDWriteNibble
00168
00169 ;test delay
000070 0EFF 00170 movlw 0xFF ;Wait ~100us @ 20 MHz
000072 6E?? 00171 movwf delay
000074 D??? 00172 rcall DelayXCycles
00173
00174
000076 0E20 00175 movlw b'00100000' ;#4 set 4-bit
000078 6E?? 00176 movwf temp_wr
00007A 90D8 00177 bcf STATUS,C
00007C D??? 00178 rcall LCDWriteNibble
00179
00007E D??? 00180 rcall LCDBusy ;Busy?
00181
000080 0E28 00182 movlw b'00101000' ;#5 Function set
000082 6E?? 00183 movwf temp_wr
000084 D??? 00184 rcall i_write
00185
000086 0E0D 00186 movlw b'00001101' ;#6 Display = ON
000088 6E?? 00187 movwf temp_wr
00008A D??? 00188 rcall i_write
00189
00008C 0E01 00190 movlw b'00000001' ;#7 Display Clear
00008E 6E?? 00191 movwf temp_wr
000090 D??? 00192 rcall i_write
00193
000092 0E06 00194 movlw b'00000110' ;#8 Entry Mode
000094 6E?? 00195 movwf temp_wr
000096 D??? 00196 rcall i_write
00197
000098 0E80 00198 movlw b'10000000' ;DDRAM addresss 0000
00009A 6E?? 00199 movwf temp_wr
00009C D??? 00200 rcall i_write
00201
00202 ; movlw b'00000010' ;return home
00203 ; movwf temp_wr
00204 ; call i_write
00205
00206
00009E 0012 00207 return
00208
0000 00209 GLOBAL LCDInit
MPASM 5.20 P18LCD.ASM 5-28-2008 15:51:07 PAGE 5
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00210 ; *******************************************************************
00211
00212
00213
00214
00215
00216
00217
00218
00219 ;****************************************************************************
00220 ; _ ______________________________
00221 ; RS _>--<______________________________
00222 ; _____
00223 ; RW \_____________________________
00224 ; __________________
00225 ; E ____________/ \___
00226 ; _____________ ______
00227 ; DB _____________>--------------<______
00228 ;
0000A0 00229 LCDWriteNibble
0000A0 A0D8 00230 btfss STATUS, C ; Set the register select
0000A2 9680 00231 bcf LCD_RS
0000A4 B0D8 00232 btfsc STATUS, C
0000A6 8680 00233 bsf LCD_RS
00234
0000A8 9480 00235 bcf LCD_RW ; Set write mode
00236
0000AA 9095 00237 bcf LCD_D4_DIR ; Set data bits to outputs
0000AC 9295 00238 bcf LCD_D5_DIR
0000AE 9495 00239 bcf LCD_D6_DIR
0000B0 9695 00240 bcf LCD_D7_DIR
00241
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -