EmbeddedRelated.com
Forums

Setting up IO ports

Started by ajellisuk September 20, 2008
Hi

I'm new to pics, and have a project where I'm using a PIC10F206.

I'm trying to set all I/O ports to 0 but I'm having no success. All
ports seem to be high except GP2 which oscillates.

My code is:

#include <10F206.h>

void main()
{
set_tris_b(0x00);

output_b(0);

while(1);

}

I'm sure the chip is being programmed because MPLAB says it was
successful. Could someone please explain what I'm doing wrong.

Thanks in advance.

Andrew Ellis
Hi Andrew,
I have not got into embedded C as yet, but from my experience of assembler, and having a quick read of the data sheet, you have to set some register bits to switch off some of the functions that share with the I/O ports. The priority function of the I/O pins, i.e. when the IC is first powered up/reset, are as follows:

GP0 = CIN+ = comparator input
GP1 = CIN- = comparator input
GP2 = FOSC4 = crystal oscillator divided by 4
GP3 = MCLR = master clear

apparently GP3 is an input only.

You will have to look at the configuration or special function registers in the datasheet to see which bits need to be set/unset to make the GP0 available. I don't know how you can do this with the compiler you are using.

Hope that at least points you in the right direction.

Gavin

--- On Sat, 9/20/08, ajellisuk wrote:
From: ajellisuk
Subject: [piclist] Setting up IO ports
To: p...
Date: Saturday, September 20, 2008, 7:24 PM

Hi

I'm new to pics, and have a project where I'm using a PIC10F206.

I'm trying to set all I/O ports to 0 but I'm having no success. All

ports seem to be high except GP2 which oscillates.

My code is:

#include <10F206.h>

void main()

{

set_tris_b(0x00) ;

output_b(0);

while(1);

}

I'm sure the chip is being programmed because MPLAB says it was

successful. Could someone please explain what I'm doing wrong.

Thanks in advance.

Andrew Ellis