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 can turn on any of the ports using realterm and a max232 using the code below.
Much stuff just commented out, serouts added so as to see variable contents, a blinky added for life signs, easy to undo. Thanks for sharing your problem, I got to learn too.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 @MyConfig = _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF @MyConfig = MyConfig & _BODEN_OFF @ __config MyConfig DEFINE OSC 20 CMCON = 7 trisa = %00000010 trisb = %00000000 PORTA = 0 PORTB = 0 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: high portA.2 pause 500 low portA.2 gosub loop1 serout portA.0,T9600,[254,2,mydata1," ",mydata2," "] serout portA.0,T9600,[$FE,$C0,address1," ",address2," " ] '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= 86 then toggle portB.0 if mydata1= 89 then 'while mydata1 = 89 ' trying this example for debounce 'pause 50 'wend high PortB.1 else low PortB.1 endif if mydata1 = 90 then 'while mydata1 = 90 'pause 50 'wend high PortB.2 else low PortB.2 endif if mydata1= 101 then 'while mydata1 = 101 'pause 50 'wend high PortB.3 else low PortB.3 endif if mydata1 = 102 then 'while mydata1 = 102 'pause 50 'wend high PortB.4 else low PortB.4 endif if mydata1=105 then toggle PortB.5 if mydata1=106 then toggle PortB.6 goto loop loop1: SERIN2 PortA.1,84,[DEC address1,DEC ADDRESS2,DEC MYDATA1,DEC MYDATA2] Return end
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.
Tazntex,
You are forgetting something I think.
When you press a button, your IF statement works only WHILE you are pressing the button.
When you do NOT press a button, your ELSE statement works continuously.
This is why "you think" that you see no change; because it happens so fast when you hit the button down and release it.
I think you should set an IF statement with the first button press, and keep it that way until you press it second time. Like a flip flop.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
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