Shop OBEX P1 Docs P2 Docs Learn Events
Code help with 4 bit LCD and running out of memory. — Parallax Forums

Code help with 4 bit LCD and running out of memory.

Rob_CRob_C Posts: 1
edited 2010-11-12 12:21 in General Discussion
I am a relative noob at this and have cobbled together examples of code to manage to get my batch of sx28's to do what I need (kindof)

I am using a sx28 @ 50Mhz in conjunction with the 4 bit lcd code example I found on here (4x16).

My main objective is timing measurement based on a pulse which the sx measures. There are 2 modes which this is done, one if a pulse which derives a time and the 2nd derives rpm which can be seen by my horrible methods to get to the correct numbers.
Timing wise I am expecting pulses in the region of 14~16 Hz which are converted to be either 45.x seconds or 25000 RPM by either 168000 / pulse width or pulse width * 718 and then dividing down to get the correct numbers. This also use WORD var so eat memory.

My mode select needs to be a interrupt but at present my other code is too hungry to do this at present. Can anyone suggest better examples ?

I have tried to optimise the code as much as possible using arrays but I have found my limit ! Am considering using stamp / propeller.

edit
lcd.sxt is this (wont allow to upload)
'***************************************************************************
' LCD.sxt - LCD Input / Output Subroutines
' Version 1.04 - 11/12/2005 - JJC
'***************************************************************************
' Summary:
' These routines are used to communicate with a parallel LCD panel.
' I used RB.4-RB.7 to free up RB.0-RB.2 for ADC type work.
'
' Assumptions:
' LCD is using 4 pin parallel interface.
' LCD is wired as:
' 1 Ground
' 2 +5vdc
' 3 connect to ctr tap 10K Pot for contrast control
' 4 SX RA.0 (Register Select) = LCDRS
' 5 Ground
' 6 SX RA.1 (Enable) = LCDE
' 7 Ground
' 8 Ground
' 9 Ground
' 10 Ground
' 11 SX RB.4
' 12 SX RB.5
' 13 SX RB.6
' 14 SX RB.7
' 15 backlight control (not used in this program)
' 16 backlight control (not used in this program)
'
' IO Pins
' LCDRS var RA.0 ' Recieve/Send pin for LCD Module
' LCDE var RA.1 ' Enable pin for LCD Module
'
' Constants
' see LCD-con.sxt
'
' Variables
' see LCD-var.sxt
'
' Subroutine Declarations
' see LCD-sub.sxt
'
'===========================================================================
' LCD SUBROUTINES
'===========================================================================
LCDInit:
LCDData = $30 ' Write a 3 out to the display 3 times.
LCDPulse
LCDPulse
LCDPulse
LCDData = $20
LCDPulse ' Now go to 4-bit mode ($30 for 8 bit mode)
LCDPulse ' this is another command
LCDData = $80 ' Tell it to use the 2-line mode
LCDPulse ' Note: 1x16 modules only work in 2 line mode
LCDcmd LCD_Blink ' Blink cursor
LCDcmd LCD_CursorOn ' Activate cursor
LCDclear ' subroutine to clear LCD
LCDSize = LCD_Width * LCD_Lines ' set max len cursor index
return

'
LCDClear:
' Clear the screen
LCDcmd 1 ' 1=Clear Screen
LCDCol = 0 ' set column position to zero
pause 10 ' allow LCD time to catch up
return

'
LCDCmd:
' Send the character to the LCD device as a command
LOW LCDRS ' LCD Register Select 0=command, 1=normal letter
LCDout __PARAM1
HIGH LCDRS
return
'
LCDOut:
' Send the character to the LCD device as a letter
' This routine sends the upper 4 bits first then
' sends the lower 4 bits.
LCDChr = __PARAM1 ' Write to the LCD (4 bits at a time).
LCDData = LCDChr & $F0
LCDPulse
LCDChr = LCDChr << 4
LCDData = LCDChr & $F0
LCDPulse
return
'
LCDPos:
' Set the cursor to the specified position
' Note: that all displays think that
' line 2 starts at pos 64 even if
' they don't have that many characters.
LCDCol = __PARAM1
LCDCol = LCDCol // LCDSize
LCDP1 = 0
LCDP2 = LCDCol // LCD_Width
If LCDCol >= LCD_Width then
LCDP3 = LCDCol / LCD_Width
LOOKUP LCDP3,0,64,LCD_Width,80,0,LCDP1
endif
LCDP1 = LCDP1 + LCDP2
LCDP1 = LCDP1 + $80
LCDcmd LCDP1
PAUSE 1
return

'
LCDPulse:
' Pulse the Enable Bit
PULSOUT LCDE,5,100
return
'===========================================================================

Comments

  • ZootZoot Posts: 2,227
    edited 2010-11-12 12:21
    Moving your modulo (//) into a subroutine will certainly help. Division and modulus operations generate fairly long lengths of code; if you use either operator more than once in your application, it is much better to wrap them into a subroutine so the main code for the operation is only generated once.
Sign In or Register to comment.