PDA

View Full Version : Simultaneous outputs



fowardbias
- 23rd October 2004, 23:13
Just starting out with the PIC's and don't understand why I can't get three LED's to all flash on and off at a 1/2 second rate. Using 12F675 with PBP with the following code:

Start: HIGH 0
HIGH 1
HIGH 2
PAUSE 500
LOW 0
LOW 1
LOW 2
PAUSE 500
GOTO Start:

With this code GPIO.0 goes on and off at a ~1.7mS rate. GPIO.1 and GPIO.2 are always off. Shouldn't all three go on and off?

I can rewrite the code and drop off the first pause and put the GOTO in it's place and all three will come on and stay on as expected.
All three outputs can be programmed individually to flash in any order or rate.
Looking for ideas please?

Bruce
- 24th October 2004, 03:31
The HIGH & LOW commands take care of the TRIS registers for you to make your I/O-pins outputs, but they don't take care of certain built-in hardware peripheral features.

In this case, that would be the onboard comparator & A/D modules.

Try this;




CMCON = 7 ' Comparators off
ANSEL = 0 ' A/D off, set I/O to all digital

Start:
HIGH 0
HIGH 1
HIGH 2
PAUSE 500
LOW 0
LOW 1
LOW 2
PAUSE 500
GOTO Start


Take a peek in the datasheet under the Comparator Module & Analog-to-Digital sections to see why this makes it work.

fowardbias
- 24th October 2004, 05:26
Thanks Bruce, that cleared up everything. I didn't find it in the config. setup as an option in the MicroCode Studio. Will code it in as necessary from now on. FB

mister_e
- 25th October 2004, 04:03
You can also do your task in less line and it will take less of your code space.




CMCON = 7
ANSEL = 0

Start:

GPIO=7
PAUSE 500
GPIO=0
PAUSE 500
GOTO Start

Bruce
- 25th October 2004, 06:37
Close, but you forgot to configure your pins as outputs.
All I/O-pins are inputs on power-up by default.

This would work.



CMCON = 7
ANSEL = 0
TRISIO = 0 ' GPIO = outputs

Start:
GPIO=7
PAUSE 500
GPIO=0
PAUSE 500
GOTO Start

And if you're really stingy on code space, you could do it something like this;



CMCON = 7
ANSEL = 0
TRISIO = 0 ' GPIO = outputs
GPIO = 7

Start:
GPIO = GPIO ^ 7 ' Toggle GPIO.0, 1 and 2
PAUSE 500
GOTO Start

mister_e
- 25th October 2004, 07:28
well done again Bruce. I was aware of this TRSIO line since i've never use this before considering that PBP was suppose to do. But after experimenting i realise that was important to include in this case. I'll use this TRIS in future as a safe programming way.

that's for sure there's many way to blink a led. XOR function are one example :). code also working without GPIO=7 but it's also a safe way.

fowardbias
- 25th October 2004, 18:57
Wow , many ways of doing things better with the first lines of code. Great eye opener. Thans to the group. FB