'========================================================== ' ' PicStic4 PicBASIC Pro Demo for saving strings [ending w/CR] into ' the EEPROM of PicStic4 and retrieving them at random ' '========================================================== ' Include "MODEDEFS.BAS" B0 var byte 'SERIAL INPUT CHARACTER VARIABLE B1 var byte 'EEPROM DATA VARIABLE [ODD OR EVEN] B2 var byte 'ODD [MSB] EVEN [LSB] ADDRESS POINTER OF THE EEPROM DATA B3 var byte 'SEARCH VARIABLE B4 var W2.byte0 '[LSB W2] IS THE ADDRESS LOCATION POINTER INTO THE EEPROM [BYTE POINTER] B5 var W2.byte1 '[MSB W2] IS THE ADDRESS LOCATION POINTER INTO THE EEPROM [BYTE POINTER] B6 var W3.byte0 '[LSB W3] IS THE ADDRESS LOCATION POINTER [WORD POINTER] B7 var W3.byte1 '[MSB W3] IS THE ADDRESS LOCATION POINTER [WORD POINTER] B8 var byte 'TEMPORARY VARIABLE STORAGE FOR B4 B9 var byte 'TEMPORARY VARIABLE STORAGE FOR B5 B19 var byte 'COMMAND [FOR PASS] B20 var byte 'LSB OF THE PARAMETER [FOR PASS] B21 var byte 'MSB OF THE PARAMETER [FOR PASS] W2 var word W3 var word SYMBOL EE86 = 1983 '2048 - 64 - 1 = 1983 BYTES START: W3=0 START1: SEROUT 7,N9600,["1-Write EEPROM",13,10] SEROUT 7,N9600,["2-Read EEPROM",13,10] SERIN 6,N9600,B0 if B0=49 then EWR if B0<>50 then START1 ERD: SEROUT 7,N9600,["Print String #? [0-255]"] SERIN 6,N9600,#B0 FOR B3=0 TO B0 ERD1: if W3>EE86 then ERD4 GOSUB RADRS if B3<>B0 then ERD2 SEROUT 7,N9600,[B1] 'print if this is it ERD2: W3=W3+1 if B1=10 then ERD3 GOTO ERD1 ERD3: NEXT B3 GOTO START ERD4: SEROUT 7,N9600,[13,10,"END of EEPROM",13,10] : GOTO START EWR: SEROUT 7,N9600,["Enter characters",13,10] SEROUT 7,N9600,["CR ends string",13,10] SEROUT 7,N9600,["CR CR quits",13,10] B2=0 EWR1: if W3>EE86 then ERD4 SERIN 6,N9600,B0 if B0=13 and B2=0 then EWR3 if B0=13 and B2<>0 then ERD4 B2=0 EWR2: SEROUT 7,N9600,[#W3,32,B0,13,10] GOSUB WADRS W3=W3+1 if W3>EE86 then ERD4 if B0=13 then EWR4 GOTO EWR1 EWR3: B2=1 : GOTO EWR2 EWR4: B0=10 : goto EWR2 SADRS: w2=w3/2 B19=30 : B20=B4 : B21=B5 : REM SET EEPROM ADDRESS call PASS if B19=30 and B20=255 and B21=255 then SADRS1 gosub ERR : goto SADRS SADRS1: RETURN RADRS: GOSUB SADRS B19=32 : B20=0 : B21=0 : REM READ EEPROM ADDRESS call PASS if B19=32 then RADRS1 gosub ERR : goto RADRS RADRS1: W2=W3//2 if W2=1 then RADRS3 RADRS2: B1=B20 : RETURN RADRS3: B1=B21 : RETURN WADRS: GOSUB RADRS B8=B20 : B9=B21 GOSUB SADRS W2=W3//2 if W2=1 then WADRS2 WADRS1: B20=B0 : B21=B9 : GOTO WADRS3 WADRS2: B21=B0 : B20=B8 WADRS3: B19=31 : REM WRITE EEPROM ADDRESS call PASS if B19=31 and B20=255 and B21=255 then WADRS4 gosub ERR : goto WADRS3 WADRS4: RETURN ERR: SEROUT 7,N9600,["Comm Error-",#B19,13,10] : RETURN