I have written a simple program for a 12F508 in picbasic Pro to
produce 190 Hz square wave on port pin GPIO.0, and I want the inverse
of this to appear on GPIO.2.
I get what I expect from GPIO.0, but nothing from GPIO.2.
From the datasheet, I can see that the GPIO.2 pin is also for TOCKI,
but it says it is a normal I/O pin also.
What am I doing wrong?
I see nothing in the datasheet that would indicate you can not do this.
What is missing here is information on how PICBASIC handles I/O and so
on. Do you have to define the ins and outs? In other words, is the pin
programmed to be an output. All pins are inputs by default. Is the
software using a read/modify/write routine for the port and the port
isn't being read as you expect? R/M/W commands are tricky on PICs that
read the pins even if they are outputs. Make sure you have the pin
hanging loose or pulled up by a 10K resistor or so AND NOTHING ELSE and
see if the problem persists.
If all else fails, a schematic and program listing could be useful.
Thanks for the reply.
OK. To come clean, I am flashing LEDs on and off via a transistor in
emmitter follower configuration, driven from GPIO.0
I have a tell tale output (following GPIO.0) on GPIO.1.
I want the complement on GPIO.02.
Both these outputs are connected via 100 Ohm resistors to a couple of
BNC outputs. The output from GPIO.1 works perfectly.
Here is the program. Is it something stupid I am doing. I am not a
programmer, but have managed to make a couple of projects work with
PIC16C715 quite well. ***************************
INTRC_OSC ' This PIC has a 4MHz built in oscillator to
MCLR_OFF ' MCLR not required
' Inputs and outputs
Output GPIO.0 ' Output Pin 7 to drive the LEDs via a BC184L
Output GPIO.1 ' Output Pin 6 to provide a +ve logic sync pulse
Output GPIO.2 ' Output Pin 5 to provide a -ve logic sync pulse
Input GPIO.3 ' Not used so make an input for good measure
Input GPIO.4 ' Not used so make an input for good measure
Input GPIO.5 ' Not used so make an input for good measure
' Now for the main program
' First set the oututs Low to start
' Now go into a never ending loop to chop the outputs on and off at
loop1:High GPIO.0 ' Turn output on to drive LEDs on
High GPIO.1 ' Turn output on to provide +ve TTL logic
Low GPIO.2 ' Turn output off to provide -ve TTL logic
Pauseus 2630 ' Pause this many microseconds with LEDs on
Low GPIO.0 ' Turn output off to drive turn LEDs off
Low GPIO.1 ' Turn output off to provide +ve TTL logic
High GPIO.2 ' Turn output on to provide -ve TTL logic
Pauseus 2630 ' Pause this many milliseconds with LEDs
GOTO loop1 ' Do the above for ever.
' And if we crash badly and fall all the way out to here end it
Low GPIO.0 ' Just in case we get here, better shut down the
I was considering adding the line near the top.
OPTION_REG.5 = 0 ' Disable TOCS and T0CKI
To make sure that the the TOCKI was not overiding TRIS (whatever that
That looks like it might do the trick.
It seems that the OPTION register is set to 11111111 on power up and
that would override the TRIS setting.
I haven't played with the 508 in a while and I have never used PICBASIC,
so I am just making educated guesses, but it is rare that a PIC comes up
with anything that would over ride the TRIS setting turned on by
default. It wouldn't hurt to give it a try.
Tried it today and it worked. I had a lot of trouble figuring out the
exact line to use to set that bit. It seems a different way of doing
it to the PIC16C715 I used before, where you can just state the name
of the register = a number, where the appropriate number allows you to
set or unset the various bits of the register to configure the chip.
Anyway, after some detective work, I got a configuration setting that
would compile without errors, and away we go.
Thanks for all the help.
With regards to PicBasic Pro (PBP). Like I say, I am not a software
engineer, but at the time, a PIC offered a convenient way to achieve
my requirements. Added to that, we all have done a little basic
programming over the years (at school for me), so we found that PBP
was easy enough and powerful enough to go with. If I had to do it in
the PIC assembly language (or C for that matter), I'm afraid it would
be somebody else who would be working (and struggling) with it.