Tear
- 30th June 2005, 20:18
Hello Everyone,
PLEASE GO TO THE 3RD POST DOWN FOR A CLEARER POST OF WHAT I AM HAVING A PROBLEM WITH!
I am working on a delay project which uses 2 buttons one for increasing the delay and one for decreasing the delay. I am using the PIC16F84 and have a button connected to PORTB pin 5,6. LED on PORTB 3,4,7 and PORTA pin 3.
PORTB pin 4 is for showing the length of the delay, pin 3 for showing when both buttons are pushed that it saves the delay to EEPROM, 7 for showing when IncreaseButton is pushed, and PORTA pin 3 for when DecreaseButton is pushed.
The problem I am having is when I program the PIC16F84 it is starting at a delay of what I believe to be 30s when it should be 15s. This is according to this line:
data word (0),(1500) 'Save 1.5s delay to EEPROM at programming
Also, it doesnt seem that the buttons are changing the delay. What I dont understand is that everything worked until I added this above line.
Here is the code that I am working on:
''Increase/Decrease Delay with Buttons
Delay var word 'Declare Variables
x var word
IncreaseButton var PORTB.5
DecreaseButton var PORTB.6
data word (0),(1500) 'Save 1.5s delay to EEPROM at programming
read 0, Delay.BYTE0 'Save value in EEPROM to delay
Read 1, Delay.Byte1
Loop:
high PORTB.4 'Turn LED on
low PORTB.3 'Turn on LED from "saving" delay
for x = 1 to Delay 'For loop to run delay/ Allows button to be
'read without interrupt
pause 1 'Pause 1 ms
if IncreaseButton = 1 then 'When IncreaseButton is pressed
high PORTB.7 'Turn LED on to show button is pushed
pause 50 'Pause for 50 ms
if DecreaseButton = 1 then'If both buttons pushed then write delay
write 0, Delay.BYTE0 'to EEPROM
write 1, Delay.BYTE1
high PORTB.3
SetDelayCycle1:
'Loop to wait until buttons are released before going on
if DecreaseButton = 0 or IncreaseButton = 0 then
goto Loop 'Restart the delay
else
goto SetDelayCycle1
endif
endif
Delay = Delay + 500 'increase delay
if Delay => 30000 then 'If delay is equal to or greater than 30 sec
Delay = 30000 'then keep delay at 30 sec max delay
pause 100 'If at max delay length flash LED
low PORTB.7
pause 100
high PORTB.7
endif
IncreaseButtonCycle:
'Loop to wait until button is released before going on
if IncreaseButton = 0 then
LOW PORTB.4 'Turn LED off
pause 500 'Pause to show LED off before restarting delay
low PORTB.7
goto loop 'Restart the delay
else
goto IncreaseButtonCycle
endif
endif
if DecreaseButton = 1 then 'When DecreaseButton is pressed
high PORTA.3
pause 50 'Pause for 50 ms
if IncreaseButton = 1 then'If both buttons pushed then write delay
write 0, Delay.BYTE0 'to EEPROM
write 1, Delay.Byte1
high PORTB.3
SetDelayCycle2:
if IncreaseButton = 0 or DecreaseButton = 1 then
goto loop 'Restart the delay
else
goto SetDelayCycle2
endif
endif
Delay = Delay - 500 'decrease delay
if Delay <= 500 then 'If delay is equal or less than 0.5 sec then
Delay = 500 'keep delay at 0.5 sec min delay
pause 100
low PORTA.3
pause 100
high PORTA.3
endif
DecreaseButtonCycle:
if DecreaseButton = 0 then
low PORTB.4 'Turn LED off
pause 500 'Pause to show LED off before restarting delay
low PORTA.3
goto loop 'Restart the delay
else
goto DecreaseButtonCycle
endif
endif
next x
low PORTB.4 'Turn LED off after full delay cycle
pause 500 'Pause to show LED off before restarting delay
goto loop 'Restart the delay (Infinite Loop)
end 'End of program
This probably is not a very efficent piece of code, but it was doing the job until I tried doing the DATA command. I tried using different values other than the 1500 such as.. 100, 500, 3000 and all of the values were causing the same thing to happen with a delay of what I believe to be 30s the max delay that I have for the piece. I also tried the EEPROM command with the same conclusion. Any help would be appreciated.
Thanks,
Michael
PLEASE GO TO THE 3RD POST DOWN FOR A CLEARER POST OF WHAT I AM HAVING A PROBLEM WITH!
I am working on a delay project which uses 2 buttons one for increasing the delay and one for decreasing the delay. I am using the PIC16F84 and have a button connected to PORTB pin 5,6. LED on PORTB 3,4,7 and PORTA pin 3.
PORTB pin 4 is for showing the length of the delay, pin 3 for showing when both buttons are pushed that it saves the delay to EEPROM, 7 for showing when IncreaseButton is pushed, and PORTA pin 3 for when DecreaseButton is pushed.
The problem I am having is when I program the PIC16F84 it is starting at a delay of what I believe to be 30s when it should be 15s. This is according to this line:
data word (0),(1500) 'Save 1.5s delay to EEPROM at programming
Also, it doesnt seem that the buttons are changing the delay. What I dont understand is that everything worked until I added this above line.
Here is the code that I am working on:
''Increase/Decrease Delay with Buttons
Delay var word 'Declare Variables
x var word
IncreaseButton var PORTB.5
DecreaseButton var PORTB.6
data word (0),(1500) 'Save 1.5s delay to EEPROM at programming
read 0, Delay.BYTE0 'Save value in EEPROM to delay
Read 1, Delay.Byte1
Loop:
high PORTB.4 'Turn LED on
low PORTB.3 'Turn on LED from "saving" delay
for x = 1 to Delay 'For loop to run delay/ Allows button to be
'read without interrupt
pause 1 'Pause 1 ms
if IncreaseButton = 1 then 'When IncreaseButton is pressed
high PORTB.7 'Turn LED on to show button is pushed
pause 50 'Pause for 50 ms
if DecreaseButton = 1 then'If both buttons pushed then write delay
write 0, Delay.BYTE0 'to EEPROM
write 1, Delay.BYTE1
high PORTB.3
SetDelayCycle1:
'Loop to wait until buttons are released before going on
if DecreaseButton = 0 or IncreaseButton = 0 then
goto Loop 'Restart the delay
else
goto SetDelayCycle1
endif
endif
Delay = Delay + 500 'increase delay
if Delay => 30000 then 'If delay is equal to or greater than 30 sec
Delay = 30000 'then keep delay at 30 sec max delay
pause 100 'If at max delay length flash LED
low PORTB.7
pause 100
high PORTB.7
endif
IncreaseButtonCycle:
'Loop to wait until button is released before going on
if IncreaseButton = 0 then
LOW PORTB.4 'Turn LED off
pause 500 'Pause to show LED off before restarting delay
low PORTB.7
goto loop 'Restart the delay
else
goto IncreaseButtonCycle
endif
endif
if DecreaseButton = 1 then 'When DecreaseButton is pressed
high PORTA.3
pause 50 'Pause for 50 ms
if IncreaseButton = 1 then'If both buttons pushed then write delay
write 0, Delay.BYTE0 'to EEPROM
write 1, Delay.Byte1
high PORTB.3
SetDelayCycle2:
if IncreaseButton = 0 or DecreaseButton = 1 then
goto loop 'Restart the delay
else
goto SetDelayCycle2
endif
endif
Delay = Delay - 500 'decrease delay
if Delay <= 500 then 'If delay is equal or less than 0.5 sec then
Delay = 500 'keep delay at 0.5 sec min delay
pause 100
low PORTA.3
pause 100
high PORTA.3
endif
DecreaseButtonCycle:
if DecreaseButton = 0 then
low PORTB.4 'Turn LED off
pause 500 'Pause to show LED off before restarting delay
low PORTA.3
goto loop 'Restart the delay
else
goto DecreaseButtonCycle
endif
endif
next x
low PORTB.4 'Turn LED off after full delay cycle
pause 500 'Pause to show LED off before restarting delay
goto loop 'Restart the delay (Infinite Loop)
end 'End of program
This probably is not a very efficent piece of code, but it was doing the job until I tried doing the DATA command. I tried using different values other than the 1500 such as.. 100, 500, 3000 and all of the values were causing the same thing to happen with a delay of what I believe to be 30s the max delay that I have for the piece. I also tried the EEPROM command with the same conclusion. Any help would be appreciated.
Thanks,
Michael