![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
hi' I wrote program for 0-99 counter. but i don't know why interrupt not work. TMR0 never incremented and then interrupt not accure. tell me, where is my problem, and how can i run Timer0, please? my compiler is microC. C code: #define uchar unsigned char //-----Function Prototype-------- void inith(); void first(); void second(); //----Variable Dicleration------- uchar num[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6 F}; uchar j, hop; // j for second function and hop for switch //----Interrupt routin----------- void interrupt() { TMR0=0; INTCON=0xa0; // clear timer0 interrupt flag bit if(j!=0) ~hop; // function hopping (first and second function) } //------------------------------- //----Program Starts Here-------- void main(){ inith(); for( ;; ){ if(!hop) first(); if(hop) second(); } } void first(){ uchar i, d; portb.F2=0; portb.F6=1; for(i=0;i<10;i++){ portd=num[i]; if(i==9){ j++; if(j>9) j=0; } for(d=0;d<100;d++){ // 1's Delay delay_ms(10); if(hop) break; } if(hop) break; } } void second(){ uchar i; portb.F6=0; portb.F2=1; portd=num[j]; for(i=0;i<5;i++){ // 1's Delay delay_ms(10); if(hop) break; } } void inith(){ portb=0x00; trisb=0x01; portd=0x00; trisd=0x00; hop=0; TMR0=0; OPTION_REG=0x01; // PSA = Timer , 1:4 INTCON=0xa0 ; // Global Interrupt enable } Last edited by Hesam Kamalan; 29th October 2007 at 12:09 PM. | |
| |
| | #2 |
|
It has been a while since I did C and not yet on a PIC but it looks like your interrupt routine makes TMR0=0 on every interrupt so it will never increment.
__________________ C:\WHUT ? Beware the asterisk * | |
| |
| | #3 |
|
thank you ClydeCrashKop, but TMR0 is a register and i can write it. when i change contents of this (for example TMR0=96; ), i have this problem too. | |
| |
| | #4 |
|
I don't do C either, but TMR0 is the poorest of the available timers, and has a LOT of restrictions.
| |
| |
| | #5 |
|
yes you are right Nigel. this program is correct when i use Timer1. timer1 has a TMR1ON for control of stop and start. but timer0 has not this control bit and i don't know how can i run timer0. | |
| |
| | #6 |
|
Which PIC are you using? Why not use Timer1 if it works?
| |
| |
| | #7 |
|
Thx blueroomelectronics. I used PIC 16F877A. becuse i can not run and work with this timer. and i didn't see anybody can work with this timer. | |
| |
| | #8 |
|
Timer0 works fine, it's a simple 8bit timer. Timer 1 & 2 are part of the 16F877A. Timer0 is always running. Tough to turn off actually , use the MPLAB simulator and set the T0CS to FOSC/4
Last edited by blueroomelectronics; 29th October 2007 at 03:34 PM. | |
| |
|
| Tags |
| pic, timer0 |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Timer0 Prescale | lord loh. | Micro Controllers | 10 | 8th October 2008 06:14 PM |
| High ADC sampling rate PIC, 18F needed? | bananasiong | Micro Controllers | 24 | 28th October 2007 01:13 PM |
| Four PIC with One LCD.. | meera83 | Micro Controllers | 13 | 20th September 2007 07:40 AM |
| 16F877 Timer0 Interrupt Affecting ADC | sebana | Micro Controllers | 13 | 12th September 2007 10:43 AM |
| Using the Timer0 module | wonbinbk | Micro Controllers | 2 | 14th September 2004 07:06 AM |