Hi. I'm a sophomore university student trying to do a simple binary to BCD converter. My code is below. It compiles and loads onto the target PIC, 16F877A, just fine, but nothing ever happens. All the output pins are high. Just to make sure, I used the BlinkLED demo code and that worked perfectly. I'm assuming that I made a mistake copying the four input pits into a variable. I tried poking around the help file but can't see anything else to try. Any help would be greatly appreciated.
Hi. I'm a sophomore university student trying to do a simple binary to BCD converter. My code is below. It compiles and loads onto the target PIC, 16F877A, just fine, but nothing ever happens. All the output pins are high. Just to make sure, I used the BlinkLED demo code and that worked perfectly. I'm assuming that I made a mistake copying the four input pits into a variable. I tried poking around the help file but can't see anything else to try. Any help would be greatly appreciated.
Thanks!
--------------------------------------------------------
'binary to BCD
'-------------------------------
#define in0 PORTB.7
#define in1 PORTB.6
#define in2 PORTB.5
#define in3 PORTB.4
#define f0 PORTD.7
#define f1 PORTD.6
#define f2 PORTD.5
#define f3 PORTD.4
#define g0 PORTD.3
#define led PORTD.2
'-------------------------------
'-------------------------------
'Set pin direction
dir in0 IN
dir in1 IN
dir in2 IN
dir in3 IN
dir f0 OUT
dir f1 OUT
dir f2 OUT
dir f3 OUT
dir g0 OUT
dir led OUT
'-------------------------------
#chip 16F877A, 4
dim binIn as byte
DO
wait 500 ms
Set binIn.0 in0
Set binIn.1 in1
Set binIn.2 in2
Set binIn.3 in3
if binIn <= 9 then
Set g0 off
end if
if binIn > 9 then
binIn = binIn - 9
Set g0 on
end if
Set f0 binIn.0
Set f1 binIn.1
Set f2 binIn.2
Set f3 binIn.3
wait 500 ms
'wait 1 s
'set led on
'wait 1 s
'set led off
LOOP
SET expects the new value to be a constant, typically "On" or "off". If you change your code to use the = sign, it will hopefully work.
Try changing this:
Set binIn.0 in0
Set binIn.1 in1
Set binIn.2 in2
Set binIn.3 in3
To this:
binIn.0 = in0
binIn.1 = in1
binIn.2 = in2
binIn.3 = in3
Do the same for the other block, and please let me know how it goes.
The documentation is getting ridiculously out of date for GCBASIC, but I'll hopefully have some time to update it in the next few weeks.
Thank you for the quick and helpful reply. I compiled it and will load it to a PIC to check tomorrow.
I was a little confused by the use of set vs =, but your explanation was clear and concise. Thanks again! :)
Tomorrow was further away then I thought. But, it worked like a charm! Thanks again for the quick, helpful reply.