IF i=%00000001 THEN HIGH 1
ELSE
LOW 1
ENDIF
should be like
IF i=%00000001 THEN
HIGH 1
ELSE
LOW 1
ENDIF
IF i=%00000001 THEN HIGH 1
ELSE
LOW 1
ENDIF
should be like
IF i=%00000001 THEN
HIGH 1
ELSE
LOW 1
ENDIF
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
can I put a pause in for debounce?
IF i=%00000001 THEN
HIGH 1
pause 50
ELSE
LOW 1
ENDIF
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.
For one thing, you've got more than one CASE ELSE inside the SELECT CASE block.
Check your manual...
The manual says:
W2 = W0
W0 = W1
W1 = W2
is the same as:
W2 = W0 : W0 = W1 : W1 = W2
So why wont this compile:
IF mydata=%01010110 THEN: HIGH 7:else: low 7: ENDIF:PAUSE 50:GOTO loop
ERROR Line 48: Bad expression. (Test(test mod2).pbp)
I've even tried it as this :
IF mydata=%01010110 THEN HIGH 7:else: low 7: ENDIF:PAUSE 50:GOTO loop
Still no go
I just started to try to use multi-line statements as suggested, sure would look better
Last edited by tazntex; - 24th July 2008 at 19:23. Reason: Typing error
Yes, that is completely valid..
Just like I said in my last post, I'm not 100% sure that an else in the IF/THEN is valid, and apparently it's not. So you still have to split up the If/Then/Else/Endif statements.So why wont this compile:
IF mydata=%01010110 THEN: HIGH 7:else: low 7: ENDIF:PAUSE 50:GOTO loop
ERROR Line 48: Bad expression. (Test(test mod2).pbp)
I've even tried it as this :
IF mydata=%01010110 THEN HIGH 7:else: low 7: ENDIF:PAUSE 50:GOTO loop
This is valid:
You're examples above are not valid.Code:If mydata = x then high 7 else low 7 endif pause 50:goto loop
These don't work either:
These work:Code:IF mydata = x then pause 50 : GOSUB something If mydata = x then for x = 1 to 10 : pause 1 : next x
Just a few examples of what works and what doesn't when using colons...and I know colons!Code:if mydata = x then pause 50 : gosub something endif if mydata = x then for x = 1 to 10 : pause 1 : next x endif
Well that makes me feel better, I always try to learn something each day. Thanks again for the explanation.
I missed this when it was first posted (on the basis I don't read everything)... this is news to me... do you have examples?
I've written some pretty complex programs and haven't come across this problem - unless of course you're dropping COLONs all over the place and your GOSUB follows on... not something I've ever done (on one line).
Example
If A=0 then Goto Start else A=A+1:Gosub DoThis
This is equivalent to...
If A=0 then
Goto Start
else
A=A+1
Gosub DoThis
Endif
And NOT as may be expected...
If A=0 then
Goto Start
else
A=A+1
endif
Gosub DoThis
There is a distinct difference (and some tricky workings) if you bung all your code on one line separated with colons. It's not really the way it should be written. There are rules for IF/THEN/ELSE, WHILE/WEND, FOR/NEXT etc.
Joe, here is the code I am sending from pic to pic:
INCLUDE "MODEDEFS.BAS"
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
' Watchdog Timer
@ DEVICE pic16F628a, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628a, MCLR_ON
' Master Clear Options (Internal)
@ DEVICE pic16F628a, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F628a, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628a, CPD_OFF
' Data Memory Code Protect
' Set to CPD_OFF for Development Copy
' Set to CPD_ON for Release Copy
@ DEVICE pic16F628a, PROTECT_OFF
define osc 4
CMCON=%00000111
trisb = %11111111
trisa = %00010111
chk_sum var byte
dgood var porta.2
serpin var porta.3
nokey con %11111111
synch con 254
address con %00000001
keyin var portb
keydata var byte
E VAR PORTB.0
D VAR PORTB.1
G VAR PORTB.2
A VAR PORTB.3
B VAR PORTB.4
C VAR PORTB.5
F VAR PORTB.6
na VAR PORTB.7
PreAmble CON $A5 ' 10100101
findkey:
if A = 0 then sw0
if B = 0 then sw1
if C = 0 then sw2
if D = 0 then sw3
if E = 0 then sw4
if F = 0 then sw5
if G = 0 then sw6
goto findkey
sw0:
keydata = %01010110
goto dout
sw1:
keydata = %01011001
goto dout
sw2:
keydata = %01011010
goto dout
sw3:
keydata = %01100101
goto dout
sw4:
keydata = %01100110
goto dout
sw5:
keydata = %01101001
goto dout
sw6:
keydata = %01101010
goto dout
dout:
low dgood
pause 100
chk_sum = (address + address)
chk_sum = chk_sum + (keydata + keydata)
goto transmit
transmit:
serout serpin,N9600[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
if keyin = nokey then x2
goto findkey
x2:
high dgood
keydata = %00000000
serout serpin,N9600,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
goto findkey
end
Anyhow, it works, tx side seems to be fine, my big problem is on the rx side each output that is a if/then statement will come on but when I release the button it stays on. The only way to make it turn off is to press another momentary button. The toggle function works fine, although if I hold onto the button to long it will toggle on/off. if/then example I have tried after Skimask post:
if mydata1=%01011001 then pause 50
if mydata1=%01011001 then
high 1
else
low 1
endif
I am using a direct cable link, and will try again later with the Linx modules.
"logic dictates, cmcon goes before anything portA, then tris registers dictate input or output, then port dictates hi or low status."
And I have modified the suggestion to this tx program yet, but I will later this evening.
Many thanks for the help.
Last edited by tazntex; - 7th August 2008 at 04:41.
Debouncing isn't going to work very well without a 'switch' to actually debounce. If you're trying to debounce a received signal, I don't think that it's the right way to go about it.Anyhow, it works, tx side seems to be fine, my big problem is on the rx side each output that is a if/then statement will come on but when I release the button it stays on. The only way to make it turn off is to press another momentary button. The toggle function works fine, although if I hold onto the button to long it will toggle on/off. if/then example I have tried after Skimask post:
This shouldn't be all that hard...but if you continue having problems, you might want to thinking about sending MAKE and BREAK codes with the TX similar to a PC keyboard.
I.E. code1 = button 1 pressed
code2 = button 1 released
code3 = button 2 pressed....
and so on and so on...
is the space in the word "address" a cut paste error or a typo in the transmit code?
Code:transmit: serout serpin,N9600[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,<font color=red>addr ess</font color>,address,keydata,keydata,chk_sum] if keyin = nokey then x2 goto findkey x2: high dgood keydata = %00000000 serout serpin,N9600,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,<font color=red>addr ess</font color>,address,keydata,keydata,chk_sum] goto findkey end
Last edited by Archangel; - 7th August 2008 at 06:46.
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.
I don't have any specific examples off the top of my head, although I've never actually used an If/Then/Else on one continuous line. Thanks for the idea
And yes, you are right about the colons. I try to stuff as much into a single line as I can, just so I don't have to scroll up and down so much. Therefore I tend to run into various issues with the aforementioned statements. I just know what works, and when something doesn't, I have a rough idea of where to lookMy current 'project' is about 4000 lines of my 'colonized' code. I split it up one day and came up with something around 19,000 lines. Sure, it's not easy to read, but I wrote it, I know what's where, and for the most part, others don't have to read it (and probably couldn't anyways
)
And you're right, it's probably not so much the way that code should be written, but there's nothing that says it CAN'T be written in such a fashion...Unless of course it doesn't work right.
Bookmarks