📄 lcd.lst
字号:
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).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -