Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //lab9 pr1
- char acd1,acdh;
- int a,ms=0,i=0;
- int sinus[] = { 127 , 192 , 239 , 255 , 239 , 200 , 154 , 117 , 101 , 107 ,127 , 148 , 154 , 138 , 101 , 55 , 16 , 0 , 16 , 62, 8};
- int sinus1[] = {127,166,202,230,248,254,248,230,202,166,127,88,52,24,6,0,6,24,52,88};
- void init_timer(){
- SREG = 1<<7; // Global Interrupt Enable
- TCCR0 = 0b00001011; //prescaler 32, mod normal de operare
- TCNT0 = 0; //se initializeaza numaratorul cu 0
- //TCCR0 = 0b00001011; //CTC-3,6; Prescaler-0,1,2
- // TCNT0 = 0;
- OCR0 = 125;
- TIMSK |= 0b00000010; //set interrupt OCM
- }
- void init_PWM2(){
- DDRD |= 1<<7; //PD7 – pin de iesire
- TCCR2 = 0b01101001; //FastPWM neinversat, N=1
- }
- void Timer1_OC_ISR() iv IVT_ADDR_TIMER0_COMP //ISR
- {
- if(ms==49){
- OCR2 = sinus[i++]; //factor de umplere = valoarea sinusului
- if(i==20) //resetarea contorului
- i=0;
- ms=0;
- }else ms++;
- }
- void Init_INT0(){
- GICR |= (1<<6); // activarea întreruperii externe INT0
- MCUCR |= 0b00000010; // precizare cã evenimentul va avea
- // loc pe frontul descrescãtor
- SREG |= (1<<7); // activarea globala a întreruperilor
- }
- void main() {
- DDRA =0b00001111;
- DDRC= 0b11111111;
- init_PWM2();
- init_timer();
- //Init_INT0();
- for(;;);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement