I been trying to change this to work on a 16f684 using a 74hc164 for the shift register. With no luck I was using some code that Myke Predko wrote in a book i have 123 pic microcontorller experiments.
I think the delays are not working right or it's FSR It's driving me crazy.
Thanks for any helpCode:list p=16f684 ; list directive to define processor #include <P16F684.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _FCMEN_OFF & _IESO_OFF cblock 0x020 Dlay ; 8 Bit Delay Variable Temp ; Temporary Value Used When Sending Out Data NOTemp ; Temporary Value to "NybbleOutput" endc #define Data PORTC,0 #define Clock PORTC,1 ; Macros ClockStrobe MACRO ; Strobe the Data Bit bsf Clock bcf Clock ENDM EStrobe MACRO ; Strobe the "E" Bit bsf Data bcf Data ENDM ORG 0x000 ; processor reset vector goto init ; go to beginning of program ORG 0x004 ; interrupt vector location init: banksel PORTC clrf PORTC movlw 07h movwf CMCON0 banksel ANSEL clrf ANSEL banksel TRISC movlw b'00000000' movwf TRISC banksel PORTC movlw b'00000000' movwf PORTC goto Set_LCD Set_LCD: call Dlay5 ; Wait 20 msecs before Reset call Dlay5 call Dlay5 call Dlay5 bcf STATUS, C ; Clear Carry (Instruction Out) movlw 0x03 ; Reset Command call NybbleOut ; Send the Nybble call Dlay5 ; Wait 5 msecs before Sending Again EStrobe call Dlay160 ; Wait 160 usecs before Sending the Third Time EStrobe call Dlay160 ; Wait 160 usecs before Sending the Third Time bcf STATUS, C movlw 0x02 ; Set 4 Bit Mode call NybbleOut call Dlay160 movlw 0x028 ; Note that it is a 2 Line Display call SendINS movlw 0x008 ; Turn off the Display call SendINS movlw 0x001 ; Clear the Display RAM call SendINS call Dlay5 ; Note, Can take up to 4.1 msecs movlw 0x006 ; Enable Cursor Move Direction call SendINS movlw 0x00C ; Turn the LCD Back On call SendINS clrf FSR ; Output the Message OutLoop movf FSR, w ; Get the Offset to Output incf FSR call Message iorlw 0 ; At the End of the Message? btfsc STATUS, Z goto Loop ; Yes - Equal to Zero call SendCHAR ; Output the ASCII Character goto OutLoop Loop ; Loop Forever when Done goto Loop ; Subroutines Message ; Message to Output addwf PCL ; Output the Characters dt "Hello", 0 SendCHAR ; Send the Character to the LCD movwf Temp ; Save the Temporary Value swapf Temp, w ; Send the High Nybble bsf STATUS, C ; RS = 1 call NybbleOut movf Temp, w ; Send the Low Nybble bsf STATUS, C call NybbleOut return SendINS ; Send the Instruction to the LCD movwf Temp ; Save the Temporary Value swapf Temp, w ; Send the High Nybble bcf STATUS, C ; RS = 0 call NybbleOut movf Temp, w ; Send the Low Nybble bcf STATUS, C call NybbleOut return NybbleOut ; Send a Nybble to the LCD movwf NOTemp ; Save the Nybble to Shift Out swapf NOTemp ; Setup to Output to the High Part of the Byte movlw 6 ; Clear the Shift Register movwf Dlay NO2Loop1 ClockStrobe decfsz Dlay goto NO2Loop1 movlw 5 ; #### - Now, Shift out the Data with the "RS" Bit movwf Dlay bsf Data ; Put out the Gate Bit ClockStrobe NO2Loop2 bcf Data ; #### - Clear the Data Bit (which is the Clock) btfsc STATUS, C ; #### - If the Bit to be output is a "1", Shift it Out bsf Data ClockStrobe rlf NOTemp ; #### - Shift the Next Bit into the Carry Flag decfsz Dlay goto NO2Loop2 EStrobe ; Strobe out the LCD Data return Dlay160 ; Delay 160 usecs movlw 256 - ( 160 / 4 ) ; Loop Until Carry Set addlw 1 btfss STATUS, C goto $-2 return Dlay5 ; Delay 5 msecs movlw 4 ; Set up the Delay movwf Dlay movlw 256 - 0x0E8 addlw 1 btfsc STATUS, Z decfsz Dlay goto $-3 return end
See i get this when I build the line it points to is the delay
Oh one more thing the lcd comes on and rolls out 8 squaresWarning[202] C:\2WIRE\2WIRE1.ASM 163 : Argument out of range. Least significant bits used.
Warning[202] C:\2WIRE\2WIRE1.ASM 174 : Argument out of range. Least significant bits used.



Reply With Quote

