Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- //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 };
- // unsigned char sine_pos = 0;
- void Init_Timer(void);
- int main(void)
- {
- /* insert your hardware initialization here */
- DDRB |= (1<<PB2); // OC0A as output
- Init_Timer();
- sei(); // enable global interrupts
- for(;;){
- /* insert your main loop code here */
- }
- return 0; /* never reached */
- }
- void Init_Timer(void) {
- TCCR0A |= (1<<COM0A1)| (1<<WGM01)|(1<<WGM00); // Clear OC0A on Compare Match, set OC0A at TOP; Fast PWM
- TCCR0B = 0x00;
- TCCR0B |= (1<<CS01)|(1<<CS00); // clkI/O/(No prescaling)
- OCR0A = 0x00; // Output Compare Register
- TCNT0 = 0x00; // Reset Timer
- TIMSK |= (1<<OCIE0A);
- }
- ISR(TIMER0_COMPA_vect) {
- OCR0A++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement