Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
ryusgnal said:How to write C program to make LED blinking with 1 sec delay.
int main(void) {
while(1) {
led_on();
for(int i = 0; i < 0xffff; i++);
led_off();
for(int i = 0; i < 0xffff; i++);
}
return 0;
}
crowinu said:ryusgnal said:How to write C program to make LED blinking with 1 sec delay.
what you mean by 1 second delay, the delay between on and off state??
Tricky Dicky said:Put time loop from this:
[ **broken link removed** ]
into this:
[ **broken link removed** ]Code:int main(void) { while(1) { led_on(); for(int i = 0; i < 0xffff; i++); led_off(); for(int i = 0; i < 0xffff; i++); } return 0; }
#include <reg51.h>
void timer0_init( void );
/******************************************************************************/
/* Define area */
/******************************************************************************/
#define time_high 0xFB //Change time here
#define time_low 0xB4 //Change time here
sbit Pulse = P1^ 0;
/******************************************************************************/
/* main routine area */
/******************************************************************************/
void main( void ) {
Pulse = 0;
timer0_init (); // Init timer0
while(1) { // Repeat at here
}
}
/******************************************************************************/
/* timer0 interrupt routine area */
/******************************************************************************/
void int_timer0(void) interrupt 1 {
TF0 = 0;
TR0 = 0;
Pulse = ~Pulse;
TH0 = time_high;
TL0 = time_low;
TR0 = 1;
}
/******************************************************************************/
/* Init function area */
/******************************************************************************/
void timer0_init( void ) {
TMOD &= 0xF0;
TMOD |= 0x10;
TH0 = time_high;
TL0 = time_low;
ET0 = 1;
EA = 1;
TR0 = 1;
}