0% found this document useful (0 votes)
57 views2 pages

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

The document describes a lab experiment involving interfacing LEDs with an I/O port on a microcontroller. It specifies that if a particular pin on one port is high, the LEDs connected to another port will light up from least significant bit to most significant bit, and if the pin is low, the LEDs will light up in the opposite order, with only one turning on at a time in both cases. It provides sample code that implements this functionality by setting the ports as inputs and outputs, then using a for loop to iterate through arrays assigning either the msb or lsb values to light the LEDs in the specified fashion.
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)
57 views2 pages

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

The document describes a lab experiment involving interfacing LEDs with an I/O port on a microcontroller. It specifies that if a particular pin on one port is high, the LEDs connected to another port will light up from least significant bit to most significant bit, and if the pin is low, the LEDs will light up in the opposite order, with only one turning on at a time in both cases. It provides sample code that implements this functionality by setting the ports as inputs and outputs, then using a for loop to iterate through arrays assigning either the msb or lsb values to light the LEDs in the specified fashion.
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/ 2

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