Habs mal mit 38400 Baud getestet funktioniert wunderbar....
Code:
#include <avr/io.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "init.h"
#include "lcd.h"
//SoftUART PINS
#define RXPIN 2
#define RXINT INT0
#define UARTDDR DDRD
#define UARTPIN PIND
#define UARTPORT PORTD
#define T0REL 204
#define T0WAIT 48
char iOut[20];
unsigned char sFlag = 0;
unsigned char bitCnt = 0;
unsigned char udr = 0;
void cfgInt0(void)
{
MCUCR |= (1<<ISC01); //INT0 falling edge
GICR |= (1<<INT0); //INT0 interrupt enable
}
void cfgTimer0(void)
{
TCNT0 = T0WAIT;
TCCR0 = 1; //pre = 1
//TIMSK |=(1<<TOIE0);
}
void cfgSoftUart(void)
{
UARTDDR &=~ (1<<RXPIN); //RX Pin als Input
UARTPORT &=~ (1<<RXPIN); //RX Pin auf 0
cfgInt0(); //Software UART Interrupt
cfgTimer0(); //Software UART Timer
}
int main(void)
{
cfgPorts();
cfgSoftUart();
cfgLcd(LCD_ON_CURSOR_OFF);
lcdCls();
enableInterrupts();
_delay_ms(200);
lcdPrint("Software Uart",1,1);
while(1)
{
itoa(udr,iOut,10);
lcdPrint(" ",1,3);
lcdPrint(iOut,1,3);
itoa(udr,iOut,2);
lcdPrint(iOut,5,3);
_delay_ms(1000);
}
return 0;
}
ISR(INT0_vect)
{
GICR &=~ (1<<INT0);
TCNT0 = T0WAIT;
TCCR0 = 1;
TIFR |= (1<<TOV0);
TIMSK |=(1<<TOIE0);
}
ISR(TIMER0_OVF_vect)
{
TCNT0 = T0REL;
if(sFlag == 0)
{
sFlag = 1;
TCCR0 = 2;
}else
{
if(!(PIND & (1 << PD2)))
{
udr &=~ (1<<bitCnt++);
}else
{
udr |= (1<<bitCnt++);
}
}
if(bitCnt == 8)
{
bitCnt = 0;
sFlag = 0;
TIMSK &=~(1<<TOIE0);
GIFR |= (1<<INTF0);
GICR |= (1<<INT0);
}
}
mal gucken wie sowas mit ctc aussieht.....
noch mal super herzlichen dank !
mfg Fugitivus
Lesezeichen