Author Topic: Project of Atmega  (Read 959 times)

0 Members and 1 Guest are viewing this topic.

Offline yalectTopic starter

  • Regular Contributor
  • *
  • Posts: 133
Project of Atmega
« on: December 26, 2017, 06:37:07 pm »
Hi,
I want to ask you about this C program that make the Led connected to the output of Atmega fliflop but the problem is when I simulated this program on Protuse I observed that the Led still on not flashs
2) which program or software is better to simulate Atmega?
thank you
**********************************************************************************************************
int main(void)
{
  DDRC |= (1<<PINC0); //Nakes first pin of PORTC as Output
  // OR DDRC = 0x01;
  DDRD &= ~(1<<PIND0);//Makes firs pin of PORTD as Input
  // OR DDRD = 0x00; //Makes all pins of PORTD input
  while(1) //infinite loop
  {
    if(PIND & (1<<PIND0) == 1) //If switch is pressed
    {
      PORTC |= (1<<PINC0); //Turns ON LED
      Delay_ms(3000); //3 second delay
      PORTC &= ~(1<<PINC0); //Turns OFF LED
    }
  }
}
 

Offline hugatry

  • Contributor
  • Posts: 17
  • Country: 00
Re: Project of Atmega
« Reply #1 on: December 26, 2017, 07:11:06 pm »
The code actually works (almost) as you intended it to work; While PD0 is high, PC0 repeatedly toggles between high and low.
Problem is, the low-state won't last long. PC0 goes back to high so fast that you won't even notice the low-state.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf