Guest User

Untitled

a guest
Jun 22nd, 2014
345
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * uart.c
  3. *
  4. * Created: 03-06-2014 PM 04:20:03
  5. * Author: Help
  6. */
  7.  
  8. #define F_CPU 16000000UL
  9. #include
  10. #include
  11. #include
  12.  
  13. void USARTInit(unsigned int ubrr_value)
  14. {
  15. UBRRL = ubrr_value;
  16. UBRRH = (ubrr_value>>8);
  17. UCSRC=(1<<URSEL)|(3<<UCSZ0); //|(1<<USBS)
  18. UCSRB=(1<<RXEN)|(1<<TXEN);
  19. }
  20.  
  21. unsigned char USARTReadChar()
  22. {
  23. while(!(UCSRA & (1<<RXC)));
  24.  
  25. return UDR;
  26. }
  27.  
  28. void USARTWriteChar(char data)
  29. {
  30. while(!(UCSRA & (1<<UDRE)))
  31. ;
  32.  
  33. UDR=data;
  34. }
  35.  
  36. void USARTFlush(void)
  37. {
  38. unsigned char dummy;
  39. while ( UCSRA & (1<<RXC) ) {
  40. dummy = UDR;}
  41. }
  42.  
  43. int main()
  44. {
  45. //char data;
  46. USARTInit(103); //UBRR = 103//9600
  47. _delay_ms(100);
  48. USARTFlush();
  49. while(1)
  50. {
  51.  
  52. // data=USARTReadChar();
  53.  
  54. // USARTWriteChar('[');
  55. USARTWriteChar('a');
  56. _delay_ms(500);
  57. // USARTWriteChar(']');
  58. // while(1);
  59.  
  60. }
  61. }
RAW Paste Data