View previous topic :: View next topic |
Author |
Message |
nina
Joined: 20 Apr 2007 Posts: 111
|
counter + lcd |
Posted: Wed Jun 27, 2007 5:16 pm |
|
|
I am trying implement this source code but I did not understand how it work.
I want develop a code that count hours and when reach a certain hour a message will be showed on LCD.
This part of the code never is called by main function and how does it count time?
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 76 times
if(--int_count==0) { // per second.
++seconds;
int_count=INTS_PER_SECOND;
}
}
----------------------------------------------------------------------------------
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 76 times
if(--int_count==0) { // per second.
++seconds;
int_count=INTS_PER_SECOND;
}
}
void main() {
BYTE start;
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
do {
printf("Press any key to begin.\n\r");
getc();
start=seconds;
printf("Press any key to stop.\n\r");
getc();
printf("%u seconds.\n\r",seconds-start);
} while (TRUE);
}
----------------------------------------------------------------------------- |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Thu Jun 28, 2007 5:06 am |
|
|
Hello Nina,
This program use 'interrupt' mechanism.
A counter (RTCC) is setup to the line :
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);.
This counter is incremented automatically by the PIC's hardware. With the previous setup, if the external clock is 20Mhz, the counter will overflow every 13mS.
Each time the counter is overflow, the PIC call the function declared after '#int_rtcc' (void clock_isr() in your example.).
The interrupts must be enables with the following lines :
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
There are some other interrupt and generally other counters depending on the PIC used.
dro. _________________ in médio virtus |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
interrupt |
Posted: Thu Jun 28, 2007 9:23 am |
|
|
but when and where the interrupt will be called?
tks
nina |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Thu Jun 28, 2007 10:33 am |
|
|
Hello Nina,
When: every time the counter overflow (about every 13mS in this case).
Where: internally. From the hardware circuitry for control timer and interrupt.
dro. _________________ in médio virtus |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
interrupt |
Posted: Fri Jun 29, 2007 2:14 pm |
|
|
thank you very much inserv
I will try to implement and If appear others doubt I post here.
Thanks again
Nina |
|
|
|