New to PICBASIC Pro and have simple question
I am using Picbasic Pro to program a 16F684. What I am trying to do it get pins on portA other than porta.3 to be a input and see a high or low signal. I don't know why this isn't working and I am SURE something will point out the obvious reason it's not. Anyway here is the code below. When I put "high" to porta.0 it doesn't flash the led. I know everything working right because if I just set portc to outputs and set it to flash the same led its fine.
Any help would be great. Thanks!
TRISA=%111111
TRISC=%000000
PORTC=%000000
MAIN:
IF PORTA.0 = 1 THEN
PORTC.0 = 1
PAUSE 60
PORTC.0 = 0
PAUSE 60
ENDIF
GOTO MAIN
Pull up may still be needed
I think you will probably still need a pull-up resistor in your design to get the PIC to see a high-to-low and low-to-high transition to get any of these commands to work.
If you wanted, for example portb.0 to be your input and portb.1 to be an output, then you'd:
'program the port so the correct pins are in or outs
'this makes bit 1 an input, all other pins are outputs
trisb = 1
START:
portb.1 = portb.0
GOTO START
If you wanted to do this across ports:
trisb = 255 'all of port b is inputs
trisd = 0 'all of port d is outputs
START:
portd = portb
GOTO START
or if you just want to do a single bit on each port:
START:
portd.0 = portb.1 'this makes bit 0 on port D reflect what is going on on portb bit 1
You could also flip-flop the bits of a port using a variable:
portBflipval VAR BYTE
START:
portBflipval.bit0 = portb.7
portBflipval.bit1 = portb.6
portBflipval.bit2 = portb.5
portBflipval.bit3 = portb.4
portBflipval.bit4 = portb.3
portBflipval.bit5 = portb.2
portBflipval.bit6 = portb.1
portBflipval.bit7 = portb.0
portd = portBflipval 'port d now has the value that is on port b, but flipped!!!
Also, if you wanted to track the status of an input, so your code doesn't, for example send out multiple codes:
buttonState VAR BIT
START:
if portb.0 <> buttonState then
buttonState = portb.0
if buttonState = 0 then HSEROUT ["Button 0 released and it's a zero!"]
if buttonState = 1 then HSEROUT ["Button 0 pressed and it's a one!"]
endif
goto START
I've found that this method is excellent for be-bouncing a button press... I don't know why but it works great, even with a hundred lines of code...
If your aim is to read an analog voltage and then send that out on one of the 8 bit ports, that should be easy. Although I havent worked with this yet myself.