swapan
Full Member level 4
Hi guys,
While developing a simple code of blinking LED with PIC16F722A it is seen that TMR2 is not working. I have observed the code with Oshonsoft PIC simulator where TMR2 does not increase whereas program counter advances as usual. Interestingly, it is also seen that TMR0 is also not increases. Please see the code and suggest where is the bug. Incidentally, it is to state that configuration bit MCLR is disabled. The same code when developed with PIC16F72, works properly.
sbit LED at RB2_Bit;
unsigned char state;
void interrupt() {
if (TMR2IF_Bit == 1) {
if (state == 1) {
LED = 1;
state = 2;
TMR2IF_Bit = 0;
}
else {
LED = 0;
state = 1;
TMR2IF_Bit = 0;
}
}
void main() {
TRISA = 0x2F;
TRISB = 0x21;
TRISC = 0x2;
OPTION_REG =0x80;
ANSELB= 0x21;
INTCON = 0xC0;
T2CON = 0x5A;
TMR2ON_bit = 1;
TMR2IE_bit = 1;
PR2 = 128;
LED = 1;
state = 2;
while (1);
}
While developing a simple code of blinking LED with PIC16F722A it is seen that TMR2 is not working. I have observed the code with Oshonsoft PIC simulator where TMR2 does not increase whereas program counter advances as usual. Interestingly, it is also seen that TMR0 is also not increases. Please see the code and suggest where is the bug. Incidentally, it is to state that configuration bit MCLR is disabled. The same code when developed with PIC16F72, works properly.
sbit LED at RB2_Bit;
unsigned char state;
void interrupt() {
if (TMR2IF_Bit == 1) {
if (state == 1) {
LED = 1;
state = 2;
TMR2IF_Bit = 0;
}
else {
LED = 0;
state = 1;
TMR2IF_Bit = 0;
}
}
void main() {
TRISA = 0x2F;
TRISB = 0x21;
TRISC = 0x2;
OPTION_REG =0x80;
ANSELB= 0x21;
INTCON = 0xC0;
T2CON = 0x5A;
TMR2ON_bit = 1;
TMR2IE_bit = 1;
PR2 = 128;
LED = 1;
state = 2;
while (1);
}
Last edited: