LED blinking program

Status
Not open for further replies.

jidan12

Newbie level 5
Joined
Oct 5, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
58
HI,
I wrote code for LED blinking
start
turn ON LED
wait for some time (delay )
turn OFF LED

Code:
// LED blinking c code 
//start 
//turn ON LED
// wait for some time (delay )
// turn OFF LED


include<regx51.h>		        // header file for 8051 
include<delay.h>				// header file for delay 
#define LED_ON  00000001		// LED ON
#define LED_off 00000000        // LED OFF      			
void main()					   //main function starts
{
while (1)				       //infinite loop
{		                  
setb P1_1=00000001;
delay (1000);
setb P1_1=00000000;
}
}
"LED" - 0 Error(s), 2 Warning(s).

this code with no error
this code will work ?
 

That won't work because after executing the code
Code:
setb P1_1=00000000;
the instruction pointer jumps immediately to
Code:
setb P1_1=00000001;
to turn the LED on again. With common microcontroller clock frequencies this means the duty cycle of the LED will be very close to 1, thus giving the impression the LED is turned on all the time. You need to add a second delay after turning the LED off.

Also, why are you defining the constants LED_ON and LED_OFF, while you don't use them?
 

Code:
// LED blinking c code 
//start 
//turn ON LED
// wait for some time (delay )
// turn OFF LED


include<regx51.h>		        // header file for 8051 
include<delay.h>				// header file for delay 
#define LED_ON  00000001		// LED ON
#define LED_off 00000000        // LED OFF      			
void main()					   //main function starts
{
while (1)				       //infinite loop
{		                  
setb P1_1=00000001;
delay (1000);
setb P1_1=00000000;
[COLOR="#FF0000"]delay (1000);[/COLOR]
}
}

What is the LED state after programmed your original program?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…