Help please

HAZELEB

Member
Hi, I have an 18x connected to the LCD using the Serial LCD firmware and 24lC16B EEPROM
I am trying to write the letters A-Z and 0-9 to the EEPROM and then read then back alphabetically
To spell out a name on the LCD, I want to use a push switch to move through the alphabet until
I find the letter then advance the cursor for the next one until I have spelt the name and then save back into another block of the EEPROM to recall at a latter date, I am not sure if this is the best way to do this or if it can be done, I am not looking for someone to right a program for me just a bit of help please Thanks.
 

ylp88

Senior Member
I did something similar a LONG time ago with a 28X. It split the EEPROM into its 8 separate locations for 8 different messages. The register was selectable at runtime and the program would prompt the user to select which register to use, then after selection of the register, whether they wanted to read the register, or write to it. Long messages would automatically scroll. The LCD was not serially interfaced - direct parallel connection.

A start-up routine consisted of the firmware version and a welcome message. After a period of time, it would prompt the user to press the "Start" button until which time it would display the temperature from a digital temperature sensor.

I usually don't do this but I'll post the code in full because you probably can't use it without quite a lot of modification and even still, it is not exactly what you want. Perhaps it can be of some "inspiration"...

Hopefully the comments will help you follow my mediocre programming. The code can easily be optimised but works fine as it is. It was built into a working circuit (from breadboard to PCB) so all should be good...

<code><pre><font size=2 face='Courier'>' DECLARE PINOUTS
' Analog 0 - Light Level Sensor
' 1 - Not Used
' 2 - Not Used
' 3 - Not Used
' Input 0 - Button: Select
' 1 - Button: Right
' 2 - Button: Left
' 3 - i2c Clock
' 4 - i2c Data
' 5 - Dallas One-Wire Temperature Sensor
' 6 - Not Used
' 7 - Not Used
' Output 0 - LCD Backlight
' 1 - Busy LED Indicator
' 2 - LCD: Register Select (RS)
' 3 - LCD: Enable (E)
' 4 - LCD: Par. Data 4 (DB4)
' 5 - LCD: Par. Data 5 (DB5)
' 6 - LCD: Par. Data 6 (DB6)
' 7 - LCD: Par. Data 7 (DB7)

' DECLARE SYMBOLS
symbol btnSel = pin0
symbol btnRight = pin1
symbol btnLeft = pin2
symbol ledBusy = 1

' DECLARE INTERNAL EEPROM
eeprom 0, (&quot;Welcome Yang-Lit&quot;)
eeprom 16,(&quot;F/W Version 5.0a&quot;)
eeprom 32,(&quot;Select register:&quot;)
eeprom 48,(&quot;&lt;-Read | Write-&gt;&quot;)
eeprom 64,(&quot;Please wait... &quot;)
eeprom 80,(&quot;Temperature: &quot;)
eeprom 96,(&quot;File Saved! &quot;)
eeprom 112,(&quot;Press to Start &quot;)

' VARIABLE DECLARATION
' b0 = Temporary Temperature reading
' b1 = LCD Reserved (wrchr/wrins)
' b2 =
' b3 = For/Next loop
' b4 = Lookup position
' b5 =
' b6 =
' b7 =
' b8 =
' b9 =
' b10 =
' b11 =
' b12 =
' b13 =

' MAIN ROUTINE START

init: ' Initialize LCD in 4-bit mode
let pins = 0
let b4 = 0
pause 200
let pins = 48
pulsout 3,1
pause 10
pulsout 3,1
pulsout 3,1
let pins = 32
pulsout 3,1
pulsout 3,1
let pins = 128
pulsout 3,1
let b1 = 14

let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

reset:

b1 = 0
b2 = 0
b3 = 0
b4 = 0
b5 = 0
b6 = 0
b7 = 0
b8 = 0
b9 = 0
b10 = 0
b11 = 0
b12 = 0

b1 = 1 ' Clear screen
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

For b3 = 0 to 15 ' Introductory messages
read b3, b1 ' * &quot;Welcome Yang-Lit&quot; *

let pins = b1 &amp; 240 ' WRCHR
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1

Next b3

b1 = 192

let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

For b3 = 16 to 31
read b3,b1 ' * &quot;F/W Version 5.0a&quot; *

let pins = b1 &amp; 240 ' WRCHR
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1

Next b3

pause 1500

