Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. //lab9 pr1
  2.  
  3. char acd1,acdh;
  4. int a,ms=0,i=0;
  5. int sinus[] = { 127 , 192 , 239 , 255 , 239 , 200 , 154 , 117 , 101 , 107 ,127 , 148 , 154 , 138 , 101 , 55 , 16 , 0 , 16 , 62, 8};
  6. int sinus1[] = {127,166,202,230,248,254,248,230,202,166,127,88,52,24,6,0,6,24,52,88};
  7.  
  8. void init_timer(){
  9. SREG = 1<<7; // Global Interrupt Enable
  10. TCCR0 = 0b00001011; //prescaler 32, mod normal de operare
  11. TCNT0 = 0; //se initializeaza numaratorul cu 0
  12. //TCCR0 = 0b00001011; //CTC-3,6; Prescaler-0,1,2
  13. // TCNT0 = 0;
  14. OCR0 = 125;
  15. TIMSK |= 0b00000010; //set interrupt OCM
  16. }
  17.  
  18. void init_PWM2(){
  19. DDRD |= 1<<7; //PD7 – pin de iesire
  20. TCCR2 = 0b01101001; //FastPWM neinversat, N=1
  21. }
  22.  
  23.  
  24. void Timer1_OC_ISR() iv IVT_ADDR_TIMER0_COMP //ISR
  25. {
  26. if(ms==49){
  27. OCR2 = sinus[i++]; //factor de umplere = valoarea sinusului
  28. if(i==20) //resetarea contorului
  29. i=0;
  30. ms=0;
  31. }else ms++;
  32. }
  33.  
  34. void Init_INT0(){
  35. GICR |= (1<<6); // activarea întreruperii externe INT0
  36. MCUCR |= 0b00000010; // precizare cã evenimentul va avea
  37. // loc pe frontul descrescãtor
  38. SREG |= (1<<7); // activarea globala a întreruperilor
  39. }
  40.  
  41. void main() {
  42. DDRA =0b00001111;
  43. DDRC= 0b11111111;
  44. init_PWM2();
  45. init_timer();
  46. //Init_INT0();
  47.  
  48. for(;;);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement