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.

led flashing using timer in on atmega

Status
Not open for further replies.

Disha Karnataki

Full Member level 5
Joined
Jul 20, 2013
Messages
249
Helped
9
Reputation
18
Reaction score
8
Trophy points
18
Location
india
Activity points
2,231
this is my code :
Code:
#include <avr/io.h>
  void tim0(unsigned int);
  int main(void)
  {
    DDRB=0X0F;     //making lower nibble o/p port
    PORTB=0X00;    
	TCCR0=0X01;    //timer with no prescaler
	TCNT0=0X00;    //initial count value=0x00
	while(1) 
	{  
	PORTB=0X0A;    //portb has 0x0a value
	tim0(90);       //set some delay
	PORTB=0X00;     //portb value =0x00
	tim0(90);      //set some delat
	}
	}
	void tim0(unsigned int x)       //sub routine for delay
	{
	unsigned int i;              
	
	for(i=x;i>0;i--)               
	{
	    
	     if(TCNT0!=190);        //loop till tcnt value becomes 190
		 TCNT0=0;           //reset the tcnt value back to zero
    }                     //continue this loop till i=0
	}
what is mistake in this code as only 0X0A value is shown on PORTB.
 

The code seems fine.I think it is due to the low delay that you have put..the flashing is happening at a rate so fast,your eyes perceive the LEDs to be on all the time.Increase the delay from 90 to atleast 300,and let us know what happens in that case,
 
The code seems fine.I think it is due to the low delay that you have put..the flashing is happening at a rate so fast,your eyes perceive the LEDs to be on all the time.Increase the delay from 90 to atleast 300,and let us know what happens in that case,
i have tried with 1000-9000 range but the result is same
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top