Download Getting Started with dsPIC30F Digital Signal Controllers User's Guide

Transcript
Getting Started with dsPIC30F Digital Signal Controllers
A.2
FLASH LED WITH dsPIC30F6014.c
/******************************************************************************
*
Software License Agreement
*
*
*
*
The software supplied herewith by Microchip Technology Incorporated
*
*
(the "Company") for its dsPIC controller is intended and supplied to
*
*
you, the Company's customer, for use solely and exclusively on
*
*
Microchip dsPIC products. The software is owned by the Company and/or
*
*
its supplier, and is protected under applicable copyright laws. All
*
*
rights are reserved. Any use in violation of the foregoing
*
*
restrictions may subject the user to criminal sanctions under
*
*
applicable laws, as well as to civil liability for the breach of the
*
*
terms and conditions of this license.
*
*
*
*
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
*
*
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO,
*
*
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
*
*
PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY
*
*
CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL
*
*
DAMAGES, FOR ANY REASON WHATSOEVER.
*
*
*
*******************************************************************************
*
*
Use Timer 1 to flash LED1 when switch SW1 is not pressed
*
and flash LED2 when switch SW1 is pressed
*
******************************************************************************/
#include "p30F6014.h"
//----------------------------------------------------------------------------//Configuration bits
_FOSC(CSW_FSCM_OFF & XT_PLL4);
_FWDT(WDT_OFF);
_FBORPOR(PBOR_OFF & BORV_27 & PWRT_16 & MCLR_EN);
_FGS(CODE_PROT_OFF);
//----------------------------------------------------------------------------//Program Specific Constants
#define
FCY
7372800
//Instruction cycle rate (Osc x PLL / 4)
//=============================================================================
//Main routine
//Set up LEDs and timer, wait for timer periods, and flash one of the two LEDs
int main(void)
{
LATD = 0xffff;
TRISD = 0xfff0;
LATDbits.LATD0 = 0;
//Initialize LED pin data to off state
//Set LED pins (PORTD bits 0-3) as outputs
//Turn LED1 on (active low)
T1CON = 0;
TMR1 = 0;
PR1 = FCY/256/5;
T1CON = 0x8030;
//Turn off Timer1 and clear settings
//Start Timer1 at zero
//Set period register value for 1/5 second
//Turn on Timer1 with 1:256 prescaler
while(1)
//Loop forever
DS70151A-page 102
© 2005 Microchip Technology Inc.