SW006012 Microchip Technology, SW006012 Datasheet - Page 92

C COMPILER FOR DSPIC30F FAMILY

SW006012

Manufacturer Part Number
SW006012
Description
C COMPILER FOR DSPIC30F FAMILY
Manufacturer
Microchip Technology
Type
MPLAB® C30 Compilerr
Series
PIC24 & DsPICr
Datasheets

Specifications of SW006012

Supported Families
PIC24, DsPIC30F And DsPIC33F
Core Architecture
PIC, DsPIC
Kit Contents
Software And Docs
Mcu Supported Families
PIC24 MCUs And DsPIC DSCs
Tool Type
Compiler
Processor Series
PIC24, dsPIC
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
dsPIC30F
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
MPLAB
DS51284F-page 86
®
C30 User’s Guide
EXAMPLE 6-1:
/*
** Sample Real Time Clock for dsPIC
**
**
**
*/
#include <p30f6014.h>
/* Timer1 period for 1 ms with FOSC = 20 MHz */
#define TMR1_PERIOD 0x1388
struct clockType
void reset_clock(void)
void
{
} volatile RTclock;
{
}
{ static int sticks=0;
}
unsigned int timer;
unsigned int ticks;
unsigned int seconds;
RTclock.timer = 0;
RTclock.ticks = 0;
RTclock.seconds = 0;
TMR1 = 0;
PR1 = TMR1_PERIOD;
T1CONbits.TCS = 0;
IPC0bits.T1IP = 4;
IFS0bits.T1IF = 0;
IEC0bits.T1IE = 1;
SRbits.IPL = 3;
T1CONbits.TON = 1;
Uses Timer1, TCY clock timer mode
and interrupt on period match
if (RTclock.timer > 0)
RTclock.ticks++;
if (sticks++ > 1000)
{
sticks = 0;
RTclock.seconds++;
}
IFS0bits.T1IF = 0;
return;
__
attribute
RTclock.timer -= 1;
__
SAMPLE REAL-TIME CLOCK
((
__
interrupt
/* countdown timer, milliseconds */
/* absolute time, milliseconds
/* absolute time, seconds
/* clear software registers
/* clear timer1 register
/* set period1 register
/* set internal clock source */
/* set priority level
/* clear interrupt flag
/* enable interrupts
/* enable CPU priority levels 4-7*/
/* start the timer*/
/* if countdown timer is active */
/*
/* increment ticks counter
/*
/*
/* clear interrupt flag
/* if time to rollover
__
decrement it
clear seconds ticks
and increment seconds
)) _T1Interrupt(void)
© 2007 Microchip Technology Inc.
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

Related parts for SW006012