login:
b1 = b1 + 1
If b1 = 255 Then dispTemp
If btnLeft = 0 And btnRight = 0 And btnSel = 0 Then Login

b10 = 0
pause 250

b1 = 1 ' User select external EEPROM register
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

for b3 = 32 to 47
read b3,b1 ' * &quot;Select register:&quot; *

let pins = b1 &amp; 240 ' WRCHR
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1

pause 5
next b3

b1 = 192
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

b3 = 1

SelReg:

b1 = 192
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

b1 = b3 + 48
sertxd (b3)
let pins = b1 &amp; 240
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1

waitselreg:

if btnRight = 1 And b3 = 7 Then regMax
if btnRight = 1 And b3 &lt; 7 Then regUp
if btnLeft = 1 And b3 = 0 Then regMin
if btnLeft = 1 And b3 &gt; 0 Then regDown
if btnSel = 1 Then initReg

goto waitselreg

initreg:
pause 250
b3 = %10100000 + b3
i2cslave b3, i2cfast, i2cbyte ' Set block in EEPROM to use
b10 = b3

ReadorWrite: ' Ask user: &quot;Read or Write?&quot;
b1 = 1
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

for b3 = 48 to 64
read b3,b1

let pins = b1 &amp; 240 ' WRCHR
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1

pause 5
next b3

waitRW:
If btnLeft = 1 Then eeRead
If btnRight = 1 Then eeWrite
goto waitRW

' ******************

eeRead:
sertxd (&quot;Read process started&quot;,13)
b1 = 1
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

For b3 = 0 To 255 ' Read the whole message from external EEPROM
readi2c b3,(b1)
sertxd (b1)
If b1 = $FF Then MsgEnd

let pins = b1 &amp; 240 ' WRCHR
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1
pause 5
Next b3

MsgEnd: ' End of the message found
If b3 &lt; 15 Then Goto waitRST

b1 = 24

let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

pause 200

If btnSel = 1 Then reset

goto MsgEnd

' ******************

eeWrite:

b1 = 1
let pins = b1 &amp; 240
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

for b3 = 64 to 79 ' &quot;Please wait&quot; message as deleting takes time
read b3, b1
let pins = b1 &amp; 240
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1
pause 5
next b3

b1 = 192
let pins = b1 &amp; 240
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

for b3 = 0 To 255 ' Delete EEPROM data with $FF (255 or %11111111)
writei2c b3, ($FF)
pause 10
If b3 = 16 Or b3 = 32 Or b3 = 48 Or b3 = 64 Or b3 = 80 Or b3 = 96 Or b3 = 112 Or b3 = 128 Or b3 = 144 Or b3 = 160 Or b3 = 176 Or b3 = 192 Or b3 = 208 Or b3 = 224 Or b3 = 240 Or b3 = 256 Then pgbAdd
pgbAdded:
next b3

sertxd (&quot;Write process started&quot;,13)
b1 = 1
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

rstLU:
b4 = 0 ' Reset lookup position

