Skip to content

Instantly share code, notes, and snippets.

@JoshAshby
Created June 16, 2009 23:14
Show Gist options
  • Save JoshAshby/130972 to your computer and use it in GitHub Desktop.
Save JoshAshby/130972 to your computer and use it in GitHub Desktop.
just a test of sending data to an atmega
#include <stdint.h>
#include <avr/io.h>
#define USART_BAUD 115200ul
#define USART_UBBR_VALUE ((F_CPU/(USART_BAUD<<4))-1)
void USART_vInit(void)
{
UBRRH = (uint8_t)(USART_UBBR_VALUE>>8);
UBRRL = (uint8_t)USART_UBBR_VALUE;
UCSRC = (0<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
UCSRB = (1<<RXEN)|(1<<TXEN);
}
void USART_vSendByte(uint8_t u8Data)
{
while((UCSRA&(1<<UDRE)) == 0);
UDR = u8Data;
}
uint8_t USART_vReceiveByte()
{
while((UCSRA&(1<<RXC)) == 0);
return UDR;
}
int main(void)
{
uint8_t u8Data;
USART_vInit();
{
u8Data = USART_vReceiveByte();
if (u8Data == "on") {
PORTC = 0xFF;
PORTC = 0x00;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment