MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00002 ; 00003 ; LCD.ASM MPB Ver 1.0 28-8-05 00004 ; 00005 ; Outputs fixed and variable characters 00006 ; to 16x2 LCD in 4-bit mode 00007 ; 00008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00009 00010 PROCESSOR 16F877A 00011 ; Clock = XT 4MHz, standard fuse settings 2007 3731 00012 __CONFIG 0x3731 00013 00014 ; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00015 00016 INCLUDE "P16F877A.INC" ; Standard register labels 00001 LIST 00002 ; P16F877A.INC Standard Header File, Version 1.00 Microchip Technology, Inc. 00398 LIST 00017 00000020 00018 Timer1 EQU 20 ; 1ms count register 00000021 00019 TimerX EQU 21 ; Xms count register 00000022 00020 Var EQU 22 ; Output variable 00000023 00021 Point EQU 23 ; Program table pointer 00000024 00022 Select EQU 24 ; Copy of RS bit 00000025 00023 OutCod EQU 25 ; Temp store for output code 00024 00000001 00025 RS EQU 1 ; Register select output bit 00000002 00026 E EQU 2 ; Display enable 00027 00028 ; PROGRAM BEGINS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00029 0000 00030 ORG 0 ; Place machine code 0000 0000 00031 NOP ; for ICD mode 00032 0001 1683 1303 00033 BANKSEL TRISD ; Select bank 1 0003 0103 00034 CLRW ; All outputs Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 0004 0088 00035 MOVWF TRISD ; Initialise display port 0005 1283 1303 00036 BANKSEL PORTD ; Select bank 0 0007 0188 00037 CLRF PORTD ; Clear display outputs 00038 0008 288A 00039 GOTO Start ; Jump to main program 00040 00041 00042 ; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00043 00044 ; 1ms delay with 1us cycle time (1000 cycles)............... 00045 0009 30F9 00046 Onems MOVLW D'249' ; Count for 1ms delay 000A 00A0 00047 MOVWF Timer1 ; Load count 000B 0000 00048 Loop1 NOP ; Pad for 4 cycle loop Message[305]: Using default destination of 1 (file). MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 000C 0BA0 00049 DECFSZ Timer1 ; Count 000D 280B 00050 GOTO Loop1 ; until Z 000E 0008 00051 RETURN ; and finish 00052 00053 00054 ; Delay Xms, X received in W ............................... 00055 000F 00A1 00056 Xms MOVWF TimerX ; Count for X ms 0010 2009 00057 LoopX CALL Onems ; Delay 1ms Message[305]: Using default destination of 1 (file). 0011 0BA1 00058 DECFSZ TimerX ; Repeat X times 0012 2810 00059 GOTO LoopX ; until Z 0013 0008 00060 RETURN ; and finish 00061 00062 00063 ; Generate data/command clock siganl E ..................... 00064 0014 1508 00065 PulseE BSF PORTD,E ; Set E high 0015 2009 00066 CALL Onems ; Delay 1ms 0016 1108 00067 BCF PORTD,E ; Reset E low 0017 2009 00068 CALL Onems ; Delay 1ms 0018 0008 00069 RETURN ; done 00070 00071 00072 ; Send a command byte in two nibbles from RB4 - RB7 ........ 00073 0019 00A5 00074 Send MOVWF OutCod ; Store output code 001A 39F0 00075 ANDLW 0F0 ; Clear low nybble 001B 0088 00076 MOVWF PORTD ; Output high nybble 001C 18A4 00077 BTFSC Select,RS ; Test RS bit 001D 1488 00078 BSF PORTD,RS ; and set for data 001E 2014 00079 CALL PulseE ; and clock display register 001F 2009 00080 CALL Onems ; wait 1ms for display 00081 Message[305]: Using default destination of 1 (file). 0020 0EA5 00082 SWAPF OutCod ; Swap low and high nybbles 0021 0825 00083 MOVF OutCod,W ; Retrieve output code 0022 39F0 00084 ANDLW 0F0 ; Clear low nybble 0023 0088 00085 MOVWF PORTD ; Output low nybble 0024 18A4 00086 BTFSC Select,RS ; Test RS bit 0025 1488 00087 BSF PORTD,RS ; and set for data 0026 2014 00088 CALL PulseE ; and clock display register 0027 2009 00089 CALL Onems ; wait 1ms for display 0028 0008 00090 RETURN ; done 00091 00092 00093 ; Table of fixed characters to send .................. 00094 Message[305]: Using default destination of 1 (file). 0029 0782 00095 Line1 ADDWF PCL ; Modify program counter 002A 3443 00096 RETLW 'C' ; Pointer = 0 002B 344F 00097 RETLW 'O' ; Pointer = 1 002C 344E 00098 RETLW 'N' ; Pointer = 2 MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 002D 3453 00099 RETLW 'S' ; Pointer = 3 002E 3454 00100 RETLW 'T' ; Pointer = 4 002F 343A 00101 RETLW ':' ; Pointer = 5 0030 3430 00102 RETLW '0' ; Pointer = 6 0031 3431 00103 RETLW '1' ; Pointer = 7 0032 3432 00104 RETLW '2' ; Pointer = 8 0033 3433 00105 RETLW '3' ; Pointer = 9 0034 3434 00106 RETLW '4' ; Pointer = 10 0035 3435 00107 RETLW '5' ; Pointer = 11 0036 3436 00108 RETLW '6' ; Pointer = 12 0037 3437 00109 RETLW '7' ; Pointer = 13 0038 3438 00110 RETLW '8' ; Pointer = 14 0039 3439 00111 RETLW '9' ; Pointer = 15 00112 Message[305]: Using default destination of 1 (file). 003A 0782 00113 Line2 ADDWF PCL ; Modify program counter 003B 3456 00114 RETLW 'V' ; Pointer = 0 003C 3441 00115 RETLW 'A' ; Pointer = 1 003D 3452 00116 RETLW 'R' ; Pointer = 2 003E 3449 00117 RETLW 'I' ; Pointer = 3 003F 3441 00118 RETLW 'A' ; Pointer = 4 0040 3442 00119 RETLW 'B' ; Pointer = 5 0041 344C 00120 RETLW 'L' ; Pointer = 6 0042 3445 00121 RETLW 'E' ; Pointer = 7 0043 3420 00122 RETLW ' ' ; Pointer = 8 0044 343D 00123 RETLW '=' ; Pointer = 9 0045 3420 00124 RETLW ' ' ; Pointer = 10 00125 00126 00127 ; Initialise the display.................................... 00128 0046 3064 00129 Init MOVLW D'100' ; Load count for 100ms delay 0047 200F 00130 CALL Xms ; and wait for display start 0048 30F0 00131 MOVLW 0F0 ; Mask for select code 0049 00A4 00132 MOVWF Select ; High nybble not masked 00133 004A 3030 00134 MOVLW 0x30 ; Load initial nibble 004B 0088 00135 MOVWF PORTD ; and output it to display 004C 2014 00136 CALL PulseE ; Latch initial code 004D 3005 00137 MOVLW D'5' ; Set delay 5ms 004E 200F 00138 CALL Xms ; and wait 004F 2014 00139 CALL PulseE ; Latch initial code again 0050 2009 00140 CALL Onems ; Wait 1ms 0051 2014 00141 CALL PulseE ; Latch initial code again 0052 1208 00142 BCF PORTD,4 ; Set 4-bit mode 0053 2014 00143 CALL PulseE ; Latch it 00144 0054 3028 00145 MOVLW 0x28 ; Set 4-bit mode, 2 lines 0055 2019 00146 CALL Send ; and send code 0056 3008 00147 MOVLW 0x08 ; Switch off display 0057 2019 00148 CALL Send ; and send code 0058 3001 00149 MOVLW 0x01 ; Code to clear display 0059 2019 00150 CALL Send ; and send code MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 005A 3006 00151 MOVLW 0x06 ; Enable cursor auto inc 005B 2019 00152 CALL Send ; and send code 005C 3080 00153 MOVLW 0x80 ; Zero display address 005D 2019 00154 CALL Send ; and send code 005E 300C 00155 MOVLW 0x0C ; Turn on display 005F 2019 00156 CALL Send ; and send code 00157 0060 0008 00158 RETURN ; Done 00159 00160 00161 ; Send the fixed message to the display..................... 00162 0061 01A3 00163 OutMes CLRF Point ; Reset table pointer 0062 14A4 00164 BSF Select,RS ; Select data mode 00165 0063 0823 00166 Mess1 MOVF Point,W ; and load it 0064 2029 00167 CALL Line1 ; Get ASCII code from table 0065 2019 00168 CALL Send ; and do it Message[305]: Using default destination of 1 (file). 0066 0AA3 00169 INCF Point ; point to next character 0067 0823 00170 MOVF Point,W ; and load the pointer 0068 3C10 00171 SUBLW D'16' ; check for last table item 0069 1D03 00172 BTFSS STATUS,Z ; and finish if 16 done 006A 2863 00173 GOTO Mess1 ; Output character code 00174 006B 30C0 00175 MOVLW 0xC0 ; Move cursor to line 2 006C 10A4 00176 BCF Select,RS ; Select command mode 006D 2019 00177 CALL Send ; and send code 006E 01A3 00178 CLRF Point ; Reset table pointer 006F 0823 00179 Mess2 MOVF Point,W ; and load it 0070 203A 00180 CALL Line2 ; Get fixed character 0071 14A4 00181 BSF Select,RS ; Select data mode 0072 2019 00182 CALL Send ; and send code Message[305]: Using default destination of 1 (file). 0073 0AA3 00183 INCF Point ; next character 0074 0823 00184 MOVF Point,W ; Reload pointer 0075 3C0B 00185 SUBLW D'11' ; and check for last 0076 1D03 00186 BTFSS STATUS,Z ; Skip if last 0077 286F 00187 GOTO Mess2 ; or send next 0078 0008 00188 RETURN ; done 00189 00190 00191 ; Output variable count to display (0-9) endlessly.......... 00192 0079 01A2 00193 OutVar CLRF Var ; Clear variable number 007A 3030 00194 MOVLW 0X30 ; Load offset to be added Message[305]: Using default destination of 1 (file). 007B 07A2 00195 ADDWF Var ; to make ASCII code (30-39) 00196 007C 0822 00197 Next MOVF Var,W ; Load the code 007D 14A4 00198 BSF Select,RS ; Select data mode 007E 2019 00199 CALL Send ; and send code 00200 MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 5 LOC OBJECT CODE LINE SOURCE TEXT VALUE 007F 30CB 00201 MOVLW 0xCB ; code to move cursor back 0080 10A4 00202 BCF Select,RS ; Select command mode 0081 2019 00203 CALL Send ; and send code 0082 30FA 00204 MOVLW D'250' ; Load count to wait 250ms 0083 200F 00205 CALL Xms ; so numbers are visible 00206 Message[305]: Using default destination of 1 (file). 0084 0AA2 00207 INCF Var ; Next number 0085 0822 00208 MOVF Var,W ; Load number 0086 3C3A 00209 SUBLW 0x3A ; Check for last (10=A) 0087 1D03 00210 BTFSS STATUS,Z ; and skip if last 0088 287C 00211 GOTO Next ; or do next number 0089 2879 00212 GOTO OutVar ; Repeat from number Z 00213 00214 00215 ; MAIN PROGRAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00216 008A 2046 00217 Start CALL Init ; Initialise the display 008B 2061 00218 CALL OutMes ; Display fixed characters 008C 2879 00219 GOTO OutVar ; Display an endless count 00220 00221 END ; of source code MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 6 SYMBOL TABLE LABEL VALUE ACKDT 00000005 ACKEN 00000004 ACKSTAT 00000006 ADCON0 0000001F ADCON1 0000009F ADCS0 00000006 ADCS1 00000007 ADDEN 00000003 ADFM 00000007 ADIE 00000006 ADIF 00000006 ADON 00000000 ADRESH 0000001E ADRESL 0000009E BCLIE 00000003 BCLIF 00000003 BF 00000000 BRGH 00000002 C 00000000 C1INV 00000004 C1OUT 00000006 C2INV 00000005 C2OUT 00000007 CCP1CON 00000017 CCP1IE 00000002 CCP1IF 00000002 CCP1M0 00000000 CCP1M1 00000001 CCP1M2 00000002 CCP1M3 00000003 CCP1X 00000005 CCP1Y 00000004 CCP2CON 0000001D CCP2IE 00000000 CCP2IF 00000000 CCP2M0 00000000 CCP2M1 00000001 CCP2M2 00000002 CCP2M3 00000003 CCP2X 00000005 CCP2Y 00000004 CCPR1H 00000016 CCPR1L 00000015 CCPR2H 0000001C CCPR2L 0000001B CHS0 00000003 CHS1 00000004 CHS2 00000005 CIS 00000003 CKE 00000006 CKP 00000004 CM0 00000000 CM1 00000001 MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 7 SYMBOL TABLE LABEL VALUE CM2 00000002 CMCON 0000009C CMIE 00000006 CMIF 00000006 CREN 00000004 CSRC 00000007 CVR0 00000000 CVR1 00000001 CVR2 00000002 CVR3 00000003 CVRCON 0000009D CVREN 00000007 CVROE 00000006 CVRR 00000005 D 00000005 DATA_ADDRESS 00000005 DC 00000001 D_A 00000005 E 00000002 EEADR 0000010D EEADRH 0000010F EECON1 0000018C EECON2 0000018D EEDATA 0000010C EEDATH 0000010E EEIE 00000004 EEIF 00000004 EEPGD 00000007 F 00000001 FERR 00000002 FSR 00000004 GCEN 00000007 GIE 00000007 GO 00000002 GO_DONE 00000002 I2C_DATA 00000005 I2C_READ 00000002 I2C_START 00000003 I2C_STOP 00000004 IBF 00000007 IBOV 00000005 INDF 00000000 INTCON 0000000B INTE 00000004 INTEDG 00000006 INTF 00000001 IRP 00000007 Init 00000046 Line1 00000029 Line2 0000003A Loop1 0000000B LoopX 00000010 Mess1 00000063 MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 8 SYMBOL TABLE LABEL VALUE Mess2 0000006F NOT_A 00000005 NOT_ADDRESS 00000005 NOT_BO 00000000 NOT_BOR 00000000 NOT_DONE 00000002 NOT_PD 00000003 NOT_POR 00000001 NOT_RBPU 00000007 NOT_RC8 00000006 NOT_T1SYNC 00000002 NOT_TO 00000004 NOT_TX8 00000006 NOT_W 00000002 NOT_WRITE 00000002 Next 0000007C OBF 00000006 OERR 00000001 OPTION_REG 00000081 Onems 00000009 OutCod 00000025 OutMes 00000061 OutVar 00000079 P 00000004 PCFG0 00000000 PCFG1 00000001 PCFG2 00000002 PCFG3 00000003 PCL 00000002 PCLATH 0000000A PCON 0000008E PEIE 00000006 PEN 00000002 PIE1 0000008C PIE2 0000008D PIR1 0000000C PIR2 0000000D PORTA 00000005 PORTB 00000006 PORTC 00000007 PORTD 00000008 PORTE 00000009 PR2 00000092 PS0 00000000 PS1 00000001 PS2 00000002 PSA 00000003 PSPIE 00000007 PSPIF 00000007 PSPMODE 00000004 Point 00000023 PulseE 00000014 R 00000002 MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 9 SYMBOL TABLE LABEL VALUE RBIE 00000003 RBIF 00000000 RC8_9 00000006 RC9 00000006 RCD8 00000000 RCEN 00000003 RCIE 00000005 RCIF 00000005 RCREG 0000001A RCSTA 00000018 RD 00000000 READ_WRITE 00000002 RP0 00000005 RP1 00000006 RS 00000001 RSEN 00000001 RX9 00000006 RX9D 00000000 R_W 00000002 S 00000003 SEN 00000000 SMP 00000007 SPBRG 00000099 SPEN 00000007 SREN 00000005 SSPADD 00000093 SSPBUF 00000013 SSPCON 00000014 SSPCON2 00000091 SSPEN 00000005 SSPIE 00000003 SSPIF 00000003 SSPM0 00000000 SSPM1 00000001 SSPM2 00000002 SSPM3 00000003 SSPOV 00000006 SSPSTAT 00000094 STATUS 00000003 SYNC 00000004 Select 00000024 Send 00000019 Start 0000008A T0CS 00000005 T0IE 00000005 T0IF 00000002 T0SE 00000004 T1CKPS0 00000004 T1CKPS1 00000005 T1CON 00000010 T1INSYNC 00000002 T1OSCEN 00000003 T1SYNC 00000002 MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 10 SYMBOL TABLE LABEL VALUE T2CKPS0 00000000 T2CKPS1 00000001 T2CON 00000012 TMR0 00000001 TMR0IE 00000005 TMR0IF 00000002 TMR1CS 00000001 TMR1H 0000000F TMR1IE 00000000 TMR1IF 00000000 TMR1L 0000000E TMR1ON 00000000 TMR2 00000011 TMR2IE 00000001 TMR2IF 00000001 TMR2ON 00000002 TOUTPS0 00000003 TOUTPS1 00000004 TOUTPS2 00000005 TOUTPS3 00000006 TRISA 00000085 TRISB 00000086 TRISC 00000087 TRISD 00000088 TRISE 00000089 TRISE0 00000000 TRISE1 00000001 TRISE2 00000002 TRMT 00000001 TX8_9 00000006 TX9 00000006 TX9D 00000000 TXD8 00000000 TXEN 00000005 TXIE 00000004 TXIF 00000004 TXREG 00000019 TXSTA 00000098 Timer1 00000020 TimerX 00000021 UA 00000001 Var 00000022 W 00000000 WCOL 00000007 WR 00000001 WREN 00000002 WRERR 00000003 Xms 0000000F Z 00000002 _BODEN_OFF 00003FBF _BODEN_ON 00003FFF _CPD_OFF 00003FFF _CPD_ON 00003EFF MPASM 03.70.01 Released LCD.ASM 3-5-2006 21:14:55 PAGE 11 SYMBOL TABLE LABEL VALUE _CP_ALL 00001FFF _CP_OFF 00003FFF _DEBUG_OFF 00003FFF _DEBUG_ON 000037FF _HS_OSC 00003FFE _LP_OSC 00003FFC _LVP_OFF 00003F7F _LVP_ON 00003FFF _PWRTE_OFF 00003FFF _PWRTE_ON 00003FF7 _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _WRT_1FOURTH 00003BFF _WRT_256 00003DFF _WRT_HALF 000039FF _WRT_OFF 00003FFF _XT_OSC 00003FFD __16F877A 00000001 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0080 : XXXXXXXXXXXXX--- ---------------- ---------------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 141 Program Memory Words Free: 8051 Errors : 0 Warnings : 0 reported, 0 suppressed Messages : 10 reported, 0 suppressed