Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC12F629 gp4 problem

Status
Not open for further replies.

Mat22

New Member
This is the code for car direction indicators.
Code:
void main() {
  /* Project name:
     Detect low voltage
* Description:
     Car direction indicators
* Test configuration:
     MCU:             PIC12F629
     Dev.Board:       EasyPIC5
     Oscillator:      04.0000 MHz, Internal
     SW:              mikroC PRO for PIC
*/
unsigned char i;
bit oldstate;                       // Old state flag

{
CMCON = 0b00000111;                 // disable comparators
GPIO = 0b00000000;
TRISIO = 0b00010011;                     // gp0,gp1,gp4 = inputs, gp2, gp5= outputs

  while (1)
   {
   
    if (gpio.gp0 == 0)              // while GP0 = switch pressed
        {
        gpio.F2 =1;
        delay_ms(500);
        gpio.F2 = 0;
        delay_ms(500);
        }

     if (gpio.gp1 == 0)              // while GP1 = switch pressed
        {
        gpio.F5 =1;
        delay_ms(500);
        gpio.F5 = 0;
        delay_ms(500);
        }

     if (gpio.gp4 == 0)              // while GP4 = switch pressed
        {
        gpio.F2 =1;
        gpio.F5 =1;
        delay_ms(500);
        gpio.F2 = 0;
        gpio.F5 =0;
        delay_ms(500);
        }
     }
       }

        }
program runa like gp4 is pressed all the time, but it is not?
 
Could you measure the voltage at that pin (gp4)?
 
I see that the development board EasyPIC5 has a large set of dip-switches to enable pull-up resistor and a large set of jumpers to connect and disconnect pins from devices etc. I think you have a hardware problem.. double check your board settings. Make sure that pg4 pull-up is enabled and that the pin is connected to a button.

EDIT: Looks like GP4 and GP5 are also oscillator input pins. Make sure that you have the settings right, so that the pin is configured as GPIO and that the external oscillator jumpers (J14) are correct.
 
Last edited:
You need to clear ANSEL the adc is on so GP4 is reading high.
ANSEL = 0
 
You need to clear ANSEL the adc is on so GP4 is reading high.
ANSEL = 0

I always forget that trap. I think it is weird having analog inputs on by default after reset.
 
Hello,
thank you all. I have made mistakee in my PicFlash programmer,

I defined under oscillator INTOSC -RA4 as CLKOUT, RA5 as I/O, and correct is
INTOSC -RA4 as I/O, RA5 as I/O

:)
 
Well the configure would cause a problem , but you still need to turn off the ADC or your switch will read wrong.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top