0% found this document useful (0 votes)
31 views

Lab No. 1 - I/O Ports Programming & LED Interfacing: Home Task

The document describes an experiment with interfacing LEDs to an Arduino board. It explains that if bit 0 of PORTB is high, the LEDs connected to PORTA will light up from least significant bit to most significant bit. If bit 0 of PORTB is low, the LEDs will light up from most significant bit to least significant bit, with only one LED turning on at a time in both cases. It provides the code to implement this functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lab No. 1 - I/O Ports Programming & LED Interfacing: Home Task

The document describes an experiment with interfacing LEDs to an Arduino board. It explains that if bit 0 of PORTB is high, the LEDs connected to PORTA will light up from least significant bit to most significant bit. If bit 0 of PORTB is low, the LEDs will light up from most significant bit to least significant bit, with only one LED turning on at a time in both cases. It provides the code to implement this functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab No.

1 - I/O Ports Programming & LED Interfacing


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;
unsigned char msb[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char lsb[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
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);}}}

You might also like