- Sat Sep 27, 2008 10:57 pm
#56080
Hi, I'm trying to create a software usart for a project and to learn how it works. I've looked up some timing diagrams on the net and coded a little routine. I use WinAVR C, Mega168 at 8Mhz. Here's what I have:
FF 11111111
FF 11111111
81 10000001
82 10000010
80 10000000
84 10000100
88 10001000
90 10010000
A0 10100000
When I call DebugTransmit2 with these values:
0xFF, 0xFF, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40
I got 104uSec from 8e6/9600 cycles at 1/8e6 per cycle = 104usec
I'm not sure what I'm doing wrong.
Brainwav.
Code: Select all
I get this out of it:void DebugTransmit2( unsigned char Data )
{
int i;
unsigned char Byte;
setBit( PORTB, 0 );
_delay_us( 104 );
clearBit( PORTB, 0 );
_delay_us( 104 );
Byte = Data;
for ( i = 0; i < 8; i++ ) //Shift out the data
{
if ( Byte & 1 ) //Shift out the LSB
setBit( PORTB, 0 );
else
clearBit( PORTB, 0 );
Byte = Byte >> 1; //Shift down the data for the next bit
_delay_us( 104 ); //Delay to the next bit
}
setBit( PORTB, 0 );
_delay_us( 104 );
_delay_us( 104 );
}
FF 11111111
FF 11111111
81 10000001
82 10000010
80 10000000
84 10000100
88 10001000
90 10010000
A0 10100000
When I call DebugTransmit2 with these values:
0xFF, 0xFF, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40
I got 104uSec from 8e6/9600 cycles at 1/8e6 per cycle = 104usec
I'm not sure what I'm doing wrong.
Brainwav.