I am toying around with a Lab X1 board, trying to make a program that turns on one of two LEDs, (toggled by a switch), then remembers which LED is on when I reset the power. Right now, it always turns on the opposite of the light the was on before I turned it off. Though this does satisfy my goal of using stored memory after power is turned off, I would like it to turn on the correct light, instead of the opposite on, and for the life of me, I can't figure out why. I am sure it is something simple that I am just missing.
If anyone could take a quick look at my code, it would be phenomenal.
Thanks,
Matt
EEPROM 1,[%00000001] 'set initial EEPROM Value
TRISB=%11110000 'set imputs and outputs
PORTB=%11111110
OPTION_REG.7=0
setting Var BYTE 'declare setting as a variable
READ 1,setting 'read EEPROM value to setting
PAUSE 100
LOOP:
IF setting=%00000001 THEN 'determines which LED to turn on
HIGH PORTD.0
LOW PORTD.1
ENDIF
IF setting=%00000010 THEN
LOW PORTD.0
HIGH PORTD.1
ENDIF
IF PORTB.4=1 THEN 'goto subroutine on button press
GOSUB SWITCH
ENDIF
GOTO LOOP
SWITCH:
IF setting=1 THEN 'if setting is 1, write 2 to EEPROM
WRITE 1,%00000010
ENDIF
IF setting=2 THEN 'if setting is 2, write 1 to EEPROM
WRITE 1,%00000001
ENDIF
READ 1,setting 'read EEPROM value to setting
WHILE PORTB.4=1 'wait for button release
PAUSEus 10
WEND
RETURN 'go back to main loop
END
Bookmarks