#picaxe 20x2
#no_data
#no_table
#rem
This is done using the HSERIN on the 20x2 .... so pins 10 and 12. It takes 8.3 seconds
to push the full contents into the EEPROM ... which is pretty damn fast!
Although a menu is displayed on the serial output, you can't make menu entries unless you're
using the HSERIN pins; as it's configured to take input from there (the Python program needs
to be able to start the transaction).
The 08M2 program does the same thing, but does NOT use HSERIN ... so is constrained to a
slower baud ... deals with "disconnect" and "reconnect" for downloads, and takes around 70
seconds to fully load the eeprom ... still, not bad.
The loading is done in 64k or 128k chunks; so 'page writes' to the eeprom; which will help
extend the eeprom life.
If serial monitor is hooked up, the chip will output a random sentence from the eeprom load
ever 25 seconds or so ... it should do that around 30 times, then show the menu again...
If you hook up to the HSER pins, you can send a "D" to dump the entire contents of the eeprom
' A Standard Picaxe 20x2
' __________
' 5V VCC 1- | |- 20 0V GND
' Serial In 2- | |- 19 A.0 / Serial Out
' ADC 3 / C.7 3- | 20X2 |- 18 B.0 / ADC 1 / hint1
' C.6 4- | |- 17 B.1 / ADC 2 / hint2 / SRQ
' hpwm A / pwm C.5 / C.5 5- | |- 16 B.2 / ADC 4 / C2+
' hpwm B / SRNQ / C.4 6- | |- 15 B.3 / ADC 5 / C2-
' hpwm C / ADC 7 / C.3 7- | |- 14 B.4 / ADC 6 / hpwm D / C1-
' kb clk / ADC 8 / C.2 8- | |- 13 B.5 / ADC 10 / hi2c sda / hspi sdi
' hspi sdo / kb data / ADC 9 / C.1 9- | |- 12 B.6 / ADC 11 / hserin
' hserout / C.0 10- | |- 11 B.7 / hi2c scl / hspi sck
' ----------
'
' __________
' 5V VCC 1- | |- 20 0V GND
' Serial In 2- | |- 19 A.0 / Serial Out
' C.7 3- | 20X2 |- 18 B.0 RED LED
' C.6 4- | |- 17 B.1
' C.5 5- | |- 16 B.2
' C.4 6- | |- 15 B.3
' C.3 7- | |- 14 B.4
' C.2 8- | |- 13 B.5 hi2c sda
' BLUE LED C.1 9- | |- 12 B.6 hserin
' hserout C.0 10- | |- 11 B.7 hi2c scl
' ----------
' '
' Available Bytes: b0 - b55
' Available Words: w0 - w27
Byte Byte Variable Word Variable Word
B0 endSentence W0
B1
B2 eeprom_Byte W1
B3 serData
B4 serLoops W2
B5 menuCounter
B6 tempByte W3
B7 failure
B8 goodMark W4
B9
B10 W5
B11
B12 W6
B13
B14 W7
B15
B16 W8
B17
B18 W9
B19
B20 W10
B21
B22 tempRandom W11
B23
B24 eeprom_address W12
B25
B26 tempWord W13
B27
B28 W14
B29
B30 W15
B31
B32 W16
B33
B34 W17
B35
B36 W18
B37
B38 W19
B39
B40 W20
B41
B42 W21
B43
B44 W22
B45
B46 W23
B47
B48 W24
B49
B50 W25
B51
B52 W26
B53
B54 Counts W27
B55
#endrem
' symbol D1 = b.0 ' RED
' symbol D2 = c.1 ' BLUE
symbol LED = c.1 ' BLUE LED
symbol endSentence = bit0
symbol eeprom_byte = b2
symbol serData = b3
symbol ser_loops = b4
symbol menuCounter = b5
symbol tempByte = b6
symbol failure = b7
symbol goodMark = b8
symbol tempRandom = w11
symbol eeprom_address = w12
symbol tempWord = w13
symbol counts = w27
' Credit Hippy for below ... a cleaner way to hi2cout 128 individual bytes...
#define WR4 @ptrinc, @ptrinc, @ptrinc, @ptrinc
#define WR16 WR4, WR4, WR4, WR4
#define WR64 WR16, WR16, WR16, WR16
#define WR128 WR64, WR64
Setfreq m64 ' Rock and Roll!
#define pinBaud A.0,N19200_64
#define eeprom_ID %10100000
hi2csetup i2cmaster, eeprom_ID, i2cfast_64, i2cword
hsersetup b115200_32, %00001
readadc10 LED,tempRandom; ' Get initial seed value into random
' pause 2000 ' Time to download code if needed... Not disconnecting; not needed
main:
counts = 0
menuCounter = 0
gosub greeting:
do
gosub getInput:
if @ptr = "D" then ' Dump Eeprom
@ptr = 0;
gosub eepromDump:
else if @ptr = "W" then ' Write to eeprom
@ptr = 0;
gosub receiveAll:
exit ' Bail from the loop ...
else if @ptr = 0 then
serData = 0;
else
@ptr = 0;
serData = "R" ' Not valid entry; so "R" for reset
endif
counts = counts + 1
if counts > 200 then ' 200 loops = ~25sec at 64mhz
gosub randomSentence:
menuCounter = menuCounter + 1
toggle LED
counts = 0
endif
if menuCounter > 30 then ' reset loop;
menuCounter = 0
exit
endif
loop while serData <> "R" ' If "R" then go back to main; display greeting
goto main:
readData:
hi2cin eeprom_address,(eeprom_byte)
return
randomSentence:
endSentence = 0;
do
random tempRandom;
loop while tempRandom > 65534;
eeprom_address = tempRandom;
goodMark = 0
do
eeprom_address = eeprom_address + 1
gosub readData
if eeprom_byte = "." OR eeprom_byte = "?" then
goodMark = 1
endif
loop while goodMark = 0
eeprom_address = eeprom_address + 2 ' skip the space
do
gosub readData
serout pinBaud,(eeprom_byte);
if endSentence = 1 AND eeprom_byte = 34 then
return
endif
if endSentence = 1 AND eeprom_byte <> " " then
eeprom_byte = " "
endif
if eeprom_byte = "." OR eeprom_byte = "?" then let endSentence = 1
endif
eeprom_address = eeprom_address + 1
loop until eeprom_byte = " " AND endSentence = 1
serout pinBaud,(CR,LF);
return
greeting:
serout pinBaud,(CR,LF,"Hello There...",cr,lf)
serout pinBaud,("Enter 'D' For Dump of eeprom",cr,lf);
serout pinBaud,("Enter 'W' to write to eeprom",cr,lf);
serout pinBaud,("Enter 'R' to re-enable downloads",cr,lf);
serout pinBaud,(">");
return
eepromDump:
for eeprom_address = 0 to 65534 ' 32767 for 256k, 65534 for 512k
gosub readData
serout pinBaud,(eeprom_byte)
next eeprom_address
return
getInput:
serData = 0;
hserin [2000],0,1
ptr = 0
return
receivePage:
failure = 0;
hserptr = 0;
ptr = 0;
hserout 0,("G") ' 71 is G for "GO"!
hserin 0,128 ' Bring in 128 bytes store starting at Scratchpad 0
if hserptr <> 0 then ' 64 works for 64 bytes '0' means we rolled over from 127 ... so 128 bytes rcvd.
' hserout 0,(#ptr)
' hserout 0,(#hserptr)
hserout 0,("W") ' 87 = W for "Wait a sec, this is screwed up!"
failure = 1
return
endif
hserptr = 0
ptr = 0 ' Reset the pointer to 0 ... reading the full scratchpad
hi2cout eeprom_address, (WR128) ' Send 128 bytes to i2c see Defines above
return
receiveAll:
eeprom_address = 0x0000
for tempWord = 0 to 511
gosub receivePage:
if failure = 0 then
eeprom_address = eeprom_address + 128 ' should be 128 for 512k 64 for 256...
else
tempWord = tempWord - 1
endif
next tempWord
hserout 0, ("D") ' 68 is D for Done
return