Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my code, to run a traffic simulation in Atmel Studio 6 on an ATmega328p,

ID: 3768066 • Letter: H

Question

Here is my code, to run a traffic simulation in Atmel Studio 6 on an ATmega328p, however I'm having trouble  adding more inputs (like traffic or pedestrian switches) and/or states (include walk signals or left turn lights), as it's a bit too simple to qualify as it stand. Please help me.

#include <avr/io.h>
#include <avr/delay.h>

void sleep(uint8_t_millisec)
{
   while(millisec)
   {
       delay_ms(1000);
       millsec--;
   }
}
main()
{
   DDRC |=1<<PC5;
   DDRC |=1<<PC4;
   DDRC |=1<<PC3;
   while(1)
   {
       PORTC &= ~(1<<PC5);
       PORTC |=(1<<PC4);
       PORTC |=(1<<PC3);
       sleep(5);
       PORTC &= ~(1<<PC4);
       PORTC |=(1<<PC5);
       PORTC |=(1<<PC3);
       sleep(2);
       PORTC &= ~(1<<PC3);
       PORTC |=(1<<PC5);
       PORTC |=(1<<PC4);
       sleep(5);
   }
}

Explanation / Answer

#include <avr/io.h>
#include <avr/delay.h>
void sleep(uint8_t millisec)
{
while(millisec)
{
delay_ms(1000);
millisec--;
}
}
main()
{
DDRC |=1<<PC5;
DDRC |=1<<PC4;
DDRC |=1<<PC3;
DDRB |=1<<PB3;
DDRB |=1<<PB2;
DDRB |=1<<PB1;

while(1)
{
PORTC &= ~(1<<PC5);
PORTB &= ~(1<<PB1);
PORTB |=(1<<PB3);
PORTC |=(1<<PC4);
PORTB |=(1<<PB2);
PORTC |=(1<<PC3);
sleep(5);
PORTB &= ~(1<<PB2);
PORTB |=(1<<PB1);
sleep(2);
PORTC |=(1<<PC5);
PORTB |=(1<<PB2);
PORTC &= ~(1<<PC3);
PORTB &= ~(1<<PB3);
sleep(5);
PORTC &= ~(1<<PC4);
PORTC |=(1<<PC3);
sleep(2);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote