PDA

View Full Version : First test program, but strange results



bartman
- 13th November 2004, 21:21
I've programmed the 12F629 chip with this simple program to test the I/O for my larger program:

start:

high 0 : pause 2000
high 1 : pause 2000
high 2 : pause 2000
high 4 : pause 2000
high 5 : pause 2000
low 0 : pause 2000
low 1 : pause 2000
low 2 : pause 2000
low 4 : pause 2000
low 5 : pause 2000

goto start

end

Should be straight forward, but this is what happens.

Port 0 goes high and lights a LED.

Port 1 then goes high and lights a LED <em>BUT</em> port 0 then goes low at the exact same time and stays off.

Port 2 goes high and lights an LED, but at the same time port 1 goes low and stays off.

The rest of the results are as you would expect so it is port 0 and port 1 that are acting strange. They obviously are going high and low, but somehow are linked to each other??

Some advice would be appreciate. I'm happy that I have got something to light up, but with such a simple program I was not expecting these odd results.

Thanks.

Bart

bartman
- 13th November 2004, 22:43
Okay, I think I figured this out myself.

Port 0 and 1 also are comparitor ports. I added <b>poke $19,00000111</b> to the beginning of the program and now it works perfectly. From the chip data sheet I decided that this command would turn off that feature and I hoped that with it off, the new default would become general I/O ports.

I am beginning to love this <b>poke</b> command!

But this does raise another question in my mind. How does one know what is default for a port and what isn't? If I read the data sheet all the I/O functions are listed first on the pin call out as well as each pin description. To me that suggest they are the default, but apparently not. Trial and error to discover the results seem odd.

Bart

Ingvar
- 16th November 2004, 10:10
Hi Bart,

I assume you're using the "old" PBC since you use Poke. If you use PBP you can write "CMCON = $07", it does the same thing but is much easier to read.

If you look at Table 2-1(on page 9 in my datasheet) you can see a column on the right side that's called "Value on POR Reset". That's your overview, for more details you need to check each register. "CMCON" is listed in chapter 6.0(page 33 in my datasheet). There you'll find a description of what each bit does to your PIC, also if it's read/writeable and POR/"default" value.

/Ingvar

bartman
- 16th November 2004, 14:40
Hi,

Yes, I'm using pbc NOT the pro version. Too much cash (over $300.00 Canadian). The "crippled" cheap version was bad enough for cost.

I'll check out the datasheet again for future reference. I think I have all the appropriate pokes in place now. The test program was working anyway.

Thanks.

Bart

bartman
- 17th November 2004, 04:24
Ingvar -

I can find the table you refer to and I have looked at the tables in more detail. I'm still hard pressed to see where it is determined what the "default" pin settings are. Possibly in a terminology that I do not recognize as such.

Bart

mister_e
- 17th November 2004, 05:24
Hi Bartman,

Usual terminology POR=Power On Reset=Default value

this is what you are finding in datasheet Table 2-1, page 9.

Ingvar
- 17th November 2004, 14:26
If you want a descripion that tells you that ......GPIO.0 will start up as an analogue comparator input pin .... or whatever, you're in bad luck. No such table, you'll have to write your own. The clostest one is Table 3-1(page 24) , that table lists all register associated with GPIO, it also lists their POR("default") values. From there you need to check each register separatley, to see how the individual bits affect each pin on your Pic.

/Ingvar

bartman
- 17th November 2004, 14:51
Okay. I see what you guys are saying. I'll look at that again and see if I can now decode it.

Thanks.

Bart

bartman
- 18th November 2004, 17:09
So, when it comes to general I/O settings it is just the TRISIO that needs poking correct? GPIO is a function within and requires no other setting?

I went back to the table now that I know what to look for and that helped a lot.

Thanks.

Bart

mister_e
- 18th November 2004, 18:15
So, when it comes to general I/O settings it is just the TRISIO that needs poking correct?


correct!!!



GPIO is a function within and requires no other setting?

correct too. the only thing you have to be carefull is the POR default on some pin. Ex some have internal analog pin. If you don't need them in analog, you must turn them to digital. But you already know that!!!

regards

bartman
- 18th November 2004, 18:48
Is it the TRISIO that tells them to be digital or the poke I used to turn off the comparator?

The thing is flashing lights so I have to assume it is pulsing properly with what I have done (which is set TRISIO to output and turn off the comparator operation).

Bart

mister_e
- 19th November 2004, 02:01
TRISIO set the pin direction: input or output

your POKE to ANSEL or CMCON: is set the input mode, digital or analog.

bartman
- 19th November 2004, 04:14
All good then. The ANSEL isn't applicable to this chip as it has no analog capabilities.

Thanks. I'll need to remember this for the future if I built anything else using different chips.

Bart