diff options
author | Florian Jung <flo@windfisch.org> | 2014-03-17 17:29:32 +0100 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2014-03-17 17:29:32 +0100 |
commit | 156d616f919be4a9391b7303abc9e3377f9e2365 (patch) | |
tree | c109773d7d66ed5e50928ba4a95720bf53b7cb66 | |
parent | 896cc6755857bf455c19308a30c9237cc469e3de (diff) |
fixed things. does not successfully receive!
-rw-r--r-- | main.c | 57 |
1 files changed, 46 insertions, 11 deletions
@@ -16,7 +16,10 @@ int recv_gc() char* buf_ptr = buffer; asm volatile( + "clr r16 \n" "recv_wait_low_initial_loop: \n" + "inc r16 \n" + "breq timeout \n" "sbic %1, 5 \n" "rjmp recv_wait_low_initial_loop \n" // from low to the start of counting: 6 cycles = 0.5us "nop \n" @@ -106,11 +109,22 @@ void send_gc(char* bytes, int len) "; now send the stop bit and release the line \n" "nop \n nop \n nop \n" OUT0 - WAIT10 - OUT1 - "; done :) \n" + "; instead of WAIT10, do some sensible cleanup work \n" + "clr r16 ; needed below \n" "pop r30 \n" "pop r31 \n" + "nop \n nop \n nop \n nop \n nop \n" + OUT1 + "; done :) \n\n\n" + + + "; now the final thing is to wait for DATA become high again (should be immediately anyway) \n" + "send_final_loop: \n" + "inc r16 \n" + "breq send_timeout \n" + "sbis %0, 5 \n" + "rjmp send_final_loop \n" + "send_timeout: \n" : : "I" (_SFR_IO_ADDR(DDRC)), @@ -129,24 +143,45 @@ int main (void) PORTC=0x00; DDRB=0xFF; + DDRD=0x00; PORTB=0x55; - PORTB=0x55; - int temp=0; + int n_received; + + while(1) + { + temp++; + if (!(PIND & 0x08)) + { + //PORTB=~(1 << ((temp>>9)%6)); + PORTB=~temp; + } + else if (!(PIND & 0x10)) + { + //PORTB=~buffer[4]; + char tmp=0; + for (int i=0;i<8;i++) + tmp|= ( (buffer[i]&0x80)?(1<<i):0 ); + PORTB=~tmp; + } + else if (!(PIND & 0x20)) + { + PORTB=~n_received>>3; + } + else if (!(PIND & 0x40)) + { + PORTB=~0x00; + } - - while(1) - { - temp++; -// PORTB=~(1 << ((temp>>9)%6)); -PORTB=~temp; _delay_ms(1); char foo[] = { 0x40, 0x03, 0x02 }; send_gc(foo, 3); + n_received=recv_gc(); + } |