I have tried the:
IF i=%00000001 THEN
WHILE i=%00000001
PAUSE 50
WEND
HIGH 1
ELSE
LOW 1
ENDIF
using this on four outputs my program does nothing with these four. If I take out the while statement and use the :
If i=%00000001 THEN
HIGH 1
ELSE
LOW 1
ENDIF
then my outputs for these four comes on and stays on, forever.
I been experimenting with SELECT CASE and what I am trying to accomplish is if I am pressing the button on the transmitter, the output selected comes on and stays on until I release the button instead of cycling on/off. So here is my latest rx version which does nothing, what am I doing wrong?
INCLUDE "bs2defs.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
mydata1 VAR byte
mydata2 var byte
address1 var byte
address2 var byte
checksum var byte
chk_sum var byte
serpin VAR porta.1
PORTA = 0
PORTB = 0
trisa = %00000010
trisb = %10000000
CMCON=%00000111
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
select case mydata1
case 0
mydata1=%01010110
toggle 0
pause 50
case 1
mydata1=%01011001
high 1
pause 50
case else
low 1
case 2
mydata1=%01011010
high 2
pause 50
case else
low 2
case 3
mydata1=%01100101
high 3
pause 50
case else
low 3
case 4
mydata1=%01100110
high 4
pause 50
case else
low 4
case 5
mydata1=%01101001
toggle 5
pause 50
case 6
mydata1=%01101010
toggle 6
pause 50
end select
goto loop
loop1:
SERIN serpin,N9600,[254],address1,address2,mydata1,mydata2,chk_sum
Return
One more thing when I copy and paste my code to this forum everything becomes lower case. I have been reminded as a courtesy of DEFINE OSC 4 just wanted to let ya'll know
why everything appears in the lower case. Many Thanks
FineLine Viewer was created to sort out the if - endif statements by drawing brackets between the if and endif's.
See IDE FineLine Viewer.
Scroll down to and download v1.3
Be sure to have "Hide extensions for known file types"
unchecked in Any folder>Tools>Folder options>View to see
the ".TXT" to remove.
Norm
Order of operations, I dunno maybe the compiler sorts this out, but . . . logic dictates, cmcon goes before anything portA, then tris registers dictate input or output, then port dictates hi or low status. Unless you are writing this for a basic stamp, why INCLUDE "bs2defs.bas" I would and always do use INCLUDE "MODEDEFS.BAS", as I haven't the foggiest as to what makes a stamp tick. Now having said this , someone will explain to me why I am all wrong![]()
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.
Ok, I am seeing some light, hopefully it isn't attached to a train. Thanks for pointing out the CASE ELSE, never thought about that. I started with sample code from RENTRON's site and that why I had INCLUDE "bs2defs.bas" up there, and the CMCON=%00000111 never saw exactly where that should be placed in the manual. One thing is for certain I have learned a lot from this forum. And thanks for the FINE LINE link.
I still have a problem with:
'This will do nothing
IF mydata1=%01011001 THEN
WHILE mydata1=%01011001
pause 50 ' pause for debounce
WEND
HIGH 1
ELSE
LOW !
ENDIF
or
'This works, to turn on but will not turn off
IF mydata1=%01011001 THEN
HIGH 1
ELSE
LOW !
ENDIF
Thanks again
Last edited by tazntex; - 6th August 2008 at 21:37.
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
For one thing, you've got more than one CASE ELSE inside the SELECT CASE block.
Check your manual...
Bookmarks