Moin, schönen Valentinstag!
Es geht!!! Nach viel grübeln ist mir aufgefallen, daß ich, wenn ich keinen RS232-Treiber nehme, ich die Signale schon Softwaremäßig invertieren muß.... (Jaa, ich weiß, man sollte nicht direkt mit TTL an RS232, aber meine kleinen Picaxe machen das auch alle und es funktioniert) Die Routine funktioniert, selbst wenn ich den ATTiny26 mit dem internen PLL auf 16MHz takte (lt. Datenblatt S.32), sauber bei 115200 baud. Mit Treiber muß man halt wieder 'sbi' und 'cbi' vertauschen. Im Moment ist der Port,Pin und die Verzögerung (siehe AppNote AVR305) hardcoded, da werd ich noch dran feilen. Außerdem bin ich mir nicht sicher, ob das mit dem Inline-ASM-Operanden so richtig ist, auch wenn's funktioniert. Vielleicht kann da mal jemand drübergucken, der sich mit sowas auskennt.
Hier mal mein Code:
Code:
#include <avr/io.h>
#include <util/delay.h>
void init_uart()
{
DDRA |= (1<<0);
PORTA = 0;
}
void txd(uint8_t data)
{
uint8_t bitcnt;
uint8_t delay;
__asm__(
" ldi %A0,0x0a\n\t" //;1+8+sb (sb is # of stop bits)
" com %A1\n\t" //;Inverte everything
" sec\n\t" //;Start bit
"0: brcc 1f\n\t" //;If carry set
" sbi 0x1b,0\n\t" //;send a '0'
" rjmp 2f\n\t" //;else
"1: cbi 0x1b,0\n\t" //;send a '1'
" nop\n\t"
"2: rcall 3f\n\t" //;One bit delay
" rcall 3f\n\t"
" lsr %A1\n\t" //;Get next bit
" dec %A0\n\t" //;If not all bit sent
" brne 0b\n\t" //;send next
//;else
" ret\n\t" //; return
"3: ldi %C0,19\n\t"
"4: dec %C0\n\t"
" brne 4b\n\t"
" ret\n\t"
::"r"(bitcnt),"r"(data),"r"(delay));
}
int main(void)
{
uint8_t x,y;
init_uart();
{
for (y=0;y<124;y++)
{
for (x=0;x<128;x++)
{
txd(y);
//_delay_ms(4000);
}
}
}
return 0;
}
Lesezeichen