Hello Everyone!
I recently started using PIC microcontollers for a project that I want to complete. I found the 2 Wire LCD program and schematic by Mike Predko at http://www.rentron.com/Myke1.htm The assembly code was written for the PIC16C84 and thought that I might be able to port it over to the PIC16F88 instead. I've been trying everything that I can and hunting through the online forums for any clue that might help me get it operational.
If anyone would be so kind to look over the code that has been modified from the original, unsuccessfully.
I know it has been done by someone else using the C language, however, I'm liking the assembly language and how easy it is to compile it into the .HEX file. The page with the C language code is located at: http://ghmicro.com/index.php?option...cd-interface&catid=6:16f88&Itemid=2&showall=1 if this helps at all.
The .asm file has been attached as a .txt document and the code has also been copied below:
Thanks for any insights you might be able to provide. I really, really appreciate it!
Jared
I recently started using PIC microcontollers for a project that I want to complete. I found the 2 Wire LCD program and schematic by Mike Predko at http://www.rentron.com/Myke1.htm The assembly code was written for the PIC16C84 and thought that I might be able to port it over to the PIC16F88 instead. I've been trying everything that I can and hunting through the online forums for any clue that might help me get it operational.
If anyone would be so kind to look over the code that has been modified from the original, unsuccessfully.
I know it has been done by someone else using the C language, however, I'm liking the assembly language and how easy it is to compile it into the .HEX file. The page with the C language code is located at: http://ghmicro.com/index.php?option...cd-interface&catid=6:16f88&Itemid=2&showall=1 if this helps at all.
The .asm file has been attached as a .txt document and the code has also been copied below:
Rich (BB code):
; Using 2WireLCD to write messages to LCD Screen
; - 4 Bit Mode
; - Data is shifted out to a 74LS174 with The High Order Bit being a "Gate"
; Bit connected to the LCD's "E" line. The next Highest Bit goes to the
; LCD's "RS" Bit. The lowest Bit goes to D4 (and each Bit is higher from
; there).
;
; Hardware Notes:
; - Reset is tied directly to Vcc and PWRT is Enabled.
; - The PIC is a 16F88 Running at 4 MHz.
; - PortA.0 is the Data Bit
; - PortA.1 is the Clock Bit
;
; Shift Data:
; Bit 1 - Always High (Gate for "E")
; Bit 2 - RS Bit
; Bit 3 - LCD D4
; Bit 4 - LCD D5
; Bit 5 - LCD D6
; Bit 6 - LCD D7
;
LIST P=16F88, R=DEC ; 16F88 Decimal
errorlevel 0,-305
INCLUDE "P16F88.inc"
; Register Usage
CBLOCK 0x00C ; Start Registers at End of the Values
Dlay ; 8 Bit Delay Variable
Temp ; Temporary Value Used When Sending Out Data
NOTemp ; Temporary Value to "NybbleOutput"
CounterA ; Counter Value - For Time Delay Calculations
CounterB ; Counter Value - For Time Delay Calculations
CounterC ; Counter Value - For Time Delay Calculations
Next2 ; Don't know why but MPLAB IDE told me I needed this one
ENDC
; Define Inforation
#DEFINE Data PORTA,0
#DEFINE Clock PORTA, 1
; Macros
ClockStrobe MACRO ; Strobe the Data Bit
bsf Clock
bcf Clock
ENDM
EStrobe MACRO ; Strobe the "E" Bit
bsf Data
bcf Data
ENDM
PAGE
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
org 0
clrf PORTA
clrf PORTB
bsf STATUS, RP0 ; BANK 1
movlw b'01100000' ; Set internal osc to 4Mhz
movwf OSCCON & 0x7F
movlw b'111100' ; Set PortA 0 & 1 to Digital I/O - Added 8-24-10
movwf ANSEL ; Write the data to ANSEL File - Added 8-24-10
movlw 0x07 ; Load 7 into W register - Added 8-24-10
movwf CMCON ; CMCON = contents of W register 7h - Added 8-24-10
movwf TRISA ^ 0x080
bcf STATUS, RP0 ; BANK 0
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
;----------------------------------------------------------------------
;OutPut Message Screen 1 Line 1
call OutLoopA
call IntroMessageLine1
call OutLoopC
;----------------------------------------------------------------------
;Delay 1 Second Before Displaying Screen 1 Line 2
Next1 ; Next Line
call Delay1s ; 1 Second Delay
movlw 0x0C0 ; Move to Next Line on LCD
call SendINS
;----------------------------------------------------------------------
;OutPut Message Screen 1 Line 2
call OutLoopA
call IntroMessageLine2
call OutLoopC
;----------------------------------------------------------------------
;Delay 4 Seconds Before Clearing LCD Screen and Displaying Next Screen
Next4 ; 4 Second Delay Loop
call Delay1s ; 1 Second Delay
call Delay1s ; + 1 Second Delay = 2 Second Delay
call Delay1s ; + 1 Second Delay = 3 Second Delay
call Delay1s ; + 1 Second Delay = 4 Second Delay (5 Seconds Total)
;----------------------------------------------------------------------
;Display Program 1 Screen Line 1
call ClearDR
call OutLoopA
call Prog1Line1
call OutLoopC
;----------------------------------------------------------------------
;Display Program 1 Screen Line 2
call OutLoopA
call Prog1Line2
call OutLoopC
Loop123
goto Loop123 ;Loop forever until code development continues...
;----------------------------------------------------------------------
;Output Loops for Sending Text to LCD Screen
OutLoopA
clrf FSR ; Output the Message
OutLoopB
movf FSR, w ; Get the Offset to Output
incf FSR
return
OutLoopC
iorlw 0 ; At the End of the Line?
btfsc STATUS, Z
goto NextLn ; Yes - Equal to Zero
call SendCHAR ; Output the ASCII Character
goto OutLoopB
return
;----------------------------------------------------------------------
;Commands for Clearing LCD Screen & RAM
ClearDR
movlw 0x001 ; Clear the Display & RAM
call SendINS
call Dlay5 ; Can take up to 4.c1 msecs
return
;----------------------------------------------------------------------
;Commands for Moving to the Next Line on the LCD Screen
NextLn ; Next Line
movlw 0x0C0 ; Move to Next Line on LCD
call SendINS
return
; Subroutines
;----------------------------------------------------------------------
IntroMessageLine1 ; Message to Output
addwf PCL ; Output the Characters
dt "Initializing...", 0
;----------------------------------------------------------------------
;Commands to Send Characters to LCD Screen
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
;----------------------------------------------------------------------
IntroMessageLine2 ; Message to Output
addwf PCL ; Output the Characters
dt "Loading Menu...", 0
goto SendCHAR
;----------------------------------------------------------------------
Prog1Line1 ; Message to Output
addwf PCL ; Output the Characters
dt "Program #1:", 0
goto SendCHAR
;----------------------------------------------------------------------
Prog1Line2
addwf PCL ; Message to Output
dt "Reflex Timing", 0
goto SendCHAR
;----------------------------------------------------------------------
;Commands to Send Instructions to LCD Screen
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
;----------------------------------------------------------------------
;Commands to Sending Nibbles to LCD Screen
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
NOLoop1
ClockStrobe
decfsz Dlay
goto NOLoop1
bsf Data ; Put out the Gate Bit
ClockStrobe
bcf Data ; Put out the RS Bit
rlf PORTA
ClockStrobe
movlw 4 ; Now, Shift out the Data
movwf Dlay
NOLoop2
rlf NOTemp ; Shift Through the Nybble to Output
bcf Data ; Clear the Data Bit (which is the Clock)
rlf PORTA ; Shift the Carry into the Shift Register
ClockStrobe
decfsz Dlay
goto NOLoop2
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
;----------------------------------------------------------------------
Delay1s ; Delay Loop for 1 Second
movlw 6
movwf CounterC
movlw 24
movwf CounterB
movlw 167
movwf CounterA
loop decfsz CounterA,1
goto loop
decfsz CounterB,1
goto loop
decfsz CounterC,1
goto loop
return
;----------------------------------------------------------------------
end
Jared
Attachments
-
9 KB Views: 69