ECE 2560 Introduction to Microcontroller-Based Systems
ECE 2560 Introduction to Microcontroller-Based Systems –
Lecture 24
Laundry Day aka
Copyright By PowCoder代写 加微信 powcoder
Interrupts for a Real Life MCU Application
Joke of the Day
Why did the programmer die in the shower?
He read the shampoo bottle instructions: Lather. Rinse. Repeat.
ECE 2560 Introduction to Microcontroller-Based Systems –
Recap: Multiplying Signed Numbers
Recall, given a number x
• If the number is positive, represent it with the binary numeral for x
• If the number is negative, represent it with the binary numeral for 216 – |x|
Let’s multiply a positive and negative number: x>0 and y<0 Binary representations will be x and 216 – |y|
216 x – x |y|
And two negative numbers: x<0 and y<0
Binary representations will be 216 – |x| and 2n - |y|
These are the result in the n-bit register
232 –216 (|x|+|y|)+|x||y|
Þ Multiplication works the same way for signed & unsigned numbers as long as |xy| does not overflow the 16-bit signed number range
ECE 2560 Introduction to Microcontroller-Based Systems –
Signed/Unsigned x_times_y
Multiply all 16 bits, not just 8, but make sure that |xy| does not overflow signed integer range
ECE 2560 Introduction to Microcontroller-Based Systems –
ECE 2560 Introduction to Microcontroller-Based Systems –
Solution to Quiz 6 – Main Loop
No need to configure S1 and S2 separately
No nop necessary when there is more code to follow – in a subroutine or ISR
ECE 2560 Introduction to Microcontroller-Based Systems –
How to Write ISRs? First thing to do is to check the source of the interrupt
Ideally, all unused interrupts should be disabled
We did not pay much attention to this – but default settings are disable
Still a good idea to check the source even if there is only one interrupt expected from the source
ECE 2560 Introduction to Microcontroller-Based Systems –
How to Write ISRs?
The ISR needs to clear the interrupt flag!
BUT do not get carried away and wipe out the entire register Clear only the flags you have served!!!
Might work for the given
task BUT not good practice – think nuking a mosquito
ECE 2560 Introduction to Microcontroller-Based Systems –
Solution to Quiz 6 – ISR
serve clear
ECE 2560 Introduction to Microcontroller-Based Systems –
Solution to Quiz 6 – IVT
We add the label of the ISR to the Interrupt Vectors (at the end of *.asm) For Port P1
Identifies address 0xFFDA Label of ISR
ECE 2560 Introduction to Microcontroller-Based Systems –
One Word of Caution The order of your code can make a big difference !!
If you sandwich ISR between Stack Pointer definition and Interrupt Vectors
your code will crash
ECE 2560 Introduction to Microcontroller-Based Systems –
Your main.asm needs to end with these two blocks
in this order
Laundry Day
What does the MCU of a washing machine do?
• Program selection: Take user input and set variables such as: target water temperature, target spin speed, cycle length etc.
• Measure water temperature (sensors), compare against target water temperature
• Turn on/off heating element based on outcome of above comparison
Þ Control water temperature using a closed loop feedback
• Control spin speed
• Set timers to end one cycle segment and proceed to next segment: wash, rinse, spin
• Connect to WiFi ???
ECE 2560 Introduction to Microcontroller-Based Systems –
Configuring Target Water Temperature
User presses a single button to cycle through possible options:
Tap ColdàColdàWarmàHotàExtra Hot àTap ColdàCold ...
Task: Write assembly code that takes user input through push button S1 and sets the target water temperature (variable target_temp)
State machine starts at Warm and cycles through states as shown above Temperature values are
Tap Cold: no target value, no water temperature control loop Cold : 30°C Hot : 60°C
Warm : 40°C Extra Hot : 95°C
Follow good programming practices and good problem solving
• define constants instead of hardcoding values
• write modular code: ISR calls subroutine set_target_temp ECE 2560 Introduction to Microcontroller-Based Systems –
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com