Getting Started

(lily) #1

Chapter 6: C Functions and Program Structures


if(string[count-1] == '\n')// HyperTerminal string ends wi
{
string[count-2] = '\0'; //convert to a string


th \r\n

parseInput(string);
string[0] = '\0';
count = 0;

}

ar isCharAvailable()
the RX0 bit of the USART Status and Control Register
ate a char has been received?
SR0A & (0x80)) ) return 1;
else return 0;

UDR0 = data;

&0x40) );

}
else if(count > 64)
{
count = 0;
string[0] = '\0';
sendString("Error - received > 64 characters");


}


}
return 0;
}


ch
{
// Does
// indic
if ( (UC


}


char receiveChar()
{
// Return the char in the UDR0 register
return UDR0;
}


void sendChar(char data)
{
int i = 0;


// To send data with the USART put the data in the USART data register


// Check to see if the global interrupts are enabled
if(SREG & 0x80)
{
// Wait until the byte is sent or we count out
while ( !(UCSR0A&0x40) && (i<10000) )
{
i++;
}
}
else // Wait until the byte is sent
while( !(UCSR0A


// Clear the TXCflag
UCSR0A=UCSR0A|0x40;
}

Free download pdf