CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

counter + lcd

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nina



Joined: 20 Apr 2007
Posts: 111

View user's profile Send private message Send e-mail

counter + lcd
PostPosted: Wed Jun 27, 2007 5:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 5:06 am     Reply with quote

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

View user's profile Send private message Send e-mail

interrupt
PostPosted: Thu Jun 28, 2007 9:23 am     Reply with quote

but when and where the interrupt will be called?

tks

nina
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 10:33 am     Reply with quote

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

View user's profile Send private message Send e-mail

interrupt
PostPosted: Fri Jun 29, 2007 2:14 pm     Reply with quote

thank you very much inserv

I will try to implement and If appear others doubt I post here.
Thanks again

Nina
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group