Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #define F_CPU 8000000
  2.  
  3. #include <avr/io.h>
  4. #include <avr/interrupt.h>
  5.  
  6. void initClock()
  7. {
  8. // Setting CLKPSR does not affect the problem (It doesn't work regardless of what this is set to)
  9. // I have tried this before and after setting CLKMSR
  10.  
  11. CCP = 0xD8;
  12. CLKPSR = 0;
  13.  
  14. CCP = 0xD8;
  15. CLKMSR |= (1 << CLKMS1);
  16.  
  17.  
  18.  
  19. }
  20.  
  21. void initPorts()
  22. {
  23.  
  24. DDRB |= (1 << PORTB0); // PB0 = OCR0A
  25. }
  26.  
  27. void initTimer()
  28. {
  29. // I posted this code just in case, this works as expected (but only on the internal oscillator)
  30.  
  31. // We want Compare Output Mode, Clear OC0A on Compare Match
  32. TCCR0A = (1 << COM0A0);
  33.  
  34.  
  35.  
  36.  
  37. // Overflow setting
  38. TIMSK0 |= (1 << OCIE0A);
  39.  
  40. // We will not use a prescaler
  41. // This also starts the timer
  42. TCCR0B = (1 << CS00) | (1 << WGM02);
  43.  
  44. // This is the value at which the timer will restart
  45. OCR0A = 8299;
  46.  
  47. // Set external interrupts
  48. sei();
  49.  
  50.  
  51. }
  52.  
  53.  
  54.  
  55. int main(void)
  56. {
  57. initClock();
  58. initPorts();
  59. initTimer();
  60.  
  61. while(1)
  62. {
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement