tahir4awan
Full Member level 4

I wrote two programs just to check how PIC timer works with internal and external clock. But when I check both my program on ISIS Proteus 7 they are working abnormal. Please also check my code that, are they written correctly. Note that are not for specific purpose I just want to check timers.
For internal clock
===========================================================
int count = 0;
void main()
{
TRISB = 0x00;
TMR0 = 0;
GIE_bit = 1;
PEIE_bit = 1;
T0IE_bit = 1;
T0IF_bit = 0;
T0CS_bit = 1;
T0SE_bit = 0;
PSA_bit = 0;
PS0_bit = 1;
PS1_bit = 1;
PS2_bit = 1;
while(1){
if(!T0IF_bit) {
count++;
if(count==15)
PORTB = 0x01;
else if(count==30)
PORTB = 0x02;
else if(count==45)
PORTB = 0x03;
else if(count==60)
PORTB = 0x04;
}
}
}
===========================================================
and for external clock. There is also a problem in ISIS Proteus that with external clock it is only working with clock speed given in PIC option. Is there any option to disable internal clock so we can input pulse from RA4 pin.
===========================================================
void main()
{
ANSEL = 0;
ANSELH = 0;
TRISB = 0x00;
TRISA.RA4 = 1;
TMR0 = 0;
GIE_bit = 0;
PEIE_bit = 0;
T0IE_bit = 0;
T0IF_bit = 0;
T0CS_bit = 0;
T0SE_bit = 0;
PSA_bit = 0;
PS0_bit = 0;
PS1_bit = 0;
PS2_bit = 0;
while(1){
if(TMR0==5) {
PORTB = 0xFF;
else if(TMR0==10)
PORTB = 0xAF;
else if(TMR0==15)
PORTB = 0xAA;
else if(TMR0==20)
PORTB = 0xCC;
}
}
}
===========================================================
For internal clock
===========================================================
int count = 0;
void main()
{
TRISB = 0x00;
TMR0 = 0;
GIE_bit = 1;
PEIE_bit = 1;
T0IE_bit = 1;
T0IF_bit = 0;
T0CS_bit = 1;
T0SE_bit = 0;
PSA_bit = 0;
PS0_bit = 1;
PS1_bit = 1;
PS2_bit = 1;
while(1){
if(!T0IF_bit) {
count++;
if(count==15)
PORTB = 0x01;
else if(count==30)
PORTB = 0x02;
else if(count==45)
PORTB = 0x03;
else if(count==60)
PORTB = 0x04;
}
}
}
===========================================================
and for external clock. There is also a problem in ISIS Proteus that with external clock it is only working with clock speed given in PIC option. Is there any option to disable internal clock so we can input pulse from RA4 pin.
===========================================================
void main()
{
ANSEL = 0;
ANSELH = 0;
TRISB = 0x00;
TRISA.RA4 = 1;
TMR0 = 0;
GIE_bit = 0;
PEIE_bit = 0;
T0IE_bit = 0;
T0IF_bit = 0;
T0CS_bit = 0;
T0SE_bit = 0;
PSA_bit = 0;
PS0_bit = 0;
PS1_bit = 0;
PS2_bit = 0;
while(1){
if(TMR0==5) {
PORTB = 0xFF;
else if(TMR0==10)
PORTB = 0xAF;
else if(TMR0==15)
PORTB = 0xAA;
else if(TMR0==20)
PORTB = 0xCC;
}
}
}
===========================================================