Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.91 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3.  
  4. //unsigned char sine_table[] = { 127, 129, 132, 134, 137, 139, 142, 144, 147, 149, 151, 154, 156, 158, 161, 163, 165, 168, 170, 172, 174, 176, 178, 180, 183, 185, 187, 189, 190, 192, 194, 196, 198, 199, 201, 203, 204, 206, 207, 209, 210, 211, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 225, 226, 226, 226, 227, 227, 227, 227, 227, 227, 227, 227, 227, 226, 226, 226, 225, 225, 224, 223, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214, 213, 211, 210, 209, 207, 206, 204, 203, 201, 199, 198, 196, 194, 192, 190, 189, 187, 185, 183, 180, 178, 176, 174, 172, 170, 168, 165, 163, 161, 158, 156, 154, 151, 149, 147, 144, 142, 139, 137, 134, 132, 129, 127, 125, 122, 120, 117, 115, 112, 110, 107, 105, 103, 100, 98, 96, 93, 91, 89, 86, 84, 82, 80, 78, 76, 74, 71, 69, 67, 65, 64, 62, 60, 58, 56, 55, 53, 51, 50, 48, 47, 45, 44, 43, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 31, 30, 29, 29, 28, 28, 28, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 29, 29, 30, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 47, 48, 50, 51, 53, 55, 56, 58, 60, 62, 64, 65, 67, 69, 71, 74, 76, 78, 80, 82, 84, 86, 89, 91, 93, 96, 98, 100, 103, 105, 107, 110, 112, 115, 117, 120, 122, 125 };
  5. // unsigned char sine_pos = 0;
  6.  
  7. void Init_Timer(void);
  8.  
  9. int main(void)
  10. {
  11.     /* insert your hardware initialization here */
  12.     DDRB |= (1<<PB2);   // OC0A as output
  13.    
  14.     Init_Timer();    
  15.    
  16.     sei();  // enable global interrupts
  17.    
  18.     for(;;){
  19.         /* insert your main loop code here */
  20.     }
  21.     return 0;   /* never reached */
  22. }
  23.  
  24. void Init_Timer(void) {
  25.     TCCR0A |= (1<<COM0A1)| (1<<WGM01)|(1<<WGM00);   // Clear OC0A on Compare Match, set OC0A at TOP; Fast PWM
  26.     TCCR0B = 0x00;
  27.     TCCR0B |= (1<<CS01)|(1<<CS00);  // clkI/O/(No prescaling)
  28.     OCR0A = 0x00;   // Output Compare Register
  29.     TCNT0 = 0x00;   // Reset Timer
  30.    
  31.     TIMSK |= (1<<OCIE0A);
  32. }
  33.  
  34. ISR(TIMER0_COMPA_vect) {
  35.     OCR0A++;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement