kgavionics
Full Member level 3
- Joined
- Jun 12, 2012
- Messages
- 167
- Helped
- 7
- Reputation
- 14
- Reaction score
- 11
- Trophy points
- 1,298
- Location
- Alberta.Canada
- Activity points
- 2,479
Hello guys
I'm learning AVR assembly, and I'm having trouble sending 16bits data to a 74595(shift register). I have successfully written a code that works to send 8 bits data, but somehow it doesn't work (with a little modification of course) for 16 bits data.
to send 16 bits I modified the following code, but the output is always wrong!
Does someone have an idea how to fix this?
Thanks in advance!
I'm learning AVR assembly, and I'm having trouble sending 16bits data to a 74595(shift register). I have successfully written a code that works to send 8 bits data, but somehow it doesn't work (with a little modification of course) for 16 bits data.
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 .device ATmega328P .org 0 ldi r16,low(ramend) out sph,r16 ldi r16,high(ramend) out sph,r16 sbi ddrb,0 ; arduino pin 8 (serial in) sbi ddrd,7 ;arduino pin7 (clock) sbi ddrd,4 ;arduino pin 4 (latch) start: ldi r17,$0f call send call latch here: rjmp here .org $100 clock: sbi portd,7 call delay cbi portd,7 call delay ret .org $120 latch: sbi portd,4 call delay cbi portd,4 ret .org $140 delay: ldi r19,$0f loop2: ldi r20,$ff loop1: nop dec r20 brne loop1 dec r19 brne loop2 ret .org $160 send: ldi r16,$09 ; number of bits to be sent (for some unknown reason 08 sends only 7 bits, so I had to use 9 to send 8 bits clc loop: lsr r17 call clock brcs one cbi portb,0 call delay rjmp go one: sbi portb,0 go: dec r16 brne loop ret
to send 16 bits I modified the following code, but the output is always wrong!
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 .device ATmega328P .org 0 ldi r16,low(ramend) out sph,r16 ldi r16,high(ramend) out sph,r16 sbi ddrb,0 ; arduino pin 8 (serial in) sbi ddrd,7 ;arduino pin7 (clock) sbi ddrd,4 ;arduino pin 4 (latch) ldi r17,$0f ; low byte to be sent call send ldi r17,$f0 ; high byte to be sent call send call latch here: rjmp here .org $100 clock: sbi portd,7 call delay cbi portd,7 call delay ret .org $120 latch: sbi portd,4 call delay cbi portd,4 ret .org $140 delay: ldi r19,$0f loop2: ldi r20,$ff loop1: nop dec r20 brne loop1 dec r19 brne loop2 ret .org $160 send: ldi r16,$09 ; number of bits to be sent (for some unknown reason 08 sends only 7 bits, so I had to use 9 to send 8 bits clc loop: lsr r17 call clock brcs one cbi portb,0 call delay rjmp go one: sbi portb,0 go: dec r16 brne loop ret
Does someone have an idea how to fix this?
Thanks in advance!
Last edited: