; Title "LCD test." ; list P = 16F877 ; include "P16f877.inc" __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEBUG_OFF & _CPD_OFF ; ; -------------------- ; USER RAM DEFINITIONS ; -------------------- ; CBLOCK 0x20 ; MessPt DisData DelayL DelayM DelayH Temp ; ENDC lcdRW equ 2h ; RB2 = LCD RW pin lcdRS equ 4h ; RB4 = LCD RS pin lcdE equ 5h ; RB5 = LCD E pin ; PORTD USED FOR LCD DATA PINS RB0 - RB7 = D0 - D7 ; ; --------------------- ; YOUR CODE BEGINS HERE ; --------------------- ; org 0x0000 clrf PORTA clrf PORTD clrf PORTC clrf PORTD clrf PORTE bsf STATUS,RP0 ; RAM Page 1 clrf TRISA clrf TRISB clrf TRISC clrf TRISD clrf TRISE ; ; ------------------------- ; SET ANALOG/DIGITAL INPUTS ; ------------------------- ; movlw b'00000110' ; = all digital movwf ADCON1 bcf STATUS,RP0 movlw 20h ; 25mS powerup delay @ 4MHz movwf DelayH ; data sheet says 15mS clrf DelayL PUPD decfsz DelayL goto PUPD decfsz DelayH goto PUPD call Control ; initialize display ; ; ----------------------------------------------------- ; DISPLAY THE MESSAGE WHEN THE BUTTON ON RA3 IS PRESSED ; ----------------------------------------------------- ; MnLoop clrf MessPt movlw 0x80 ; line 1 call LCDins Loop1 call TheText xorlw 0h btfsc STATUS,Z goto DoLine2 call LCDout incf MessPt goto Loop1 DoLine2 incf MessPt movlw 0xC0 ; line 2 call LCDins Loop2 call TheText xorlw 0h btfsc STATUS,Z goto DoDelay call LCDout incf MessPt goto Loop2 DoDelay call BigDel ; wait goto MnLoop ; ; ------------------------ ; LCD INITIALIZATION CODES ; ------------------------ ; TheText movlw High($) movwf PCLATH movf MessPt,W addwf PCL DT " HELLO FROM", 0h DT " THE PIC 16F873", 0h ; ; ----------------- ; SEND CONTROL DATA ; ----------------- ; According to the data sheet, a delay of 4mS minimum must occur ; between each control data byte being sent. ; Control movlw 38h ; (128) display initialisation call LCDins ; output to display movlw 38h ; page 45 of the data sheet call LCDins ; output to display movlw 38h ; two line call LCDins ; output to display movlw .6 ; increment display call LCDins ; output to display movlw 0ch ; display = on, cursor = off call LCDins ; output to display movlw .1 ; clear display call LCDins ; output to display return ; ; ----------------------------- ; OUTPUT 1 DATA BYTE TO DISPLAY ; ----------------------------- ; LCDout movf DisData,w movwf PORTD bsf PORTB,lcdRS ; (4) Write data to display call Clock bsf PORTB,lcdE ; (5) enable call Clock bcf PORTB,lcdE ; (5) call Clock bcf PORTB,lcdRS ; (5) bcf STATUS,RP0 ; ram page 0 return ; ; ------------------------------------ ; OUTPUT 1 INSTRUCTION BYTE TO DISPLAY ; ------------------------------------ ; LCDins movf DisData,w movwf PORTD bcf PORTB,lcdRS ; (4) Write instruction to display call Clock bsf PORTB,lcdE ; (5) enable call Clock bcf PORTB,lcdE ; (5) call Clock clrf DelayL movlw 8h ; about 6mS delay @ 4MHz movwf DelayH ctlp1 decfsz DelayL goto ctlp1 decfsz DelayH goto ctlp1 return ; ; ----------------------------- ; CLOCKING DELAY - 200uS @ 4MHz ; ----------------------------- ; Clock movlw 40h movwf DelayL kdloop decfsz DelayL goto kdloop return ; ; -------------------------------- ; ABOUT A HALF SECOND DELAY @ 4MHz ; -------------------------------- ; BigDel clrf DelayL clrf DelayM movlw 5h movwf DelayH BDloop decfsz DelayL goto BDloop decfsz DelayM goto BDloop decfsz DelayH goto BDloop return test movlw 8h movwf DelayH ctlp2 decfsz DelayL goto ctlp2 decfsz DelayH goto ctlp2 return ; ; ----------------------- ; BOOT CODE START ADDRESS ; ----------------------- ; DO NOT PLACE ANY CODE PAST THIS POINT ; org 0x0F00 ; ; end
file: /Techref/microchip/16F877/tlcd.asm, 4KB, , updated: 2001/2/1 10:45, local time: 2024/11/15 02:23,
3.144.172.9:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.ecomorder.com/techref/microchip/16F877/tlcd.asm"> microchip 16F877 tlcd</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.