Created
October 20, 2012 11:12
-
-
Save jgrar/3922999 to your computer and use it in GitHub Desktop.
thinking about changing it up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#define BAUD 19200 | |
#define important_magic_number F_CPU/16/BAUD-1 | |
int32_t main{ | |
begin(important_magic_number); | |
/* need to figure out which ports /registers/pins to use*/ | |
void begin( uint16_t ubrr) { | |
/* set bit transfer rate */ | |
UBRRH = (uint8_t)(ubrr>>8); | |
UBRRL = (uint8_t)ubrr; | |
/*i hope this is right for tx/rx */ | |
UCSRB = (1<<RXEN)|(1<<TXEN); | |
UCSRC = (1<<URSEL)|(3<<UCSZ0); | |
/*frame: 8data one stop bit [?parity?]*/ | |
} | |
void put_char(int8_t data) { | |
/* evidently there is some kind of buffer */ | |
while ( !(UCSRA & (_BV(UDRE))) ); | |
UDR = data; /*---- put! ---*/ | |
} | |
char get_char(void) { | |
/* we learned this in k&r */ | |
while ( !(UCSRA & (_BV(RXC))) ); | |
return UDR; /*---- get! ---*/ | |
} | |
void put_string(int8_t *c) { | |
while (*c) { | |
put_char(*c); | |
c++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment