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?
 
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:
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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…