I recently had a written exam for a class and one of the questions was to write a program for the ATmega8515. I wrote down this:
#include <avr/io.h>
#define F_CPU 4000000UL
#include <util/delay.h>
#define Delay 5000
int main(void){
DDRB = 0xFF; //set to output
DDRA = 0x00; //set to input
PORTB = 0xFF; //turn off all LEDs
while(1) {
if (PINA == 0b11111100){ //if SW0 and SW1 are pressed
for(uint8_t i = 7; i<=0; i--){
PORTB &= ~(1<<i); //Turn on led at location i
_delay_ms(Delay); //Delay
PORTB |= (1<<i); //Turn off led at location i
_delay_ms(Delay); //Delay
}
}
else if(PINA == 0b11111110){
for(uint8_t i=0; i>=7; i++){
PORTB &= ~(1<<i);
_delay_ms(Delay);
PORTB |= (1<<i);
_delay_ms(Delay);
}
}
else if(PINA == 0b11111101){
for(uint8_t i = 7; i<=0; i--){
PORTB &= ~(1<<i);
_delay_ms(Delay);
PORTB |= (1<<i);
_delay_ms(Delay);
}
for(uint8_t i=0; i>7; i++){
PORTB &= ~(1<<i);
_delay_ms(Delay);
PORTB |= (1<<i);
_delay_ms(Delay);
}
}
else{}
}
}
For some reason this does not work.
The expected outcome is that if the first two switches are pressed (SW0 & SW1), it'll scroll the leds from left to right. if the first switch is pressed (SW0), the LEDs will scroll from right to left. And if the second switch is pressed (SW1), the leds will scroll from left to right going back and forth forever
As of now, I know the for loops work, I've tested them in other programs. It just seems like I'm not getting and input from the switches.
