OK. Completed the code and things are working great now. Thanks to Darrel (DT), he explained a few things that I was doing wrong and clarified my understanding of what I thought was happening and what was really happening. After a few days of trial and error, I got it working perfectly. To clear up where the problem were, the following changes were made.
1) Didn't need to make two arrays (L_state and R_state). One array served just fine and a (+ 1) went on the second byte values so that all the left inputs went into the even memory slots and the right inputs went into the odd memory slots.
2) There was no need for four lines of code to invert the input value. The ! command took care of that (leftvalue.0[x] = !leftbutton)
3) Wasn't writing my limit to eeprom, so the value erased itself when power was removed.
So the major changes are:
Code:EE_Limit DATA @254,WORD 0 Reset: OPTION_REG.7 = 0 ' Pullups enabled WPU = %000000 ' Weak Pull Up disabled because of my external pullups TRISIO = %001111 ' sets pin as input (1) or output (0) ANSEL = 0 ' Disable analog inputs CMCON0 = 7 ' Disable comparators ' -----[ Variables ]------------------------------------------------------- record var gpio.0 ' program button input leftbutton var gpio.1 ' left button input rightbutton var gpio.2 ' right button input rightled var gpio.4 ' right led output leftled var gpio.5 ' left led output leftvalue var byte ' stores the opposite value of the button rightvalue var byte ' stores the opposite value of the button counter var word ' counts how many bits are being used limit var word ' stores the last count value for the loop x var byte ' variable for bit count y var byte ' loop variable for output flash ' -----[ Action ]---------------------------------------------------------- action: READ EE_Limit , WORD limit FOR counter = 0 TO limit Step 2' start reading bit locations read counter, leftvalue ' read the array of bits and place in left value read counter + 1, rightvalue' read the array of bits and place in right value for x = 0 to 7 leftled = leftvalue.0[x] ' left led will mimic bit value rightled = rightvalue.0[x] ' right led will mimic bit value pause 100 ' pause 1/10th of a second next x if record = 0 then flash ' If program button is pressed, then ' goto program mode NEXT counter goto action ' -----[ Program ]--------------------------------------------------------- flash: for y = 1 to 3 ' flash outputs three times high leftled high rightled pause 500 low leftled low rightled pause 500 next y counter = 0 ' reset counter value to 0 program: if record = 1 then action ' if the program button was momentarily pressed, ' return to action loop while record = 0 ' while record button is pressed, loop here if counter = 60 then finish ' if 24 seconds is reached, exit program mode for x = 0 to 7 leftvalue.0[x] = !leftbutton ' store inverted value of leftbutton leftled = leftvalue.0[x] ' display on led rightvalue.0[x] = !rightbutton ' store inverted value of rightbutton rightled = rightvalue.0[x] ' display on led pause 100 ' pause 1/10th of a second next x write counter, leftvalue write counter + 1, rightvalue counter = counter + 2 ' advance counter by 2 wend limit = counter - 2 ' write counter value to limit WRITE EE_Limit , WORD limit goto action ' go to action and run pattern ' -----[ Exit Program ]---------------------------------------------------- finish: while record = 0 ' loop here while program button is held low leftled low rightled pause 500 ' just wait 1/2 a second wend ' exit loop when button is released limit = counter - 2 ' write counter value to limit WRITE EE_Limit , WORD limit goto action ' return to action




Bookmarks