Skip to content

Instantly share code, notes, and snippets.

@TheZoq2
Created April 20, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheZoq2/821e65e0e6abc1bea59f43ce823baf04 to your computer and use it in GitHub Desktop.
Save TheZoq2/821e65e0e6abc1bea59f43ce823baf04 to your computer and use it in GitHub Desktop.
.global main
main:
; Setup stack pointer
ldi r16,0x08
out SPH,r16
ldi r16,0xff
out SPL,r16
; Configure pin as output
ldi r16,(1<<PB5)
out DDRB,r16
; Initial pin value
ldi r16,0
ldi ZH, hi8(TAB)
ldi ZL, lo8(TAB)
loop:
call fetch_char
call convert_char
; ldi r16,1
; call beep
; call nobeep
; ldi r16,0
; call beep
; call nobeep
rjmp loop
; Beep related subroutines. These trash r17, r18, r19, r20
beep:
ldi r17,(1<<PB5)
out PORTB,r17
call beep_helper
ret
nobeep:
clr r15
out PORTB,r15
call beep_helper
ret
beep_helper:
cpi r16,1
breq long_beep
jmp short_beep
long_beep:
ldi r18, 82
ld_3:
ldi r19, 0
ld_2:
ldi r20, 0
ld_1:
dec r20
brne ld_1
dec r19
brne ld_2
dec r18
brne ld_3
ret
short_beep:
ldi r18, 8
sd_3:
ldi r19, 0
sd_2:
ldi r20, 0
sd_1:
dec r20
brne sd_1
dec r19
brne sd_2
dec r18
brne sd_3
ret
# Fetches a char from the Z, increments Z unless the byte is NULL
fetch_char:
lpm r16,Z
cpi r16,0
breq fetch_char_NULL
adiw r30,1
fetch_char_NULL:
ret
// Replaces the character in r16 with the morse code representation
convert_char:
ldi YH, hi8(MORSE)
ldi YL, lo8(MORSE)
add YL,r16
adc YH,0
ld r17,Y
ld r16,Y
ret
TAB:
.byte 'H'
.byte 'E'
.byte 'L'
.byte 'L'
.byte 'O'
.byte 0
MORSE:
.skip 0x40
.byte 0x60
.byte 0x88
.byte 0xA8
.byte 0x90
.byte 0x40
.byte 0x28
.byte 0xd0
.byte 0x08
.byte 0x20
.byte 0x78
.byte 0xB0
.byte 0x48
.byte 0xE0
.byte 0xa0
.byte 0xf0
.byte 0x68
.byte 0xD8
.byte 0x50
.byte 0x10
.byte 0xC0
.byte 0x30
.byte 0x18
.byte 0x70
.byte 0x98
.byte 0xB8
.byte 0xC8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment