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.

Gpio not turning high in led blink program

Status
Not open for further replies.
Hi all iam new to pic12f675.trying to implement led blink program
But Gpio not turning high
kindly review the code below and please guide

#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-Up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config CP = OFF // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)

#include <xc.h>
#define _XTAL_FREQ 4000000
void main(void) {
TRISIO = 0x00;//set led as o/p
ANSEL = 0x00;//for setting digital i/o
CMCON = 0x07;
VRCON = 0x00;
ADCON0 = 0x00;
GPIO = 0;
// INTCON.PIE=0;
while(1)
{

GP2 = 1;// setting port as 1
__delay_ms(2000);
GP2 = 1;// setting port as 1
__delay_ms(2000);

}

return;
}
 
TRISIO, ANSEL and CMCON are all correct. I find no need for VRCON or ADCON0 as those are turned off.
Is GP2 a valid identifier, or should it be GPIO.2 ?
 
Code:
GP2 = 1;// setting port as 1
__delay_ms(2000);
GP2 = 1;// setting port as 1
__delay_ms(2000);

Looks like you are turning on GP2 and then doing the same after 2 sec delay. If you want GP2 low you want it like this:
Code:
GP2 = 1;// setting port as 1
__delay_ms(2000);
GP2 = 0;// setting port as 0
__delay_ms(2000);

GP2 is High for 2 seconds then Low for 2 seconds over and over again.

Ron
 
TRISIO, ANSEL and CMCON are all correct. I find no need for VRCON or ADCON0 as those are turned off.
Is GP2 a valid identifier, or should it be GPIO.2 ?
I cut and pasted the code into MPLABX, and it compiles fine - so presumably GP2 is perfectly acceptable?.
Code:
GP2 = 1;// setting port as 1
__delay_ms(2000);
GP2 = 1;// setting port as 1
__delay_ms(2000);

Looks like you are turning on GP2 and then doing the same after 2 sec delay. If you want GP2 low you want it like this:
Code:
GP2 = 1;// setting port as 1
__delay_ms(2000);
GP2 = 0;// setting port as 0
__delay_ms(2000);

GP2 is High for 2 seconds then Low for 2 seconds over and over again.

Ron
I noticed that as well, but I presumed he'd changed it because he can't get GP2 to go high?, and this was a desperate attempt to try and make it so - personally I'd have simply commented out all but the first of the four lines.
 
#pragma config MCLRE = ON // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
This is worded wrong MCLRE = ON means you need a resistor to 5v circ 10k.. MCLRE = OFF means tied internally

datasheet said:
bit 5 MCLRE: GP3/MCLR Pin Function Select bit(5)
1 = GP3/MCLR pin function is MCLR
0 = GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top