CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with I/O output

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
seanbb



Joined: 10 Jan 2007
Posts: 5

View user's profile Send private message

Problem with I/O output
PostPosted: Mon Jan 15, 2007 8:49 pm     Reply with quote

Hi, I fail to output GP0 high of PIC12F510.
Do I need to config the TRISIO? In my watch window, I found TRISIO, GPIO is always 0.
seanbb



Joined: 10 Jan 2007
Posts: 5

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 8:53 pm     Reply with quote

Here is my code

#include <12f510.h>
#include <stdlib.h>
//#include <delay.c>

//#fuses INTRC, NOWDT,NOPROTECT,NOMCLR


#fuses NOWDT,NOPROTECT,NOMCLR,INTRC
#use delay(clock=8000000)


//#endif

#define adc=8;//sean
void init(void);
char adc_tmp[5];
char i=0;
char pin_to_use;


void main()
{
init();

while(TRUE)
{
for(i=0;i<5;i++)
{
delay_ms(50);
set_adc_channel(2);
adc_tmp[i] = read_adc();
}
i=0;
pin_to_use = PIN_B0;
switch(pin_to_use) {
case PIN_B0:
output_high(PIN_B0);
break;
case PIN_B1:
output_high(PIN_B1);
break;
case PIN_B3:
output_high(PIN_B3);
break;
}
delay_ms(1000);
}
}

void init()
{
// setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
// set_tris_b(0x0b);
setup_adc_ports(AN2); // Setup ADC to AN0
setup_adc(ADC_CLOCK_INTERNAL); // Set ADC On
delay_ms(500);
}
Code:
seanbb



Joined: 10 Jan 2007
Posts: 5

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 10:05 pm     Reply with quote

Hi, I have try to set GP4 as output by output_high(PIN_B4), and GP5 as output by output_high(PIN_B5), it is working correct.

While I try to set GP0, GP1 to output high, it is not working. The difference between GP0,1 and GP5,6 is that GP0,1 work as AN0/1 as highest priority, while Gp4,5 work as OSC as highest priority. Does it make the sense?

If it is, how to set the GP0,1 Correct to get the output high?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 10:45 pm     Reply with quote

Whenever a pin doesn't work in the expected way, you need to look
at the pin description table in the data sheet. Usually it's in the
Device Overview section. For the 12F510, it's in the Architectural
Overview section: TABLE 3-2: PIN DESCRIPTIONS – PIC12F510

That table shows that pin GP0 can be: GP0, AN0, C1IN+, and ICSPDAT.
In other words, this pin can be used for General Purpose I/O, Analog
input, Comparator input, or a programming pin.

The PIC comes up from power-on reset with the comparator enabled.
That's apparent from looking at the data sheet, at the CM1CON0 register
diagram in the Comparator section.

You didn't say what version of the compiler you have. For the PCB
compiler, I only have the free version that comes with MPLAB 7.41,
which is PCB vs. 3.249. The compiler puts its init code at the start
of main(). In the .LST file, I don't see very much init code at all.
That's not normal. But anyway, this means you need to put in a line
of code to disable the comparator, so you can use pin GP0 for i/o.
So in your init() function, just add this line:
Code:
setup_comparator(NC_NC);

There might be other problems, but at a minimum you need to do this.
Guest








PostPosted: Thu Jan 18, 2007 1:16 am     Reply with quote

thanks, just add setup_comparator(NC_NC), i solve the problem...;-)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group