View previous topic :: View next topic |
Author |
Message |
FFT
Joined: 07 Jul 2010 Posts: 92
|
12f675 GP2 has no internal pull-up resistor? |
Posted: Thu Jul 08, 2010 7:35 am |
|
|
Hi,
I've enabled internal pull-ups but input(GP2) returns 0...
I initialize the pic using these codes:
Code: | #include <12F675.h>
#device adc=10
#FUSES WDT,INTRC_IO,CPD,PROTECT,NOMCLR,PUT,BROWNOUT
#use fast_io(A)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
#use delay(clock=4M,RESTART_WDT)
#byte gpio = getenv("SFR:GPIO")
.
.
.
gpio = 0;
set_tris_a(0b011111);
port_a_pullups(TRUE);
setup_adc_ports(sAN0|sAN1|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_wdt(WDT_288MS);
disable_interrupts(GLOBAL);
gpio = 0; |
And GP2 is not connected anywhere, just blank.
I could not see any note in the datasheet that GP2 has no internal pull-up resistor?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 08, 2010 12:17 pm |
|
|
Quote: | I've enabled internal pull-ups but input(GP2) returns 0... |
1. Post a complete test program where you actually call this line of code.
The program should be compilable if I copy-and-paste it into MPLAB.
2. Explain how you know that the pin returns 0. The program should
have a short section that does something based on the returned value.
This could be setting an LED on or off, for example.
3. Tell if you're running this test in hardware or in Proteus.
4. Try to make a test program without all that extra code at the start
of main() that is unnecessary (such as disabling peripherals that are
already disabled upon power-on reset of the PIC).
5. Post your compiler version. |
|
|
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Fri Jul 09, 2010 10:37 am |
|
|
I'm testing on a real pcb and the GP2 is blank. My compiler version is 4.107.
in this code below led does not work. If I write GP4 instead of GP2 in if statement, led works (GP4 is already blank). I use GP0-1 as ADC but I removed the adc_read code.
Code: | #include <12F675.h>
#device adc=10
#FUSES WDT //Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES CPD //Data EEPROM Code Protected
#FUSES PROTECT //Code protected from reads
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES PUT //Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#use fast_io(A)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
#use delay(clock=4M,RESTART_WDT)
#byte gpio = getenv("SFR:GPIO")
#bit Led = gpio.5
#rom 0x3ff={0x345C} // Calibration Word
void main(void)
{
gpio = 0;
set_tris_a(0b011111);
port_a_pullups(TRUE); //*****
setup_adc_ports(sAN0|sAN1|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_wdt(WDT_288MS);
disable_interrupts(GLOBAL);
gpio = 0;
if(input(GP2) == 1) // returns 0
Led=1;
// if(input(GP4) == 1) // returns 1
// Led=1;
for(;;)
delay_us(1);
} |
Thanks in advance. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 09, 2010 11:55 am |
|
|
The 12F675 has individual enables for each pin. You have to use a
bitmask as the parameter for the port_a_pullups() function. You can't
use True/False on this PIC. Do it similar to the way you do the TRIS. |
|
|
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Sat Jul 10, 2010 9:30 am |
|
|
It works!!! Thank you very much! |
|
|
|