Viss konfiguration syns inte som tex att DDRD för klockpinnen är 0 som deafult, dvs ingång som den ska vara eftersom tangentbordet genererar klockan. I interruptet så finns mottaget data i UDR0, färdigt att placeras i bufferten.
Kod: Markera allt
void usart_init()
{
//Pull-up RXD and XCK
PORTD |= _BV(PD0) | _BV(PD4);
//Recieve complete interrupt and recive enable
UCSR0B |= _BV(RXCIE0) | _BV(RXEN0);
//Synchronous USART, odd parity, 8-bit
UCSR0C |= _BV(UMSEL00) | _BV(UPM01) | _BV(UPM00) |
_BV(UCSZ01) | _BV(UCSZ00);
//Init buffer
head = tail = buffer;
sei();
}
//Interruptrutinen
ISR(USART_RX_vect)
{
//Recieved data in UDR0
if(bytes < 8) {
*head = UDR0;
if(head == buffer + 7)
head = buffer;
else
head++;
bytes++;
}
}
Urklipp ur listfilen. Visste inte om jag skulle ta med den eller inte. Endast usart_init.
Kod: Markera allt
void usart_init()
{
22a: 8b b1 in r24, 0x0b ; 11
22c: 81 61 ori r24, 0x11 ; 17
22e: 8b b9 out 0x0b, r24 ; 11
PORTD |= _BV(PD0) | _BV(PD4);
UCSR0B |= _BV(RXCIE0) | _BV(RXEN0);
230: e1 ec ldi r30, 0xC1 ; 193
232: f0 e0 ldi r31, 0x00 ; 0
234: 80 81 ld r24, Z
236: 80 69 ori r24, 0x90 ; 144
238: 80 83 st Z, r24
UCSR0C |= _BV(UMSEL00) | _BV(UPM01) | _BV(UPM00) |
23a: e2 ec ldi r30, 0xC2 ; 194
23c: f0 e0 ldi r31, 0x00 ; 0
23e: 80 81 ld r24, Z
240: 86 67 ori r24, 0x76 ; 118
242: 80 83 st Z, r24
_BV(UCSZ01) | _BV(UCSZ00);
head = tail = buffer;
244: 85 e1 ldi r24, 0x15 ; 21
246: 91 e0 ldi r25, 0x01 ; 1
248: 90 93 20 01 sts 0x0120, r25
24c: 80 93 1f 01 sts 0x011F, r24
250: 90 93 1e 01 sts 0x011E, r25
254: 80 93 1d 01 sts 0x011D, r24
sei();
258: 78 94 sei
25a: 08 95 ret