Lab No. 1 - I/O Ports Programming & LED Interfacing: Home Task
Lab No. 1 - I/O Ports Programming & LED Interfacing: Home Task
Home Task:
If Bit 0 of PORTB is high, LEDs connected at PORTA will glow from LSB to MSB.
If Bit 0 of PORTB is low, LEDs connected at PORTA will glow from MSB to LSB. In
both
cases, one LED should be ON at a time.
CODE:-
#define F_CPU 1000000UL
#include <util/delay.h> // For delay function
#include <avr/io.h>
int main(void)
{DDRA = 0xFF; // Set Port A as output, Data Direction Register
DDRB = 0x00; // Set Port B as input, Data Direction Register
while(1) //Forever Loop
{ unsigned char x;
if(PINB&0b00000001)
{for(x=0;x<8;x++)
{PORTA=msb[x];
_delay_ms(250);}}
else
for(x=0;x<8;x++)
{ PORTA=lsb[x];
_delay_ms(250);}}}