Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1.  
  2. #define F_CPU 9216000UL
  3. #include <util/delay.h>
  4. #include <avr/io.h>
  5. #include <avr/interrupt.h>
  6. #include <stdlib.h>
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. void USART_init(void);
  14. void InitTimer0(void);
  15. void StartTimer0(void);
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. void USART_init(void){
  25. UCSR0A = (1<<U2X0);
  26. UBRR0H = (uint8_t)(4>>8);
  27. UBRR0L = (uint8_t)(4);
  28. UCSR0B = (1<<RXEN0)|(1<<TXEN0);
  29. UCSR0C = (3<<UCSZ00);
  30.  
  31. }
  32.  
  33.  
  34. void InitTimer0(void)
  35. {
  36.  
  37. OCR0A=(119); //119 //9k6Hz
  38. TCCR0A |= (1<<WGM01); //Set CTC mode
  39. }
  40.  
  41.  
  42.  
  43. void StartTimer0(void)
  44. {
  45.  
  46. TCCR0B |=(1<<CS01); //Set Prescaler 64 and start timer //|(1<<CS00)
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. int main(void)
  57. {
  58.  
  59.  
  60. DDRB|=(1<<DDB0);
  61. USART_init();
  62.  
  63. InitTimer0();
  64. sei();
  65.  
  66.  
  67.  
  68.  
  69.  
  70. StartTimer0();
  71.  
  72. TIMSK0 |= (1<<OCIE0A);
  73.  
  74.  
  75. while (1)
  76. {
  77.  
  78. }
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85. ISR (TIMER0_COMPA_vect)
  86. {
  87. static uint8_t cnt; //unser "i"
  88. PORTB =(1<<PB0);
  89.  
  90. cnt++;
  91.  
  92. UDR0=(cnt);
  93.  
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement