|
|
View previous topic :: View next topic |
Author |
Message |
seanbb
Joined: 10 Jan 2007 Posts: 5
|
Problem with I/O output |
Posted: Mon Jan 15, 2007 8:49 pm |
|
|
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
|
|
Posted: Mon Jan 15, 2007 8:53 pm |
|
|
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);
}
|
|
|
seanbb
Joined: 10 Jan 2007 Posts: 5
|
|
Posted: Mon Jan 15, 2007 10:05 pm |
|
|
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
|
|
Posted: Mon Jan 15, 2007 10:45 pm |
|
|
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
|
|
Posted: Thu Jan 18, 2007 1:16 am |
|
|
thanks, just add setup_comparator(NC_NC), i solve the problem...;-) |
|
|
|
|
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
|