Last active
December 17, 2015 18:29
-
-
Save kala13x/5653434 to your computer and use it in GitHub Desktop.
AVR Assembly Code for BIGAVR6 Board. It's like piano. When you press a button on the board, code returns some tone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //;========================================================== | |
| ; | |
| ; Author: kala13x (a.k.a. 7th Ghost) | |
| ; AVR Assembly. | |
| ; Processor: ATMega128 | |
| ; Board: BIGAVR6 | |
| ; | |
| ; Code works on BIGAVR6 board. It's like piano. | |
| ; When you press a button on board, code returns some tone. | |
| ; | |
| ;============================================================// | |
| #include "m128def.inc" | |
| .org 0x0000 JMP reset | |
| .org 0x0100 | |
| reset: | |
| ;---------------------------------- | |
| ; Configure Stack Ponter | |
| LDI r16, 0x10 OUT SPH, r16 | |
| LDI r16, 0xFF OUT SPL, r16 | |
| ;---------------------------------- | |
| ;---------------------------------------- | |
| ; Timer/Counter Control Registres Config | |
| ; LDI r16, $00 OUT TCCR1C, r16 | |
| LDI r16, $54 OUT TCCR1A, r16 | |
| LDI r16, $09 OUT TCCR1B, r16 | |
| ;--------------------------------------- | |
| LDI r16, 32 OUT DDRB, r16 OUT PORTB, r16 | |
| ;LDI r16, 0b00000001 OUT TCCR1B, r16 ; Enable Clock | |
| ;LDI r16, 0b00010000 OUT TIMSK, r16 ; Enable Interrupt Overflow | |
| loop: | |
| ;------------------------------------------ | |
| ; Read One | |
| IN r16, PORTA | |
| CPI r16, 1 | |
| BREQ DO | |
| ;------------------------------------------ | |
| CALL PAUSE | |
| ;------------------------------------------ | |
| ; Read Two | |
| IN r16, PORTA | |
| CPI r16, 2 | |
| BREQ RE | |
| ;------------------------------------------ | |
| CALL PAUSE | |
| JMP loop | |
| DO: | |
| ;------------------------------------------ | |
| ; Tone Do | |
| LDI r16, $10 OUT OCR1AH, r16 | |
| LDI r16, $09 OUT OCR1AL, r16 | |
| JMP loop | |
| ;------------------------------------------ | |
| RE: | |
| ;------------------------------------------ | |
| ; Tone RE | |
| LDI r16, $30 OUT OCR1AH, r16 | |
| LDI r16, $09 OUT OCR1AL, r16 | |
| JMP loop | |
| ;------------------------------------------ | |
| PAUSE: | |
| ;----------------------------------------------- | |
| ; Pause Function | |
| PUSH R16 | |
| IN R16, SREG | |
| PUSH R16 | |
| LDI R19, 0 | |
| P1: | |
| LDI R18, 0 | |
| P2: | |
| LDI R17, 0 | |
| P3: | |
| INC R17 | |
| CPI R17, 128 | |
| BRNE P3 | |
| INC R18 | |
| CPI R18, 128 | |
| BRNE P2 | |
| INC R19 | |
| CPI R19, 64 | |
| BRNE P1 | |
| POP R16 | |
| OUT SREG, R16 | |
| POP R16 | |
| ;----------------------------------------------- | |
| RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment