Final Exam Topic 1 Example Questions
Final Exam Topic 1 Example Questions
Final Exam Topic 1 Example Questions
Problem 1 : Write the C program to scan the BT0, BT1, BT3,BT4 when button-x is pressed, toggle The aprropriate LED0,LED1, LED3 and LED4.
#ifndef F_CPU
#endif
#define BT0 0
#define BT1 1
#define BT3 3
#define BT4 4
#define LED0 4
#define LED1 5
#define LED2 6
#define LED3 7
#include <avr/io.h>
#include <util/delay.h>
int main(void)
PORTD = 0xFF;
while(1) //loop
{
if((PINB & 1<<BT0)==0) //If BT0 is pressed
{ _delay_ms(1000);
//-----------
{ _delay_ms(1000);
//--------------
{ _delay_ms(1000);
{ _delay_ms(1000);
.nolist
.list
OUT DDRB,R16
OUT PORTB,R16
OUT DDRD,R16
OUT PORTD,R16
while_1:
IN R16, PINB
ldi R17,(1<<0)
AND R16,R17
BRNE check_1
ldi R17,(1<<4)
IN R16,PORTD
EOR R17,R16
jmp while_1
;-----------------------------------------------
check_1:
IN R16,PINB
ldi R17,(1<<1)
AND R16,R17
BRNE check_2
ldi R17,(1<<5)
IN R16,PORTD
EOR R17,R16
JMP while_1
;--------------------------------------------------
check_2:
IN R16,PINB
ldi R17,(1<<3)
AND R16,R17
BRNE check_3;
ldi R17,(1<<6)
IN R16,PORTD
EOR R17,R16
JMP while_1
;------------------------------------------------------
check_3:
IN R16,PINB
ldi R17,(1<<4)
AND R16,R17
BRNE while_1
ldi R17,(1<<7)
IN R16,PORTD
EOR R17,R16
JMP while_1
Advance questions : Compile Assembly Code in Problem 2 into AVR Binary Machine Code