Shop OBEX P1 Docs P2 Docs Learn Events
Need help with my 8 bit LCD code — Parallax Forums

Need help with my 8 bit LCD code

Capt. QuirkCapt. Quirk Posts: 872
edited 2007-02-14 09:23 in General Discussion
I have been working for months now on trying to develop my own 8 bit LCD SX/B code. I have a few converted BS2 programs that will display a message, but I need to display real time data and Bean's last contribution will fix that (thanks Bean).

Also thanks to·Jonny Mac, the Debuging info has been helpful, but I am still working on·intergrating assm examples into sx/b.

The code I am posting, I was trying to make use of the latest SX/B 1.5 changes and kinda used the BS2PE commands as a guideline to what can be done with SX/B. I been trying to do it this way in order to better learn the SX-Key and SX-Sim debugging tools, but watching data flow and execution timmings for this hitachi parallel clone has lead me to whits end.


So far this code seems to flow right, but I think I am still·have some timming issues. The best I have gotten so far was, a underline cursor, but it didn't blink like it should have.

' =========================================================================
'
'·· File...... myOwnLcdCode_test.sxb
'·· Purpose... SX/B LCD Initialization routine
'·· Author.... Bill Mazzacane
'·· E-mail....
'·· Started...12/02/07
'·· Updated...
'
' =========================================================================

'
' Program Description
'

'
' Device Settings
'
· DEVICE········· SX28, OSCHS2, TURBO, STACKX, OPTIONX
· FREQ··········· 4_000_000
· ID············· "SXB 1.50"
'
'· IO Pins
'
· ctrlBus·············· ·VAR···· RA······················ ' Enable pin
· lcdBus················ VAR··RB
'· RA.1 = E
'· RA.2 = RW
'· RA.3 = RS
'· 8 Bit data = RB.0 thru RB.7
'
' Constants
'
' None
'
' Variables
'
· char··········· VAR···· Byte··················· 'character sent to LCD
· idx············· VAR···· Byte··················· 'loop counter
· temp1········· VAR···· Byte ·················· 'Byte variable passed to subroutine
' =========================================================================
· PROGRAM Start
' =========================================================================
Msg:·····
········· DATA· "The SX RULES!", 0·· ···' store message
'
' Subroutine Declarations
'
LCD_CMD····SUB, 1·······'Main contol subroutine
'
' Program Code
'

Start:
··PAUSE 100··································· ' let the LCD settle
·TRIS_A = %0000······························ 'Set RA to outputs
·TRIS_B = %00000000
·

Lcd_Setup:
· LCD_CMD %00110000 ···················· '8-bit mode, lcdBus remains at steady state·······
··· ················································ 'until changed
· LCD_CMD %00001110·······················'on, crsr, blink, **** For Debug only ****
· LCD_CMD %00000110 ···················· 'inc crsr, no disp shift·························


Main:
· DO
··· READ Msg + idx, char······················'get character from EE
· IF char = 0 THEN EXIT······················ 'if 0, message is complete
·· ·LCD_CMD char·······························'write the character
··· idx = idx + 1································· 'point to next character
· LOOP
END····································

'
' Subroutine Code
'
LCD_CMD:································ 'Main contol subroutine
·· ctrlBus = %0000 ···················· 'Set lcd for input
·· temp1 = __param1·················· 'Pass byte variable
·· IF temp1 = %00110000 THEN··'Instruction for 8 bit interface, No busy flsg is required
·· lcdBus = temp1······················· 'Pass byte variable to lcd
·· PULSOUT RA.1, 0····················· 'Strobe enable
·· PAUSE 5································ 'pause 5 m/s
·· PULSOUT RA.1, 0····················· 'Strobe enable
·· PAUSEUS 100·························· 'Pause 100 u/s
·· PULSOUT RA.1, 0······················ 'Strobe enable
·· PAUSEUS 100·························· 'Pause 100 u/s
·· ctrlBus = %0011······················ 'Reset SX to recieve data from lcd
ELSE··························· ·' All other instructions use the busy flag
·· ctrlBus = %0100······················· 'set E high before variable is sent
·· lcdBus = temp1························ 'Pass byte variable to lcd
·· ctrlBus = %0000························ 'set E low to allow variable to send
·· PAUSEUS 200······························ 'Pause 200 u/s
·· ctrlBus = %0010······················· 'set RW high before checking busy flag
·· TRIS_B = %11111111················ 'set RB for input
DO UNTIL RB.7 = 0···················· 'wait for busy flag to clear
··· PULSOUT RA.1, 0···················· 'Strobe enable before checking busy flag again
LOOP
· TRIS_B = %00000000··············· 'Reset RB for output
·· ctrlBus = %0011······················ 'Reset SX to recieve data from lcd
·ENDIF
RETURN

' =========================================================================
' User Data
'tried using the busy flag with the SX since the timming is so much faster than the BS2.
'LCD clock @ 2Mhz
' =========================================================================
Pgm_ID:
· DATA· "SX/B 1.50 Template", 0

Post Edited (Capt. Quirk) : 2/13/2007 1:19:36 AM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2007-02-12 23:13
    Bill,
    Are you using a 4MHz resonator ? OSCHS2 is good for 4MHz. Try OSCXT1.
    If you want to use the internal 4MHz, then use OSC4MHZ on the device line.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-02-12 23:55
    Thanks Bean, no go. I tried·4mhz each way I could think of. I reduced it down from the overkill of a 50 mhz yesterday. But soon after I get this part working, I'll need to have it read·9000 + pulses/sec from an hall sensor and control an ignition and fuel injection system (and I can't even get an lcd to work, oh boy)

    I know the set-up works. It's on a profesional development board and when I switch the wires over to the BS2, I get a full display in 8 or 4 bit mode and the 4 bit SX assm code works great too.

    Yesterday I used the SX-Sim for the first time and figured out the time involved for each line of code and using the hitachi timming diagrams and I thought I would finally get it to work. but nogo. This code is based off that previous days work, but I tried to keep it a bit more simple. I thought by using a "control bus", I could more accurately control functions like "pulsout" and control the times with "pause" & "pauseus"·. much of the code exucuted in .02 - .05 u/s.

    I did make one change since the post, but I don't think it helped (idx = 0).

    Post Edited (Capt. Quirk) : 2/13/2007 12:05:14 AM GMT
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-02-13 17:18
    Please do not waste your time with this thread, I purchased a serial lcd today from parallax. TY
  • JonnyMacJonnyMac Posts: 8,941
    edited 2007-02-13 18:08
    If you ever do decide to "roll your own" the serial LCD project in the SX/B help file works.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-02-14 09:23
    In the past I have tried to strip the "Example Code" program down and insert it into some BS2 code, but I never got it to work. Some of that was from knowing nothing·about Serial Communications and the· "__Param1, __Param2" family of code (what I could use or not). But my·journey ("the old keep trying things until the @#@% compiler likes it method") has changed that, especially from trying to serial out to a terminal and learning the SX/B code improvements.
    ·
    I really think it's funny that the night before I receive my new serial LCD, I figured it out. LMAO !!
    ·
    It's defiantly not a bad thing, I have been wanting to use the "Example Code" to to serial in my ADC info and interface the LCD to a few buttons or a·4 x 4 keyboard. (no reason to carry around a lap top, huh).
    ·
    Thanks Bean & Jonny Mac for the help.
    ·
    Bill
Sign In or Register to comment.