Why won't this compile? cc = a ^ b
Hello.·
I want to monitor two pins.
When the two pins are dissimilar, then I want to increase a counter by 1.
Here is my code.· It won't compile.· The error message says "unknown command LET".· What is this?
' =========================================================================
'
'·· File......
'·· Purpose...
'·· Author....
'·· E-mail....
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Conditional Compilation Symbols
'
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
FREQ··········· 4_000_000
'
' I/O Pins
'
Pin1 PIN RA.0 INPUT
Pin2 PIN RA.2 INPUT
'
' Constants
'
'
' Variables
'
·a VAR bit
·b VAR bit
·cc VAR bit
' =========================================================================
' INTERRUPT
' =========================================================================
'ISR_Start:
· ' ISR code here
'ISR_Exit:
· 'RETURNINT ' {cycles}································
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine / Function Declarations
'
'
' Program Code
'
Start:
· a = Pin1
· b = Pin2
·
· cc = a ^ b
· IF cc = 1 THEN
··· counter = counter + 1
· ENDIF
Main:
· GOTO Main
'
' Subroutine / Function Code
'
'
'
' User Data
'
·
I want to monitor two pins.
When the two pins are dissimilar, then I want to increase a counter by 1.
Here is my code.· It won't compile.· The error message says "unknown command LET".· What is this?
' =========================================================================
'
'·· File......
'·· Purpose...
'·· Author....
'·· E-mail....
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Conditional Compilation Symbols
'
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
FREQ··········· 4_000_000
'
' I/O Pins
'
Pin1 PIN RA.0 INPUT
Pin2 PIN RA.2 INPUT
'
' Constants
'
'
' Variables
'
·a VAR bit
·b VAR bit
·cc VAR bit
' =========================================================================
' INTERRUPT
' =========================================================================
'ISR_Start:
· ' ISR code here
'ISR_Exit:
· 'RETURNINT ' {cycles}································
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine / Function Declarations
'
'
' Program Code
'
Start:
· a = Pin1
· b = Pin2
·
· cc = a ^ b
· IF cc = 1 THEN
··· counter = counter + 1
· ENDIF
Main:
· GOTO Main
'
' Subroutine / Function Code
'
'
'
' User Data
'
·
Comments
Forget about cc altogether and just use "IF a <> b THEN".
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson
"It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter
www.iElectronicDesigns.com
·
Main:
SHOW_TIME
oldpin = newpin
newpin = TicPin
'result = oldpin ^ newpin 'XOR does not work on Bit
IF oldpin <> newpin THEN 'Forget about result, just compare oldpin v. newpin
counter = counter + 1
IF counter = 2 THEN
counter = 0
UPDATE_TIME
ELSE
I was actually monitoring 1 pin to see if it changed. So I saved it as oldpin, then got a new reading as newpin and tried to do an XOR.
Anyway, now thinking again, I agree that I should have just directly compared it instead of XORing it.
But I learned that XOR does not work on Bit variables.
Thanks for all your help.
I'd still like to see your whole program or what you're attempting to convert; sometimes fragments have no context and one would approach them differently given a "big picture" view.
[noparse][[/noparse]Edit] Looking at your code, I think this is more efficient and accomplishes the same thing:
... basically it calls the UPDATE_TIME subroutine on every other change of TicPin.
And, just for grins, here's another way to do it. Let's say you want to call UPDATE_TIME when you have a 0 to 1 transition on TicPin; here's a possible solution:
This second segment of code uses just one byte versus one byte + one bit, or one byte + two bits with your original code.
Post Edited (JonnyMac) : 9/3/2008 1:29:02 AM GMT
' =========================================================================
'
' File...... Stampworks10
' Purpose... Stampworks 10 in SX/B
' Author.... C.M.
' E-mail....
' Started... Sept. 1, 2008
' Updated...
'
' =========================================================================
'
' Program Description
'
' 8 digit LED
' takes input square voltage in TicPin (RB.0) and uses this as timing signal
' displays time in four 8 segment LEDs
' uses time multiplexing and persistence of vision
'
' Conditional Compilation Symbols
'
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
FREQ 4_000_000
'
' I/O Pins
'
Segs PIN RC OUTPUT
TicPin PIN RB.0 INPUT
DigSel PIN RA OUTPUT
'
' Constants
'
Blank CON 0
Dig0 CON %1111 'all digits off
Dig1 CON %0111 'tens minutes digit
Dig2 CON %1011 'ones minutes digit
Dig3 CON %1101 'tens seconds digit
Dig4 CON %1110 'ones seconds digit
'
' Variables
'
'idx VAR Byte
counter VAR Byte
sec VAR Byte
seconds VAR Byte
minutes VAR Byte
sec_ones VAR Byte
sec_tens VAR Byte
min_ones VAR Byte
min_tens VAR Byte
digit VAR Byte
digitvalue VAR Byte
value VAR Byte
pinstatus VAR Byte
time VAR Byte
oldpin VAR Byte
newpin VAR Byte
result VAR Byte
' =========================================================================
' INTERRUPT
' =========================================================================
'ISR_Start:
' ISR code here
'ISR_Exit:
'RETURNINT ' {cycles}
' =========================================================================
PROGRAM Start
' =========================================================================
'
' Subroutine / Function Declarations
'
SHOW_TIME SUB 0
UPDATE_TIME SUB 0
'
' Program Code
'
Start:
counter = 0
sec = 0
digit = 0
DigSel = Dig0
newpin = TicPin
Main:
SHOW_TIME
oldpin = newpin
newpin = TicPin
result = oldpin ^ newpin
IF result <> 0 THEN
counter = counter + 1
IF counter = 2 THEN
counter = 0
UPDATE_TIME
ELSE
'only changed 1 time
'oldpin = newpin ' try adding more code here
ENDIF
ELSE
'oldpin = newpin ' try adding more code here
ENDIF
WATCH sec
WATCH seconds
WATCH minutes
WATCH sec_ones
WATCH sec_tens
WATCH min_ones
WATCH min_tens
WATCH value
WATCH digitvalue
WATCH oldpin
WATCH newpin
BREAK
GOTO Main
'
' Subroutine / Function Code
'
SUB SHOW_TIME
'Segs = Blank ' try activating this
digSel = Dig4
READ DecDig+sec_ones, Segs
PAUSE 1
digSel = Dig3
READ DecDig+sec_tens, Segs
PAUSE 1
digSel = Dig2
READ DecDig+min_ones, Segs
PAUSE 1
digSel = Dig1
READ DecDig+min_tens, Segs
PAUSE 1
DigSel = Dig0 'need this? try eliminating this.
'
ENDSUB
SUB UPDATE_TIME
sec = sec + 1
IF sec=60 THEN
sec = 0
sec_tens = 0
sec_ones = 0
min_ones = min_ones + 1
IF min_ones = 10 THEN
min_ones = 0
min_tens = min_tens + 1
IF min_tens = 9 THEN
min_tens = 0
ENDIF
ENDIF
ELSE
sec_tens = sec / 10
sec_ones = sec // 10
ENDIF
ENDSUB
'
'
' User Data
'
DecDig:
DATA %01111110 '0
DATA %00110000 '1
DATA %01101101 '2
DATA %01111001 '3
DATA %00110011 '4
DATA %01011011 '5
DATA %01011111 '6
DATA %01110000 '7
DATA %01111111 '8
DATA %01111011 '9
DATA %01110111 'A
DATA %00011111 'b
DATA %01001110 'C
DATA %00111101 'd
DATA %01001111 'E
DATA %01000111 'F
I've translated the program similar to what you're doing, but that program in StampWorks was to demonstrate the process of multiplexing, and was never intended to be a practical application. The SX has interrupts and that's the better way to go for this type of application. See the help file for a clock/time example using interrupts in SX/B. In the mean time you may learn a few tricks about SX/B from the attached program.
For example: you should encapsulate high-level functions like PAUSE into a subroutine so that they just get compiled once -- this will save code space. You might want to go back and read all my Nuts & Volts articles that use the SX. Since I have to explain the project code it should be fairly educational, especially those articles over the last year or so. You can get them from the Parallax web site.