Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

blink led program in c18 compiler

Status
Not open for further replies.

hemnath

Advanced Member level 3
Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Visit site
Activity points
6,589
Hi, I'm using c18 compiler, 18F8722 microcontroller, cystal 20Mhz.

HTML:
#include<p18f8722.h>                                                    
#pragma config  OSC = HS, IESO = OFF, FCMEN = OFF, WDT = OFF
/*  ***************  TIMER *************** */
void delayzz(void)
{             
	int i, j;
	for(i=0;i<1000;i++)
	{
		for(j=0;j<2;j++)
		{         
			  /* Well its Just a Timer */            
		}    
	}   
}
                           

                /* ****************** MAIN ****************** */

void main(void)
{
	TRISD= 0x00;                  // PORT B Setting: Set all the pins in port B to Output.

	while(1)  
	{
		LATDbits.LATD0 = 1;   // RB-1 to High  

		Delay10KTCYx(250);
		
//		delayzz();
		
		LATDbits.LATD0 = 0;    // RB-0 to LOW

		Delay10KTCYx(250);
		
//		delayzz();
	}
}

Trying to blink the led which is conneced on pin D0. But it is not blinking. What could be the problem?
Please help.
 

What is happening ? Does the LED turn ON but not OFF ? Maybe delays are not proper.
 

It is not at all blinking. When I changed the configuration settings to IESO = ON. It is blinking.

I thought that crystal 20Mhz could be damaged. But already i have changed it to new crystal also.
 

HTML:
#include<p18f8722.h>                                                    
#pragma config  OSC = HS, IESO = OFF, FCMEN = OFF, WDT = OFF

void main(void)
{
	TRISD= 0x00;                  

	while(1)  
	{
		LATDbits.LATD0 = 1;   // RB-1 to High  
	}
}

Very simple code to glow the LED. It is not working with configuration settings IESO = OFF. LED glows once i changed to IESO = ON

- - - Updated - - -

But i want to use the external oscillator. Please find the zip file.
 

Attachments

  • Blink LED.zip
    18.6 KB · Views: 87

Very simple code to glow the LED. It is not working with configuration settings IESO = OFF. LED glows once i changed to IESO = ON

Proves that the external oscillator is not working. This is a hardware rather than a coding problem.

By the way, why are you always using HTML code tags for C code?
 

Are you testing on breadboard ? If yes, try on a soldered board or atleast solder the oscillator circuit and try.
 

I'm not testing on breadboard. I have a development board. Since there could be a chance of bad crystal. So i have replaced it with new 20Mhz crystal and 22pf capacitors. I have also double checked the connections from oscillator to micro-controller pins.

But still led doesn't turn ON.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top