mf1364
Full Member level 3

Does any body can give me some information about interrupts of PICs and usage of them especially timers and counters . any PDF , links and so on can be my favorite
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 unsigned char COUNT, PCOUNT; void interrupt(){ COUNT++; if (COUNT = 0) PCOUNT++; PORTB = PCOUNT; INTCON.TMR0IF = 0; } void main(void){ COUNT = 1; CCP1CON = 0; TRISB = 0; CMCON = 7; ADCON1 = 7; OPTION_REG = 0x82; INTCON = 0xA0; PORTB = 0; TMR0 = 0; while (1); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 void interrupt(void) { if(T0IF_bit == 1) { RA5_bit=1; //To see if interrupt is triggered Delay_ms(2000); RA5_bit = 0; T0IF_bit = 0; //You HAVE to clear interrupt flag } } void main() { TMR0 = 0; //Clear timer 0 OPTION_REG = 8; GIE_bit = 1; //Enable Global Interrupt T0IF_bit = 0; T0IE_bit = 1; //Enable TMR0 interrupt PEIE_bit = 1; PORTA = 0; /*set RA0-RA5 low */ TRISA = 0; /*set PORTA to output*/ PORTD = 0; /*set RA0-RA5 low */ TRISD = 0; /*set PORTA to output*/ ADCON1 = 7; //Disable ADC //CMCON = 7; - FOR 16F877A while(1) { RA0_bit=1; Delay_ms(200); RA0_bit=0; Delay_ms(200); } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 unsigned char COUNT, PCOUNT; //declaring variables as 8-bit void interrupt(){ //This is executed when any interrupt occurs COUNT++; //Increment COUNT if (COUNT = 0) //If count overflows to 0 from 255 (since it's an 8-bit register) PCOUNT++; //Increment PCOUNT PORTB = PCOUNT; //Assign the value of PCOUNT to PORTB INTCON.TMR0IF = 0; //Whenever interrupt occurs a flag is set //When a timer overflows the corresponding interrupt flag is raised //When TMR0 overflows and interrupt occurs, TMR0IF is raised //You HAVE to clear the flag } //Return from interrupt void main(void){ //main code COUNT = 1; //initializing count variable by putting 1 in it CCP1CON = 0; //disabling PWM TRISB = 0; //setting PORTB as output CMCON = 7; //disabling comparator ADCON1 = 7; //disabling ADC OPTION_REG = 0x82; //disabling pull-ups and setting TMR0 prescaler to 1:8 INTCON = 0xA0; //INTCON - GIE | PEIE | TMR0IE | INTE | RBIE | TMR0IF | INTF | RBIF // Assigning 0xA0 to INTCON, means setting GIE to 1 and TMR0IE to 1 // Whenever you need to have an interrupt GIE must be set to 1 // Setting TMR0IE to 1 means that TMR0 interrupt is enable PORTB = 0; //Clearing any initial value PORTB holds TMR0 = 0; //Resetting TMR0 so that it holds 0 while (1); // Loop here continuously //Since nothing is performed, the only action will be in the interrupt }
Dont you think this is a peculiar question? You are asking members "what is Your problem" and again asking how to solve it?.Hi every body
Dose any body know , what is my problem ? and how can I solve it ?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 int count = 0; void main () { portb=0; trisb=0; TMR0=0; T0CS_bit=0; T0SE_bit=0; PSA_bit=0; PS0_bit=1; PS1_bit=1; PS2_bit=1; while(1) { while(!T0IF_bit) { T0IF_bit=0; count++; if(count==15) { count=0; portb=~portb;} }}}
[/COLOR]There is something wrong here. Everytime I fix the above appearance, it comes back to this.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 void interrupt() { cnt++; TMR0L = 96; INTCON = 0x20; } void main() { ADCON1 = 0x3F; T0CON = 0xC4; TRISB = 0; PORTB = 0xFF; TMR0L = 96; INTCON = 0xA0; cnt = 0; do { if (cnt == 512) { PORTB = ~PORTB; cnt = 0; } } while(1); }