Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Tmr0 configuration in Melab PICBASIC PRO

Status
Not open for further replies.

alokdaga

Member level 2
Member level 2
Joined
Feb 10, 2011
Messages
44
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Visit site
Activity points
1,479
Hi,
I am trying to configure Timer0 in PICBASIC PRO. Processor is 16f877a.

I need to generate an interrupt periodically and update seconds counter to ultimately update time.

I don't want to use RTC chip...

Any help in this regards will be highly appreciated..

Regards
 

I think you want to generate an interrupt in every second. For this set timer0 in counter mode with prescaler value 256 to get maximum time delay. Since the micro controller is very fast it will overflow many times within a second depending on your clock speed. You need to calculate how many times the timer will overflow within a second depending on the clock frequency and prescaler value.Then use that value as a count to make exactly one second delay. Example program is given below


Code:
#include <htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif
int COUNT=0;

__CONFIG(FOSC_HS & WDTE_OFF& PWRTE_OFF & BOREN_ON &
LVP_OFF & WRT_OFF & DEBUG_OFF & CPD_OFF & CP_OFF);
void interrupt ISR(void)  //interrupt service routine for timer0 overfloe
{
if(TMR0IF)
{
TMR0IE=0;
TMR0IF=0;
COUNT=COUNT++;
if(COUNT==76)
{
SEC=SEC++;
count=0;
}
}
}


void main(void)
{

OPTION_REG=0X07; //timer0 in counter mode with prescaler 256
GIE=1;           //global interrupt enable
PEIE=1;         //peripheral interrupt enable
TMR0IE=0;   //timer0 interrupt enable
while(1);
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top