This shows you the differences between two versions of the page.
| en:multiasm:exercisesbook:avr:sut:scenarios:avr3 [2026/05/03 19:59] – created pczekalski | en:multiasm:exercisesbook:avr:sut:scenarios:avr3 [2026/05/12 10:01] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== AVR3: Using 7-segment display ====== | ||
| + | In this scenario, you will implement a code that displays on the 7-segment display.\\ | ||
| + | |||
| + | ** Prerequisites **\\ | ||
| + | You need to book one of the AVR laboratory nodes and ensure the video stream is live. | ||
| + | |||
| + | ** Scenario **\\ | ||
| + | Implement an algorithm that displays your birth year (or any other 4-digit number) on the LED 7-segment display. | ||
| + | |||
| + | ** Result **\\ | ||
| + | Observe the number via the video stream. | ||
| + | |||
| + | ** Start **\\ | ||
| + | Use AVR GCC syntax (as in the instruction): | ||
| + | Use the function '' | ||
| + | |||
| + | Also note you need to define a stack to use '' | ||
| + | |||
| + | In this algorithm, you go "full throttle" | ||
| + | |||
| + | ** Step 1 **\\ | ||
| + | Compose application definitions and configuration. Set up a stack. We do not use the' | ||
| + | <code asm> | ||
| + | ; --- Single .equ for RAM End --- | ||
| + | .equ SPH, 0x3E ; Stack Pointer High | ||
| + | .equ SPL, 0x3D ; Stack Pointer Low | ||
| + | .equ SER_PORT, 0x05 ; PORTB I/O address | ||
| + | .equ SER_PIN, | ||
| + | .equ DDRD, | ||
| + | .equ DDRB, | ||
| + | .equ CLK_PORT, 0x0B ; PORTD I/O address | ||
| + | .equ CLK_PIN, | ||
| + | .equ LAT_PORT, 0x0B ; PORTD I/O address | ||
| + | .equ LAT_PIN, | ||
| + | .equ RAMEND, | ||
| + | |||
| + | .section .text | ||
| + | .org 0x0000 | ||
| + | rjmp RESET | ||
| + | |||
| + | reset: | ||
| + | ; Initialise Stack Pointer using hi8 and lo8 functions | ||
| + | ldi r16, lo8(RAM_END) | ||
| + | out SPL, r16 | ||
| + | ldi r16, hi8(RAM_END) | ||
| + | out SPH, r16 | ||
| + | </ | ||
| + | |||
| + | ** Step 2 **\\ | ||
| + | Configure pins that control the display as outputs (GPIO 8, GPIO 7, GPIO 4): | ||
| + | <code asm> | ||
| + | ; Initialise display control outputs | ||
| + | sbi DDRB, SER_PIN | ||
| + | sbi DDRD, CLK_PIN | ||
| + | sbi DDRD, LAT_PIN | ||
| + | </ | ||
| + | |||
| + | ** Step 3 **\\ | ||
| + | Make a loop that calls the ' | ||
| + | As you use constant variables (the easiest, naturally, use '' | ||
| + | |||
| + | |||
| + | **Step4** | ||
| + | Copy '' | ||
| + | <code asm> | ||
| + | main_loop: | ||
| + | ; Display Pattern A (D2, D4 ON) | ||
| + | ldi r16, PATTERN_A | ||
| + | out PORTB, r16 | ||
| + | rcall delay_2s | ||
| + | |||
| + | ; Display Pattern B (D1, D3 ON) | ||
| + | ldi r16, PATTERN_B | ||
| + | out PORTB, r16 | ||
| + | rcall delay_2s | ||
| + | |||
| + | rjmp main_loop | ||
| + | </ | ||
| + | |||
| + | ** Result validation **\\ | ||
| + | You should be able to see the number on the 7-segment display via the video stream. | ||
| + | |||
| + | ** FAQ **\\ | ||
| + | When using the printed version of this manual, please refer to the latest online version for the most up-to-date list of FAQs.\\ | ||
| + | |||
| + | **It does not show up at all**: Did you compile and upload to the device? Those are separate steps: it is not enough to just compile, but you also need to " | ||
| + | // | ||