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.

Real Time Clock With PIC18F4550 using MikroC compiler

Status
Not open for further replies.

vinhove

Newbie level 4
Joined
Feb 11, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,336
Hello !!!

I am using PIC18F4550 for generating a real time clock by using timer0 interrupt. I have the following code which compiles successfully on MikroC compiler but on testing on proteus it is not giving any results. I have tried to change a lot of things and I have tried to research on how to solve this problem but am still facing the same problem. So can someone help me with this...

unsigned int counter;
unsigned int sec;
unsigned int mins;
unsigned int hour;
unsigned int day;
void interrupt() {

if(INTCON.TMR0IF) { // if timer 0 overflow
counter++ ;
if(counter==3907) { // one second has elapsed
counter = 0 ;
sec++ ;
if(sec == 60) { // one minute has alapsed
sec = 0 ;
mins++ ;
if(mins == 60) { // one hour has elapsed
mins = 0 ;
hour++ ;
if(hour == 24) { // one day has elapsed
hour = 0 ;
day++;
if(day ==8) { // beginning a new week
day =1;

}
}
}
}
}
}
INTCON.TMR0IF = 0 ;
TMR0L=0xFF;
T0CON.TMR0ON=1; //START TIMER
}//
void main() {
INTCON = 0xE0;
T0CON = 0x48;
INTCON2 = 0x04;
RCON = 0x80;
TMR0L=0xFF;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISD = 0x00;
PORTD = 0x00;
T0CON.TMR0ON=1; //START TIMER
while(1)
{

if (sec==20)
{
PORTD = 0xFF;
}
}

}
 

Re: Reat Time Clock With PIC18F4550 using MikroC compiler

Did you post it in the Mikroc forum?
 

unsigned int counter;
unsigned int sec;
unsigned int mins;
unsigned int hour;
unsigned int day;
void interrupt() {

if(INTCON.TMR0IF) { // if timer 0 overflow
counter++ ;
if(counter==3907) { // one second has elapsed
counter = 0 ;
sec++ ;
if(sec == 60) { // one minute has alapsed
sec = 0 ;
mins++ ;
if(mins == 60) { // one hour has elapsed
mins = 0 ;
hour++ ;
if(hour == 24) { // one day has elapsed
hour = 0 ;
day++;
if(day ==8) { // beginning a new week
day =1;

}
}
}
}
}
}
INTCON.TMR0IF = 0 ;
TMR0L=0xFF;
T0CON.TMR0ON=1; //START TIMER <<< ey???
}//
void main()
{
INTCON = 0xE0;
T0CON = 0x48;
INTCON2 = 0x04;
RCON = 0x80;
TMR0L=0xFF;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISD = 0x00;
PORTD = 0x00;
T0CON.TMR0ON=1; //START TIMER
do {
if (sec==20)
{
PORTD = 0xFF;
}
}while(1);

}

you need to start the timers in main

not in isr's
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top