📄 lm032l.asm
字号:
LIST P=16C64
ERRORLEVEL -302
;
; This program interfaces to a Hitachi (LM032L) 2 line by 20 character display
; module. The program assembles for either 4-bit or 8-bit data interface, depending
; on the value of the 4bit flag. LCD_DATA is the port which supplies the data to
; the LM032L, while LCD_CNTL is the port that has the control lines ( E, RS, RW ).
; In 4-bit mode the data is transfer on the high nibble of the port ( PORT<7:4> ).
;
; Program = LM032L.ASM
; Revision Date: 5-10-94
; 1-22-97 Compatibility with MPASMWIN 1.40
;
;
include <p16c64.inc>
ADCON1 EQU 9F
FALSE EQU 0
TRUE EQU 1
include <lm032l.h>
;
Four_bit EQU TRUE ; Selects 4- or 8-bit data transfers
Data_HI EQU FALSE ; If 4-bit transfers, Hi or Low nibble of PORT
;
;
if ( Four_bit && !Data_HI )
;
LCD_DATA EQU PORTB
LCD_DATA_TRIS EQU TRISB
;
else
;
LCD_DATA EQU PORTD
LCD_DATA_TRIS EQU TRISD
;
endif
;
LCD_CNTL EQU PORTA
;
;
;
; LCD Display Commands and Control Signal names.
;
if ( Four_bit && !Data_HI )
;
E EQU 0 ; LCD Enable control line
RW EQU 1 ; LCD Read/Write control line
RS EQU 2 ; LCD Register Select control line
;
else
;
E EQU 3 ; LCD Enable control line
RW EQU 2 ; LCD Read/Write control line
RS EQU 1 ; LCD Register Select control line
;
endif
;
;
TEMP1 EQU 0x030
;
org RESET_V ; RESET vector location
RESET GOTO START ;
;
; This is the Periperal Interrupt routine. Should NOT get here
;
page
org ISR_V ; Interrupt vector location
PER_INT_V
ERROR1 BCF STATUS, RP0 ; Bank 0
BSF PORTC, 0
BCF PORTC, 0
GOTO ERROR1
;
;
;
START ; POWER_ON Reset (Beginning of program)
CLRF STATUS ; Do initialization (Bank 0)
CLRF INTCON
CLRF PIR1
BSF STATUS, RP0 ; Bank 1
MOVLW 0x00 ; The LCD module does not like to work w/ weak pull-ups
MOVWF OPTION_REG ;
CLRF PIE1 ; Disable all peripheral interrupts
MOVLW 0xFF ;
MOVWF ADCON1 ; Port A is Digital.
;
;
BCF STATUS, RP0 ; Bank 0
CLRF PORTA ; ALL PORT output should output Low.
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF PORTE
BCF T1CON, TMR1ON ; Timer 1 is NOT incrementing
;
BSF STATUS, RP0 ; Select Bank 1
CLRF TRISA ; RA5 - 0 outputs
MOVLW 0xF0 ;
MOVWF TRISB ; RB7 - 4 inputs, RB3 - 0 outputs
CLRF TRISC ; RC Port are outputs
BSF TRISC, T1OSO ; RC0 needs to be input for the oscillator to function
CLRF TRISD ; RD Port are outputs
CLRF TRISE ; RE Port are outputs
BSF PIE1, TMR1IE ; Enable TMR1 Interrupt
BSF OPTION_REG,NOT_RBPU ; Disable PORTB pull-ups
BCF STATUS, RP0 ; Select Bank 0
;
page
;
; Initilize the LCD Display Module
;
CLRF LCD_CNTL ; ALL PORT output should output Low.
DISPLAY_INIT
if ( Four_bit && !Data_HI )
MOVLW 0x02 ; Command for 4-bit interface low nibble
endif
;
if ( Four_bit && Data_HI )
MOVLW 0x020 ; Command for 4-bit interface high nibble
endif
;
if ( !Four_bit )
MOVLW 0x038 ; Command for 8-bit interface
endif
;
MOVWF LCD_DATA ;
BSF LCD_CNTL, E ;
BCF LCD_CNTL, E ;
;
; This routine takes the calculated times that the delay loop needs to
; be executed, based on the LCD_INIT_DELAY EQUate that includes the
; frequency of operation. These uses registers before they are needed to
; store the time.
;
LCD_DELAY MOVLW LCD_INIT_DELAY ;
MOVWF MSD ; Use MSD and LSD Registers to Initilize LCD
CLRF LSD ;
LOOP2 DECFSZ LSD, F ; Delay time = MSD * ((3 * 256) + 3) * Tcy
GOTO LOOP2 ;
DECFSZ MSD, F ;
END_LCD_DELAY
GOTO LOOP2 ;
;
; Command sequence for 2 lines of 5x7 characters
;
CMD_SEQ
;
if ( Four_bit )
if ( !Data_HI )
MOVLW 0X02 ; 4-bit low nibble xfer
else
MOVLW 0X020 ; 4-bit high nibble xfer
endif
;
else ; 8-bit mode
MOVLW 0X038
endif
;
MOVWF LCD_DATA ; This code for both 4-bit and 8-bit modes
BSF LCD_CNTL, E ;
BCF LCD_CNTL, E ;
;
if ( Four_bit ) ; This code for only 4-bit mode (2nd xfer)
if ( !Data_HI )
MOVLW 0x08 ; 4-bit low nibble xfer
else
MOVLW 0x080 ; 4-bit high nibble xfer
endif
MOVWF LCD_DATA ;
BSF LCD_CNTL, E ;
BCF LCD_CNTL, E ;
endif
;
; Busy Flag should be valid after this point
;
MOVLW DISP_ON ;
CALL SEND_CMD ;
MOVLW CLR_DISP ;
CALL SEND_CMD ;
MOVLW ENTRY_INC ;
CALL SEND_CMD ;
MOVLW DD_RAM_ADDR ;
CALL SEND_CMD ;
;
page
;
;Send a message the hard way
movlw 'M'
call SEND_CHAR
movlw 'i'
call SEND_CHAR
movlw 'c'
call SEND_CHAR
movlw 'r'
call SEND_CHAR
movlw 'o'
call SEND_CHAR
movlw 'c'
call SEND_CHAR
movlw 'h'
call SEND_CHAR
movlw 'i'
call SEND_CHAR
movlw 'p'
call SEND_CHAR
movlw B'11000000' ;Address DDRam first character, second line
call SEND_CMD
;Demonstration of the use of a table to output a message
movlw 0 ;Table address of start of message
dispmsg
movwf TEMP1 ;TEMP1 holds start of message address
call Table
andlw 0FFh ;Check if at end of message (zero
btfsc STATUS,Z ;returned at end)
goto out
call SEND_CHAR ;Display character
movf TEMP1,w ;Point to next character
addlw 1
goto dispmsg
out
loop
goto loop ;Stay here forever
;
;
INIT_DISPLAY
MOVLW DISP_ON ; Display On, Cursor On
CALL SEND_CMD ; Send This command to the Display Module
MOVLW CLR_DISP ; Clear the Display
CALL SEND_CMD ; Send This command to the Display Module
MOVLW ENTRY_INC ; Set Entry Mode Inc., No shift
CALL SEND_CMD ; Send This command to the Display Module
RETURN
;
page
;
;*******************************************************************
;* The LCD Module Subroutines *
;*******************************************************************
;
if ( Four_bit ) ; 4-bit Data transfers?
;
if ( Data_HI ) ; 4-bit transfers on the high nibble of the PORT
;
;*******************************************************************
;*SendChar - Sends character to LCD *
;*This routine splits the character into the upper and lower *
;*nibbles and sends them to the LCD, upper nibble first. *
;*******************************************************************
;
SEND_CHAR
MOVWF CHAR ;Character to be sent is in W
CALL BUSY_CHECK ;Wait for LCD to be ready
MOVF CHAR, w
ANDLW 0xF0 ;Get upper nibble
MOVWF LCD_DATA ;Send data to LCD
BCF LCD_CNTL, RW ;Set LCD to read
BSF LCD_CNTL, RS ;Set LCD to data mode
BSF LCD_CNTL, E ;toggle E for LCD
BCF LCD_CNTL, E
SWAPF CHAR, w
ANDLW 0xF0 ;Get lower nibble
MOVWF LCD_DATA ;Send data to LCD
BSF LCD_CNTL, E ;toggle E for LCD
BCF LCD_CNTL, E
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -