Skip to content

Instantly share code, notes, and snippets.

@cod-r
Last active December 22, 2017 17: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 cod-r/83af8bd8b633b7d7ce81e76e50e928e3 to your computer and use it in GitHub Desktop.
Save cod-r/83af8bd8b633b7d7ce81e76e50e928e3 to your computer and use it in GitHub Desktop.
.include "m32def.inc"
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp passed_3sec
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
jmp reset
reset:
ldi r16, high(RAMEND)
out SPH, r16
ldi r16, low(RAMEND)
out SPL, r16
ldi r16, 0xFF
out DDRA, r16 ;port a is output
ldi r17, 0x00
out PORTA, r17 ;leds off
main:
cli ;interrups dezactivated
ldi r16, 0b00001000 ;configuring USART:
out UCSRB, r16 ;300bps, 8bit, even parity, 2 bit stop
ldi r16, 0b10101110
out UCSRC, r16
ldi r16, 0x06 ;setting baud rate for 8Mhz
out UBRRH, r16
ldi r16, 0x81
out UBRRL, r16
ldi r16, 0b00000000 ;seting timer counter1
out TCCR1A, r16 ;mode CTC
in r16, TIMSK
andi r16, 0b11010011
ori r16, 0b00010000
out TIMSK, r16
ldi r16, 0x5B ; 0x5B8E = 23438
out OCR1AH, r16 ;23438 * 1/(8mhz/1024) ~= 3s
ldi r16, 0x8E
out OCR1AL, r16
ldi r16, 0b00001101 ;start timer
out TCCR1B, r16
sei ;activate interrups
bucla:
rjmp bucla
passed_3sec:
in r20, SREG
ldi r16, 0b00010000
out PORTA, r16 ;led on
ldi r16, 0x6C ;ascii for "l"
out UDR, r16
call wait ;wait for data to be sent
ldi r16, 0x61 ;ascii for "a"
out UDR, r16
call wait
ldi r16, 0x62 ;ascii for "b"
out UDR, r16
call wait
ldi r16, 0x20 ;ascii for " "(SPACE)
out UDR, r16
call wait
ldi r16, 0x6D ;ascii for "m"
out UDR, r16
call wait
ldi r16, 0x69 ;ascii for "i"
out UDR, r16
call wait
ldi r16, 0x63 ;ascii for "c"
out UDR, r16
call wait
ldi r16, 0x72 ;ascii for "r"
out UDR, r16
call wait
ldi r16, 0x6F ;ascii for "o"
out UDR, r16
call wait
ldi r16, 0x00
out PORTA, r16 ;led off
out SREG, r20
reti ;return from interrupt
wait:
in r16, UCSRA ;read the state of UCSRA
sbrs r16, UDRE ;check if UDRE is empty
rjmp wait ;UDRE is not empty, we wait more
ret ;UDRE is empty, we return from waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment