Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Question On Setting Timer Interrupt

Status
Not open for further replies.

taengi

New Member
Hi all,
I'm writing a program to use Global Interrupt to run a clock countdown. The other day I flash on PIC16F877 and it works but then when I use PIC16F877A, things seems to go wrong. the clock reset when the second digits reach 8.

When I set the time to [00:07], it still can perform countdown but not more than [00:08] and above, which makes me wonder if I use the interrupt correctly?

Does anybody know about this?

I paste a portion of the related command below:

----------------

__CONFIG(0x3ff1);

#define PERIOD 1000000
#define XTAL 3580000
#define ICLK 16


void interrupt timer0_isr(void) @ 0x10
{
s14++;
T0IF=0;

}

time_edit(x)
{
if(edit==1)
{
if(edit_mov==0)
minute10=x;
//1 RC4=1;
else if(edit_mov==1)
minute=x;
// RC5=1;
else if(edit_mov==2 && x<6)
second10=x;
// RC6=1;
else if(edit_mov==3)
second=x;
// RC7=1;

grid[6]=sevenseg[minute10];
grid[7]=sevenseg[minute];
grid[8]=sevenseg[second10];
grid[9]=sevenseg[second];

dec_delay();
}

return(x);
}

main()
{
PSA=0;
PS0=PS1=PS2=1;
T0CS=0; //select internal clock
T0IE=0; //enable timer interrupt
GIE=0; //enable global interrupts


ADCON1=6; //PORTA as digital
TRISA=0; //all PORTs as output
TRISD=0b00001111;
TRISB=0;
TRISC=0;
TRISE=0;

PORTE=PORTD=PORTC=PORTA=0; //clearing PORTs

//TRISC6=TRISC7=1;

ADDEN=0; //disable address detection
BRGH=1; //high baud rate
SPBRG=23; //set the baud rate
SYNC=0; //asynchronous
SPEN=1; //enable serial port pins
CREN=1; //enable reception
SREN=0; //no effect
TXIE=0; //disable tx interrupts
RCIE=0; //disable rx interrupts
TX9=0; //8 or 9-bit transmission
RX9=0; //8 or 9-bit reception
TXEN=1; //enable the transmitter

if((second!=0)||(second10!=0)||(minute!=0)||(minute10!=0))
{
if(s14>13)
{
s14=0;
second--;

if(second>250)
{
second=9;
second10--;
}
if(second10>250)
{
second10=5;
minute--;
}
if(minute>250)
{
minute=9;
minute10--;
}
if(second>250)
{
minute10=9;
}
grid[6]=sevenseg[minute10];
grid[7]=sevenseg[minute];
grid[8]=sevenseg[second10];
grid[9]=sevenseg[second];
}
}
}

Thanks for your reply.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top