Is there another "half" to this code, that is sending data? I ask because I want to try it out and am too lazy to write code to test it![]()
Is there another "half" to this code, that is sending data? I ask because I want to try it out and am too lazy to write code to test it![]()
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Here is the entire code with the WHILE WEND example I was trying to use for a debounce.
Please ignore what should be upper case because when I copy and paste it changes back to lower case.
INCLUDE "MODEDEFS.BAS"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, MCLR_ON
@ DEVICE pic16F628a, BOD_ON
@ DEVICE pic16F628a, LVP_OFF
@ DEVICE pic16F628a, CPD_OFF
@ DEVICE pic16F628a, PROTECT_OFF
DEFINE OSC 4
CMCON=%00000111
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
mydata1 VAR byte
mydata2 var byte
address1 var byte
address2 var byte
checksum var byte
chk_sum var byte
serpin VAR porta.1
PAUSE 50
loop:
gosub loop1
CheckSum = (address1 + address2)
CheckSum = CheckSum + (mydata1 + mydata2)
IF checksum != chk_sum THEN loop
IF (mydata1) != (mydata2) THEN loop
IF (address1) != (address2) THEN loop
if mydata1=%01010110 then toggle 0
pause 50
if mydata1=%01011001 then
while mydata1=%01011001 ' trying this example for debounce
pause 50
wend
high 1
else
low 1
endif
if mydata1=%01011010 then
while mydata1=%01011010
pause 50
wend
high 2
else
low 2
endif
if mydata1=%01100101 then
while mydata1=%01100101
pause 50
wend
high 3
else
low 3
endif
if mydata1=%01100101 then
while mydata1=%01100101
pause 50
wend
high 4
else
low 4
endif
if mydata1=%01101001 then toggle 5
if mydata1=%01101010 then toggle 6
goto loop
loop1:
SERIN serpin,N9600,[254],address1,address2,mydata1,mydata2,chk_sum
Return
I think you're confused on the correct method of debouncing.
The object is to check for a switch hit, wait for the bouncing to stop, then check again and see if the same switch is still hit.
The way you are doing it, you'll catch the bouncing and kick out of your check before you get a chance to check it after the bouncing is over...
Try this:
Code:INCLUDE "MODEDEFS.BAS" @ DEVICE PIC16F628a,XT_OSC @ DEVICE pic16F628a, WDT_OFF @ DEVICE pic16F628a, PWRT_ON @ DEVICE pic16F628a, MCLR_ON @ DEVICE pic16F628a, BOD_ON @ DEVICE pic16F628a, LVP_OFF @ DEVICE pic16F628a, CPD_OFF @ DEVICE pic16F628a, PROTECT_OFF DEFINE OSC 4 CMCON=%00000111 : PORTA = 0 : PORTB = 0 : trisa = %00000010 trisb = %10000000 : mydata1 VAR byte : mydata2 var byte : address1 var byte address2 var byte : checksum var byte : chk_sum var byte : serpin VAR porta.1 PAUSE 50 loop: gosub loop1 : CheckSum = (address1 + address2) + (mydata1 + mydata2) IF checksum != chk_sum THEN loop IF (mydata1) != (mydata2) THEN loop IF (address1) != (address2) THEN loop if mydata1=%01010110 then toggle 0 pause 50 lp1: if mydata1=%01011001 then pause 50 if mydata1=%01011001 high 1 else low 1 endif if mydata1=%01011010 then pause 50 if mydata1=%01011010 high 2 else low 2 endif if mydata1=%01100101 then pause 50 if mydata1=%01100101 high 3 else low 3 endif if mydata1=%01100101 then pause 50 if mydata1=%01100101 high 4 else low 4 endif if mydata1=%01101001 then toggle 5 if mydata1=%01101010 then toggle 6 goto loop loop1: SERIN serpin,N9600,[254],address1,address2,mydata1,mydata2,chk_sum Return
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Please let us see the code you are sending to this program. Are yoy sending from a PC or a PIC?
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks