This is to be run on the Atmel 169P microcontroller. Copy and paste your code ri
ID: 2248924 • Letter: T
Question
This is to be run on the Atmel 169P microcontroller. Copy and paste your code right below the problem statement and also include screenshots of your answer. 1. Attach 8 switches on PORTD and 8 LED's attached to PORTB. Write assembly code so that when switch on PD0 is on LED on PB0 is on, switch on PD1 is on LED on PB1 is on, and repeat for all rest of the switches and LED's 2. Attach 8 switches on PORTD and 8 LED's attached to PORTB Write code so that when switch PD0 is on a binary 0 is sent to LEDs and no LEDs are on, when LEDs switch PD1 is on a binary 1 is displayed on LEDs, when LEDs switch PD2 is on a binary 2 is displayed on LEDs, when switch PD3 is on a binary 3 is displayed on LEDs, keep doing all the way up to when PD7 is on a binary 7 is displayed on the LEDs.Explanation / Answer
ATMEL 169P Microcontroller Program:
Here the Atmel 169P Microcontroller is programmed with AtmelStudio Software.The Atmel Studio software uses the C programming to write the codes hence, the program to be loaded into the Atmel studio to perform the following given functions is given as,
1.) the program to connect 8 switches to 8 LEDs
// first we need to initialize the pins to switches and leds
void main()
{
TRISD.F0 = 1; // initializing all the bits 0-7 of PORTD as input
TRISD.F1 = 1;
TRISD.F2 = 1;
TRISD.F3 = 1;
TRISD.F4 = 1;
TRISD.F5 = 1;
TRISD.F6 = 1;
TRISD.F7 = 1;
TRISB.F0 = 0; // initializing all the bits 0-7 on PORTB as outputs
TRISB.F1 = 0;
TRISB.F2 = 0;
TRISB.F3 = 0;
TRISB.F4 = 0;
TRISB.F5 = 0;
TRISB.F6 = 0;
TRISB.F7 = 0;
// now making all LEDs OFF
PORTB.F0 = 0;
PORTB.F1 = 0;
PORTB.F2 = 0;
PORTB.F3 = 0;
PORTB.F4 = 0;
PORTB.F5 = 0;
PORTB.F6 = 0;
PORTB.F7 = 0;
do
{
if ( PORTD.F0 == 0) // if switch 0 is pressed
{
PORTB.F0 = 1; // LED 0 is ON
}
if ( PORTD.F1 == 0) // if switch 1 is pressed
{
PORTB.F1 = 1; // LED 1 is ON
}
if ( PORTD.F2 == 0) // if switch 2 is pressed
{
PORTB.F2 = 1; // LED 2 is ON
}
if ( PORTD.F3 == 0) // if switch 3 is pressed
{
PORTB.F3 = 1; // LED 3 is ON
}
if ( PORTD.F4 == 0) // if switch 4 is pressed
{
PORTB.F4 = 1; // LED 4 is ON
}
if ( PORTD.F5 == 0) // if switch 5 is pressed
{
PORTB.F5 = 1; // LED 5 is ON
}
if ( PORTD.F6 == 0) // if switch 6 is pressed
{
PORTB.F6 = 1; // LED 6 is ON
}
if ( PORTD.F7 == 0) // if switch 7 is pressed
{
PORTB.F7 = 1; // LED 7 is ON
}
} while ( 1) ; // an always executing loop
}
note : the program is written in separate if statements for easy understanding of the program, all the if statements can also be enclosed within a single loop also.
2.) the program to display 3 bit binary numbers in 8 LEDs
// here the port assignments for LEDs and switches are same as above program
void main()
{
TRISD.F0 = 1; // initializing all the bits 0-7 of PORTD as input
TRISD.F1 = 1;
TRISD.F2 = 1;
TRISD.F3 = 1;
TRISD.F4 = 1;
TRISD.F5 = 1;
TRISD.F6 = 1;
TRISD.F7 = 1;
TRISB.F0 = 0; // initializing all the bits 0-7 on PORTB as outputs
TRISB.F1 = 0;
TRISB.F2 = 0;
TRISB.F3 = 0;
TRISB.F4 = 0;
TRISB.F5 = 0;
TRISB.F6 = 0;
TRISB.F7 = 0;
// now making all LEDs OFF
PORTB.F0 = 0;
PORTB.F1 = 0;
PORTB.F2 = 0;
PORTB.F3 = 0;
PORTB.F4 = 0;
PORTB.F5 = 0;
PORTB.F6 = 0;
PORTB.F7 = 0;
do
{
if ( PORTD.F0 == 0 ) // if the switch 0 is switched ON
{
PORTB.F0=0; // output a binary 0 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=0; // 0 in decimal = 00000000 in binary of 8 bits
PORTB.F2=0; // therefore all LEDs are OFF
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
if ( PORTD.F1 == 0 ) // if the switch 1 is switched ON
{
PORTB.F0=1; // output a binary 1 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=0; // 1 in decimal = 00000001 in binary of 8 bits
PORTB.F2=0; // therefore all LEDs are OFF except LED 0
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
if ( PORTD.F2 == 0 ) // if the switch 2 is switched ON
{
PORTB.F0=0; // output a binary 2 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=1; // 2 in decimal = 00000010 in binary of 8 bits
PORTB.F2=0; // therefore all LEDs are OFF except LED 1
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
if ( PORTD.F3 == 0 ) // if the switch 3 is switched ON
{
PORTB.F0=1; // output a binary 3 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=1; // 3 in decimal = 00000011 in binary of 8 bits
PORTB.F2=0; // therefore all LEDs are OFF except LED 0 and LED 1
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
if ( PORTD.F4 == 0 ) // if the switch 4 is switched ON
{
PORTB.F0=0; // output a binary 4 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=0; // 4 in decimal = 00000100 in binary of 8 bits
PORTB.F2=1; // therefore all LEDs are OFF except LED 2
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
if ( PORTD.F5 == 0 ) // if the switch 5 is switched ON
{
PORTB.F0=1; // output a binary 5 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=0; // 5 in decimal = 00000101 in binary of 8 bits
PORTB.F2=1; // therefore all LEDs are OFF except LED0 and LED2
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
if ( PORTD.F6 == 0 ) // if the switch 6 is switched ON
{
PORTB.F0=0; // output a binary 6 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=1; // 6 in decimal = 00000110 in binary of 8 bits
PORTB.F2=1; // therefore all LEDs are OFF except LED 1 and LED 2
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
if ( PORTD.F7 == 0 ) // if the switch 7 is switched ON
{
PORTB.F0=1; // output a binary 7 to all LEDS , taking LED 0 as LSB and LED 7 as MSB
PORTB.F1=1; // 7 in decimal = 00000111 in binary of 8 bits
PORTB.F2=1; // therefore all LEDs are OFF
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
}
} while(1) ; // always executing loop
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.