Hesam Kamalan
New Member
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,0x6F};
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;
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
}
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,0x6F};
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;
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: