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.

How to write a C program to make blinking LED with 1 sec delay?

Status
Not open for further replies.

ryusgnal

Advanced Member level 4
Full Member level 1
Joined
Oct 4, 2005
Messages
102
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,298
Location
Malaysia
Activity points
1,992
How to write C program to make LED blinking with 1 sec delay.
 

Re: Blinking LED

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??
 

Re: Blinking LED

Put time loop from this:
[ **broken link removed** ]
into this:
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;
}
[ **broken link removed** ]
 

Re: Blinking LED

hi
why dont you use delay calculator for it, if you need I will upload it.

regards
 

Re: Blinking LED

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??

Yes. Can you help?

Added after 3 minutes:

Tricky Dicky said:
Put time loop from this:
[ **broken link removed** ]
into this:
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;
}
[ **broken link removed** ]

Where should I connect the LED if I want to build the hardware with this code.
 

Re: Blinking LED

Code:
#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;
}
The best way by using interrupt timer to do it. Try at this code by adjust the time_high and time_low define value.
 

Re: Blinking LED

I am using PIC16F877A........ Please help me.
 

Blinking LED

Try to use interrupt timer interval, then you can put a blinking of LED inside a interrupt service routine.
 

Re: Blinking LED

You will need CCS compiler for my code.
 

Blinking LED

;Copy this codes and assemble
;///Program starts here///
; Connect your led to Portb,0

list p=16f877A
#include <p16F877A.inc>

bsf STATUS,RP0
clrf TRISB ; all TRISB pins OUTPUT
bcf STATUS,RP0

main
bsf PORTB,0 ; Led connected PB0
call Wait1_sec
bcf PORTB,0
call Wait1_sec
goto main

call Wait1_sec

cblock
d0
d1
d2
endc
Wait1_sec ;!!! 1sec for 4mhz XTAL !!!!
movlw 0x08 ; You OSC is not indefinite , i'm sorry
movwf d0 ; please tell me
movlw 0x2F
movwf d1
movlw 0x03
movwf d2
Delay_0
decfsz d0, f
goto $+2
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0

goto $+1
return

end
;//// THE END ////
;This way is very strong, keep your hair on CSS ....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top