Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Final Project Graduation

Status
Not open for further replies.

calmo_

Newbie level 3
Joined
May 10, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
Hello,

I'm doing my final project graduation and using a PIC to make a clock with alarm. I'm gonna use too a 4MHZ crystal and an 16x2 LCD. The compiler is mikroC and I need a little help for how to read the oscillation of the crystal and use this in my code. If you have any codes example with comments and circuits with crystals in mikroC I will really appreciate that.

Thanks!
 

horace1

Advanced Member level 5
Joined
Nov 18, 2008
Messages
2,123
Helped
596
Reputation
1,188
Reaction score
573
Trophy points
1,393
Location
Norwich, UK
Activity points
13,071

calmo_

Newbie level 3
Joined
May 10, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
It's a 16F876A. I'm taking a look in your link, very good examples, really going to help.
 

mehtadhaval

Member level 3
Joined
Sep 15, 2010
Messages
56
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,288
Activity points
1,616
I'm doing my final project graduation and using a PIC to make a clock with alarm. I'm gonna use too a 4MHZ crystal and an 16x2 LCD. The compiler is mikroC and I need a little help for how to read the oscillation of the crystal and use this in my code.
If you're making a clock, then you should be using a RTC (Real Time Clock).
 

calmo_

Newbie level 3
Joined
May 10, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
In Proteus I'm using LCD LM020L. I would prefer not to use a RTC, cause I don't need date, the system will be used once a day. I was planning just to use tmr0 with interruption, and there is where my problem starts. I can't figure out how to configure the tmr0 and use interruptions.
 

horace1

Advanced Member level 5
Joined
Nov 18, 2008
Messages
2,123
Helped
596
Reputation
1,188
Reaction score
573
Trophy points
1,393
Location
Norwich, UK
Activity points
13,071
here is a bit of code useing timer 0 of a to interrupt every 10mSeconds using a PIC16F917 on a Microchip PICDEM Mechatronics board
Code:
static volatile int tenMillSecCounter2=0;       // incremented every 10mSec - used for delays

// Timer 0 is programmed to interrupt every 10mSeconds
//  T0 clock is FOSC/4 = 200000
//  with 256 prescaler decrements 2000000/256 times / second
//  to get an interrupt every T mSec the calculation for TMR0 overflow from 0xFF to 0 is
//    count = 255 - T * 2000/256
//    i.e. for 10mSec counter is
#define tenMillSec 177
static void interrupt isr(void)
{
    if (T0IF)                           // A TMR0 interupt occurred
    {
        TMR0=tenMillSec;                // increment counters every 10 mSec
        tenMillSecCounter2++;
     }
    T0IF=0;                             // clear TMR0 interrupt flag
}

// delay for count tenths of a second
void tenthsSecondDelay(int count)
{
    tenMillSecCounter2=0;                         // zero counter
    while( tenMillSecCounter2  < (count*10)) ;    // wait
}
        
// delay for count seconds
void secondDelay(int count)
{
    tenMillSecCounter2=0;                         // zero counter
    while( tenMillSecCounter2  < (count*100)) ;   // wait
}
        
// initalise clock, set port A for digital input, set up timer 0, etc
void systemInitialise(void)
{
        OSCCON=0x70;             // Fosc use oscillator 8MHz
        ANSEL=0;                 // set digital inputs
        // PORTB PULL-UP DISABLED, TMR0 Timer mode Clock Source Select bit FOSC/4,  
        // Prescaler is assigned to the Timer0 module & TMR0 RATE 1:256
        OPTION=0x87;             
        TMR0=tenMillSec;         // initialise timer 0 counter
        T0IE = 1;                // enable interrupt on TMR0 overflow from 0xFF to 0
        GIE = 1;                 // Global interrupt enable
 }
 

arbj

Full Member level 4
Joined
Oct 5, 2008
Messages
238
Helped
31
Reputation
62
Reaction score
20
Trophy points
1,298
Activity points
2,601
use a 32 Khz watch crystal. Its more accurate than the timers in the device.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top