Learing Memory
Archiver
Posts: 46,084
please help me I am just learing how to work with storing things in
the eeprom. for me to learn i made a program that has three buttons,
a motor and a few leds i added the read and write so it will remember
what the last speed was. here is the program
a var byte
b var byte
c var byte
speed var byte
speeda var byte
main:
read 0,speed
start:
low 0
low 1
button 12,1,25,3,a,1,down
button 13,1,25,3,b,1,up
button 14,1,255,255,c,1,halt
if speed < 100 then up
if speed > 254 then down
pwm 11,speed,40
pause 0
debug cls
debug ? Speed
if speeda < speed then eeprom
if speeda > speed then eeprom
speeda = speed
goto start
up:
speed = speed+1
goto start
down:
speed = speed-1
goto start
halt:
speed = 0
pause 50
low 11
high 0
debug "STOPED"
restart:
button 13,1,255,255,d,1,main
goto restart
eeprom:
write 0,speed
high 1
pause 1
goto start
the program works, but output 1 will flash telling me that the
program is allways writing to the eeprom. i don't want it to write to
the eeprom unless the speed has changed
please help me
tony
the eeprom. for me to learn i made a program that has three buttons,
a motor and a few leds i added the read and write so it will remember
what the last speed was. here is the program
a var byte
b var byte
c var byte
speed var byte
speeda var byte
main:
read 0,speed
start:
low 0
low 1
button 12,1,25,3,a,1,down
button 13,1,25,3,b,1,up
button 14,1,255,255,c,1,halt
if speed < 100 then up
if speed > 254 then down
pwm 11,speed,40
pause 0
debug cls
debug ? Speed
if speeda < speed then eeprom
if speeda > speed then eeprom
speeda = speed
goto start
up:
speed = speed+1
goto start
down:
speed = speed-1
goto start
halt:
speed = 0
pause 50
low 11
high 0
debug "STOPED"
restart:
button 13,1,255,255,d,1,main
goto restart
eeprom:
write 0,speed
high 1
pause 1
goto start
the program works, but output 1 will flash telling me that the
program is allways writing to the eeprom. i don't want it to write to
the eeprom unless the speed has changed
please help me
tony
Comments
aconti@neo.rr.com writes:
the eeprom. for me to learn i made a program that has three buttons,
a motor and a few leds i added the read and write so it will remember
what the last speed was. here is the program
a var byte
b var byte
c var byte
speed var byte
speeda var byte
main:
·read 0,speed
start:
·low 0
·low 1
·button 12,1,25,3,a,1,down
·button 13,1,25,3,b,1,up
·button 14,1,255,255,c,1,halt
·if speed < 100 then up
·if speed > 254 then down
·pwm 11,speed,40
·pause 0
·debug cls
·debug ? Speed
·if speeda < speed then eeprom
·if speeda > speed then eeprom
·speeda = speed
·goto start
up:
·speed = speed+1
·goto start
down:
·speed = speed-1
·goto start
halt:
·speed = 0
·pause 50
·low 11
·high 0
·debug "STOPED"
restart:
·button 13,1,255,255,d,1,main
goto restart
eeprom:
·write 0,speed
·high 1
·pause 1
·goto start
the program works, but output 1 will flash telling me that the
program is allways writing to the eeprom. i don't want it to write to
the eeprom unless the speed has changed
The problem is simple to fix. ·You need to move the line:
·speeda = speed
to your subroutine EEPRom since that's where you jump if there is a speed
difference. ·You can also simplify your main code by doing one comparison:
·IF speed <> speeda THEN EEPRom
-- Jon Williams
-- Dallas, TX[/font]