For b3 = 0 to 255
lookup b4,(&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ &quot;,$ff,&quot;abcdefghijklmnopqrstuvwxyz &quot;,$ff,&quot;1234567890!@#$%^&amp;*()-+=:.?,&quot;,$FF),b1

let pins = b1 &amp; 240 ' WRCHR
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1
pause 5

pause 125 ' Debounce and switch delay

waitChrSel:
If btnLeft = 1 Then prevChr
If btnRight = 1 Then nextChr
If btnSel = 1 Then selChr
goto waitChrSel

nextChr:
If b4 &lt;&gt; 83 Then nextC
b4 = 255
nextC:
b4 = b4 + 1
goto ChrInc

prevChr:
If b4 &lt;&gt; 0 Then prevC
b4 = 84
prevC:
b4 = b4 - 1
goto ChrInc

chrInc:

b1 = 16
let pins = b1 &amp; 240 ' WRINS
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
pulsout 3,1
high 2

Next b3

goto rstLU

selChr:
b6 = b1
writei2c b5,(b1)
b5 = b5 + 1

If b1 = $FF Then wrEnd

'b1 = 192
'let pins = b1 &amp; 240 ' WRINS
'pulsout 3,1
'let b2 = b1 * 16
'let pins = b2 &amp; 240
'pulsout 3,1
'high 2

b1 = b6
let pins = b1 &amp; 240 ' WRCHR
high 2
pulsout 3,1
let b2 = b1 * 16
let pins = b2 &amp; 240
high 2
pulsout 3,1

If b5 &gt; 15 Then LCDscroll
goto chrInc


END ' ~ ~ ~ The End ~ ~ ~

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' '
' SUPPLEMENTARY ROUTINES HERE '
' '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

dispTemp: ' DISPLAY TEMPERATURE ON LCD '*
'*
If b10 &lt;&gt; 0 Then wrTemp '*
b1 = 1 ' Clear screen '*
let pins = b1 &amp; 240 ' WRINS '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
pulsout 3,1 '*
high 2 '*
'*
For b3 = 112 to 127 '*
read b3, b1 ' * &quot;Press to Start&quot; * '*
'*
let pins = b1 &amp; 240 ' WRCHR '*
high 2 '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
'*
Next b3 '*
'*
b1 = 192 '*
let pins = b1 &amp; 240 ' WRINS '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
pulsout 3,1 '*
high 2 '*
'*
For b3 = 80 To 95 ' * &quot;Temperature: &quot; '*
read b3,b1 '*
'*
let pins = b1 &amp; 240 ' WRCHR '*
high 2 '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
'* '*
Next b3 '* '*
'*
wrTemp: '*
For b3 = 1 To 3 '*
b1 = 16 '*
let pins = b1 &amp; 240 ' WRINS '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
pulsout 3,1 '*
high 2 '*
Next b3 '*
'*
readtemp 5,b0 ' Read the temperature '*
'*
b10 = b0 // 10 ' Split number into two digits '*
b0 = b0 / 10 '*
b1 = b0 // 10 '*
'*
b1 = b1 + 48 '*
let pins = b1 &amp; 240 ' Send first digit '*
high 2 '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
'*
b10 = b10 + 48 '*
b1 = b10 '*
'*
let pins = b1 &amp; 240 ' Send second digit '*
high 2 '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
'*
b1 = &quot;C&quot; ' &quot;C&quot; for Celcius '*
let pins = b1 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
'*
b1 = 0 '*
goto login '*

regMax: ' REGSEL BUFFER AT MAX. '*
b3 = 0 '*
pause 250 '*
goto SelReg '*

regUp: ' REGSEL BUFFER SET UP '*
b3 = b3 + 1 '*
pause 250 '*
goto SelReg '*

regMin: ' REGSEL BUFFER AT MIN. '*
b3 = 7 '*
pause 250 '*
goto SelReg '*

regDown: ' REGSEL BUFFER SET DOWN '*
b3 = b3 - 1 '*
pause 250 '*
goto SelReg '*

waitRST: '*
If btnSel = 1 Then reset '*
goto waitRST '*

LCDscroll: '*
b1 = 24 '*
let pins = b1 &amp; 240 ' WRINS '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
pulsout 3,1 '*
high 2 '*
goto chrInc '*

wrEnd: '*
For b3 = 96 To 111 ' * &quot;File Saved! &quot; '*
read b3,b1 '*
'*
let pins = b1 &amp; 240 ' WRCHR '*
high 2 '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
'* '*
Next b3 '*
wreset: '*
If btnLeft = 1 Or btnRight = 1 Or btnSel = 1 Then reset '*
goto wreset '*

pgbAdd: '*
b1 = $FF '*
let pins = b1 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
let b2 = b1 * 16 '*
let pins = b2 &amp; 240 '*
high 2 '*
pulsout 3,1 '*
pause 5 '*
goto pgbAdded '*

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' '
' SUBROUTINES ROUTINES HERE '
' '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</font></pre></code>

There... unedited, as is, as it was some two years ago...

<b><i>ylp88 </b> </i>
 

ylp88

Senior Member
Just realised how long it is... sorry. The main code is at the top while the sub-routines are at the bottom and are pretty standard. Most of the &quot;ideas&quot; will probably come from the top section.

<b>It might end up confusing you more than it help - post if you need clarification and I'll try and get back to you ASAP... Apologies in advance. </b>

And don't ask - I have no idea what all those &quot;*&quot; down the right-hand-side of the end of the program were for...

<b><i>ylp88 </b> </i>

Edited by - ylp88 on 26/03/2006 17:21:25
 

HAZELEB

Member
Hi. ylp88
Thanks for your fast response and the code I am sure all I need will be in there
It will take me some time to get my head around it but will let you now how I get
on many thanks again.

Regards,
Hazeleb.

 
Top