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.

C- Code issue With Led sequence.

Status
Not open for further replies.

SyPTo

New Member
I have an 12F683 , where im trying to make a double alternating strobe on GP0 and GP1 , it works , except it runs through the code 8 times then it stops and i have no idea why .



---------------------------------------------------------------------------
#include <system.h>

#pragma DATA _CONFIG, _MCLRE_OFF&_WDT_OFF&_INTRC_OSC_CLKOUT

#pragma CLOCK_FREQ 4000000

void main()
{ cmcon = 7;
trisio = 0b00001000;
gpio = 0;
delay_ms(500);

{ gpio.0 = 1;
delay_ms(100);
gpio.0 = 0;
delay_ms(50);
gpio.0 = 1;
delay_ms(100);
gpio.0 = 0;
delay_ms(50);
gpio.1 = 1;
delay_ms(100);
gpio.1 = 0;
delay_ms(50);
gpio.1 = 1;
delay_ms(100);
gpio.1 = 0;
return;
}
}
-------------------------------------------------------------------------

So if someone can enlighten me i would really appreciate it.
 
Last edited:
It will only execute once! There is no super loop only a return. This requires a while(1); before gpio.0 = 1 and the return stament outside the brackets such:

Code:
#include <system.h>

#pragma _CONFIG, _MCLRE_OFF&_WDT_OFF&_INTRC_OSC_CLKOUT

#pragma CLOCK_FREQ 4000000

void main()
	{ 
	cmcon = 7; 
	trisio = 0b00001000; 
	gpio = 0;
	delay_ms(500);

	while(1)
		{ 
		gpio.0 = 1;
		delay_ms(100);
		gpio.0 = 0;
		delay_ms(50);
		gpio.0 = 1;
		delay_ms(100);
		gpio.0 = 0;
		delay_ms(50);
		gpio.1 = 1;
		delay_ms(100);
		gpio.1 = 0;
		delay_ms(50);
		gpio.1 = 1;
		delay_ms(100);
		gpio.1 = 0;
		}
	return;
	}

Cheers Ian
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top