Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Points will be given only to the clearest well done answers and make sure your a

ID: 3548892 • Letter: P

Question

Points will be given only to the clearest well done answers and make sure your answers are correct, i don't care who will solve them firstly unless your answers were perfectly done.

(take your time in solving them)

good luck to all.

Answer the following programming questions,


Write the code to read from LDR sensor connected to ADC5 (ATMega 32). Assume the ADC reading is left adjusted (8-bits), fclk = 8 MHz. When the voltage level is between 1.5v and 3.5v, turn on the least 4 significant bits of Port B. Otherwise, turn on the most 4 significant bits of Port B. Keep the output cleared in all other cases. Vref = 5v. Write a MIPS Assembly language code to calculate. Where x is the last digit of your student ID (Use the first digit if the last digit is 0). To multiply use mult $z, $y this will put the low order of the result in special register "LO" and the high order of the result in register "HI". To move the content of LO to register $x use mflo $x and to move the content of HI to register $x use mfhi $x). Run the code using SPIM simulator and provide screenshots of the final result. Write a subroutine in MIPS assembly that stores the numbers 1, 5, 10, 15, ..., 100. in consecutive memory locations starting at address given in $x. Where x is the last digit of your ID (Use the first digit if the last digit is 0). All registers used in the subroutine must be preserved. Simulate the subroutine as well as a calling function using SPIM. Provide screenshots of the final result. Hint: SPIM utilizes the address location starting from 0x10000000 to save temporary data in the memory.

Explanation / Answer

Only solution to Question 1:


Compiled on WinAVR-20100110

OS used Windows 8



#include<avr/io.h>

#include<util/delay.h>


unsigned char getdata(unsigned char chno)

{

ADMUX=0X60; //right align the ADC result

ADMUX|=chno; //select the ADC channel

ADCSRA|=0X40; //start ADC convertion

_delay_ms(1); //give some time delay to complete the ADC convertion

return ADCH;

}


int main(void)

{

PORTB=0x00;

DDRB=0xFF;

ADCSRA=0X87; //ADC enable, ADC interrupt enable, set prescaller to 128

unsigned int value;

while(1)

{

value=getdata(0x05); //ADC5

if(value > 76 && value < 179)

{

PORTB=0x0F;

}

else

{

PORTB=0xF0;

}

_delay_ms(500);

}

}