Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start:
- ; r24 and r25 are input
- ldi r20, 16 ; Amount of times to loop
- loop:
- sbi PORTB, 2 ; 2cc Set bit 2 in PORTB, after this instruction we start counting
- nop ; 1cc 1 Wait a cycle
- lsr r24 ; 1cc 2 r24 >> 1, puts bit 0 into carry flag
- ror r25 ; 1cc 3 r25 >> 1, puts carry flag into bit 7
- ldi r18, 255 ; 1cc 4 r18 is going to be data[0] << 2, alternative instruction: ser r18
- rol r18 ; 1cc 5 r18 is 11111111 if bit in data set, 11111110 otherwise
- rol r18 ; 1cc 5 r18 << 1 + C, r18 is 11111111 if bit in data set, 11111101 otherwise
- rol r18 ; 1cc 7 r18 << 1 + C, r18 is 11111111 if bit in data set, 11111011 otherwise
- in r19, PORTB ; 1cc 8 Read the value of PORTB to "and" with
- and r18, r19 ; 1cc 9 Do the "and"
- out PORTB, r18 ; 1cc 10 Write the value back to PORTB <- here we are at the 625ns
- ldi r18, 2 ; 1cc 11 Use a small loop to wait a few cycles
- wait:
- dec r18 ; 1cc 12
- brne wait ; 2cc/1cc 16 Delay = (1 + 2) * 2 - 1 -> 11 + 5 = 16
- nop ; 1cc 17 Delay again 2 cycles
- nop ; 1cc 18
- cbi PORTB, 2 ; 2cc 20 Clear the bit in PORTB again <- here we are at the 1250ns
- nop ; 1cc 21 Wait 2 cycles
- nop ; 1cc 22
- dec r16 ; 1cc 23 Loop 16 times
- brne loop ; 2cc/1cc 25/24 Jump if not zero yet (+2 cycles from the sbi PORTB, 25+2 makes 27)
- nop ; 1cc 25 Wait 3 cycles for the last one
- nop ; 1cc 26
- nop ; 1cc 27
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement