/*
Filename: maskSw3_Mod
Author: George Howard
Date: 20/02/2024
Description: this program reads the switches from PORTC and
if DIP_switch4 is open (1) outputs the value 0xFF to LEDs on Port A
if DIP_switch4 is closed = ON (0) outputs the value 0x00 to LEDs on
Port A
*/
#include <avr/io.h>
#include <util/delay.h>
#define MASK03 0x20 //0010 0000
//============== Executive Loop
int main(void)
{
unsigned char switchesState, ledsOut, maskedSw;
//configure the ports
DDRC = 0x00; //all Port C pins configured as input
DDRA = 0xFF; //all Port A configured as output
PORTC = 0xFF; //enable the pull-up resistors
while(1)
{ //--- put your tasks here.
switchesState = PINC; //read from the Port C switches
maskedSw = switchesState & MASK03; //mask all the bits but bit 3
//select what to display based on the state of SW3
switch(maskedSw)
{
case 0x00:
ledsOut = 0x00;
break;
case MASK03:
ledsOut = 0xFF;
break;
}
PORTA = ledsOut; //display ledsOut to Port A
}
}