The microcontroller used in the following problem is the Atmel 8-bit AVR microco
ID: 2080596 • Letter: T
Question
The microcontroller used in the following problem is the Atmel 8-bit AVR microcontroller (ATtiny45/ATmega88).
A programmer has a routine LDCDisplay that formats an 8-bit number in r21 as a floating point number. For example, if r21 contains the value 124 (decimal), LCDDisplay will format and display the string "12.4|" on the LCD. The programmer uses this routine in a timer overflow ISR to update the LCD periodically: tim0_ovf: push SREG ldi r30, LOW(dcycle) ldi r31, HIGH(dcycle) Id r21, z rcall LCDDisplay pop SREG reti There are at least two potential serious errors lurking in this code. What are they?Explanation / Answer
The potential serious errors in the code are:
1. dcycle variable needs to be defined in the scope of the ISR routine tim0_ovf
2. ldi (load Immediate) is used for loading values directly into the registers. We cannot use it to load from memory (variables)
3. As there are no possible instructions affecting the SREG, we can get rid of pushing and popping operation
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.