;********************************************************************** ; * ; Filename: Parallax LCD MSG generator * ; Date: 01.01.12 * ; File Version: original * ; * ; Author: JPA * ; Company: * ; * ; * ;********************************************************************** ; * ; Files Required: P12F509.INC * ; * ;********************************************************************** ; Notes: * ; 1) Modified from Nigel Goodwin's RS232 tutorial. * ; 2) Added indirect addressing to get more than one byte. * ; 3) Original code in Serial Data Generator2 * ;********************************************************************** list p=12F509 ;list directive to define processor #include ;processor specific variable definitions errorlevel -302, -207 __CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _XT_OSC ; __CONFIG 0FF9 ;***** VARIABLE DEFINITIONS #define B_Out GPIO,1 ;Pin 6 = GP1 #define CTS GPIO,0 ;Pin 7 = GP0 List d1 equ 0x19 ;delay constant d2 equ 0x1A ;delay constant d3 equ 0x1B ;delay constant B_count equ 0x1C W_Byte equ 0x1D LCD_on equ 0x1E LCD_clr equ 0x1F Byte_0 equ 0x07 Byte_1 equ 0x08 Byte_2 equ 0x09 Byte_3 equ 0x0A Byte_4 equ 0x0B Byte_5 equ 0x0C Byte_6 equ 0x0D Byte_7 equ 0x0E Byte_8 equ 0x0F Byte_9 equ 0x10 Byte_A equ 0x11 Byte_B equ 0x12 Byte_C equ 0x13 Byte_D equ 0x14 Byte_E equ 0x15 Byte_F equ 0x16 Byte_10 equ 0x30 ;beginning of second line Byte_11 equ 0x31 Byte_12 equ 0x32 Byte_13 equ 0x33 Byte_14 equ 0x34 Byte_15 equ 0x35 Byte_16 equ 0x36 Byte_17 equ 0x37 Byte_18 equ 0x38 Byte_19 equ 0x39 Byte_1A equ 0x3A Byte_1B equ 0x3B Byte_1C equ 0x3C Byte_1D equ 0x3D Byte_1E equ 0x3E Byte_1F equ 0x3F ;********************************************************************** ORG 0x3FF ; processor reset vector ; Internal RC calibration value is placed at location 0x3FF by Microchip ; as a movlw k, where the k is a literal value. ORG 0x000 ; coding begins here movwf OSCCAL ; update register with factory cal value Start movlw b'001001' ; sets pins GPIO,3(MCLR)and GPIO,0(CTS)to input tris GPIO movlw b'10000000' ; weak pull-ups enabled (bit6 = 0) option Initialize_LCD bsf gpio,1 ;set B_out high ; call dly_2E5 ;200 mS, needs only 100 mS TurnLCD_on ;may not be necessary = default condition when movlw 0x18 ;powered on movwf LCD_on movlw 0x08 movwf B_count bcf B_Out ;start bit ; call dly_417 ;start bit On_Loop rrf LCD_on,f ; btfss status,c bcf B_Out btfsc status,c bsf B_Out ; call dly_417 decfsz B_count,f goto On_Loop bsf B_out ;stop bit ; call dly_417 ;stop bit ; call dly_2E5 ;5mS delay required by LCD Set_Bytes ;Set character ascii to display movlw 0x48 ;H movwf Byte_0 movlw 0x41 ;A movwf Byte_1 movlw 0x50 ;P movwf Byte_2 movlw 0x50 ;P movwf Byte_3 movlw 0x59 ;Y movwf Byte_4 movlw 0x09 ;space right movwf Byte_5 movlw 0x42 ;B movwf Byte_6 movlw 0x41 ;A movwf Byte_7 movlw 0x42 ;B movwf Byte_8 movlw 0x59 ;Y movwf Byte_9 movlw 0x09 ;SPACE movwf Byte_A movlw 0x09 ;SPACE movwf Byte_B movlw 0x42 ;B movwf Byte_C movlw 0x41 ;A movwf Byte_D movlw 0x42 ;B movwf Byte_E movlw 0x59 ;Y movwf Byte_F ;Second Line bsf FSR,5 ;sets bank select bit in FSR to bank1 movlw 0x31 ;1 movwf Byte_10 movlw 0x32 ;2 movwf Byte_11 movlw 0x33 ;3 movwf Byte_12 movlw 0x34 ;4 movwf Byte_13 movlw 0x35 ;5 movwf Byte_14 movlw 0x36 ;6 movwf Byte_15 movlw 0x37 ;7 movwf Byte_16 movlw 0x38 ;8 movwf Byte_17 movlw 0x39 ;9 movwf Byte_18 movlw 0x61 ;a movwf Byte_19 movlw 0x62 ;b movwf Byte_1A movlw 0x63 ;c movwf Byte_1B movlw 0x64 ;d movwf Byte_1C movlw 0x65 ;e movwf Byte_1D movlw 0x66 ;f movwf Byte_1E movlw 0x67 ;g movwf Byte_1F bcf fsr,5 ;switches back to bank0 SetFSR_0 movlw 0x07 movwf FSR Poll_CTS btfsc CTS ;CTS pin active low goto Poll_CTS ;TurnLCD_on ;Poll_CTS ; call dly_10E3 ;debounce 10 mS delay btfss CTS goto Clear_LCD ;carriage return, screen clear, cursor 0,0 goto Poll_CTS Clear_LCD ;send 0x0C -- Form Feed movlw 0x0C movwf LCD_clr movlw 0x08 movwf B_count bcf B_Out ;start bit ; call dly_417 ;start bit Clear_Loop rrf LCD_clr,f ; btfss status,c bcf B_Out btfsc status,c bsf B_Out ; call dly_417 decfsz B_count,f goto Clear_Loop bsf B_out ;stop bit ; call dly_417 ;stop bit ; call dly_2E5 ;5mS delay required by LCD ;SetFSR_0 ;line 1 ; movlw 0x07 ; movwf FSR PreserveByte clrw movf indf,w movwf W_Byte goto Counter Counter movlw 0x08 movwf B_count bcf B_Out ;start bit ; call dly_417 ;start bit Ser_Loop rrf W_Byte,f btfss status,c bcf B_Out btfsc status,c bsf B_Out ; call dly_417 decfsz B_count,f goto Ser_Loop bsf B_out ;Stop bit ; call dly_417 ;stop bit ;******************************************************************************* btfss fsr,5 ;check data memory bank to chose done routine goto Done_B0 goto Done_B1 Done_B0 ;checks if Bank0 is finished bcf status,z ;These steps are to check whether FSR has maxed movlw b'11010110' ;to 0x16 for line 1. NB, must use b'11010110' instead xorwf FSR,w ;od b'10110' because the unimplemented bits read as 1's. btfss status,z goto Byte_plus ; call dly_8E5 goto SetFSR_1 ;SetFSR_0 Done_B1 bcf status,z movlw b'11111111' ; xorwf fsr,w ; btfss status,z ; goto Byte_plus ; call dly_8E5 goto SetFSR_0 ;Poll_CTS ;******************************************************************************* Byte_plus incf fsr,f goto PreserveByte SetFSR_1 bsf fsr,5 movlw 0x30 ;b'11110000' ;F0 = 0x30 plus b'11000000' movwf FSR goto PreserveByte ;******************************************************************************** ;DELAYS dly_68 movlw 0x12 ;was 0x14 movwf d1 goto delay_0 dly_104 movlw 0x1F ;1E was better?was 22 movwf d1 goto delay_0 dly_417 movlw 0x87 ;piclist calc. 0x8A;0x88 =420 movwf d1 goto delay_0 dly_5E3 movlw 0xE7 movwf d1 movlw 0x04 movwf d2 goto delay_1 dly_10E3 movlw 0xE7 movwf d1 movlw 0x08 movwf d2 goto delay_1 dly_2E5 movlw 0x3F movwf d1 movlw 0x9D movwf d2 goto delay_1 dly_8E5 movlw 0x6D movwf d1 movlw 0xBF movwf d2 movlw 0x02 movwf d3 goto delay_2 delay_0 decfsz d1,f goto delay_0 retlw 0 delay_1 decfsz d1,f goto $+2 decfsz d2,f goto delay_1 retlw 0 delay_2 decfsz d1,f goto $+2 decfsz d2,f goto $+2 decfsz d3,f goto delay_2 retlw 0 END