📄 t630_blinky.c
字号:
//-----------------------------------------------------------------------------
// T630_Blinky.c
//-----------------------------------------------------------------------------
// Copyright (C) 2007 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program flashes the green LED on the C8051T630 motherboard about
// five times a second using the interrupt handler for Timer2.
//
//
// How To Test:
//
// 1) Download code to the 'T630 daughter board via the 'T630 motherboard
// Note: The daughter board can be the 'T630 Socket Daughter Board, or
// the 'T630 Emulation Daughter Board that contains an 'F336 MCU.
// 2) Ensure that pins 1 and 2 are shorted together on the J9 header
// 3) Run the program. If the LED (D1) on the motherboard flashes, the
// program is working
//
//
// Target: C8051T630, 'T631, 'T632, 'T633, 'T634, 'T635
// Tool chain: Generic
// Command Line: None
//
// Release 1.0
// -Initial Revision (PKC)
// -02 NOV 2007
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <compiler_defs.h> // compiler declarations
#include <C8051T630_defs.h> // SFR declarations
//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
#define SYSCLK 24500000/8 // SYSCLK frequency in Hz
SBIT(LED, SFR_P1, 3); // LED='1' means ON
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void PORT_Init (void);
void Timer2_Init (int counts);
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
void main (void)
{
PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer
// enable)
PORT_Init ();
Timer2_Init (SYSCLK / 12 / 10); // Init Timer2 to generate interrupts
// at a 10 Hz rate.
EA = 1; // Enable global interrupts
while (1) {} // Spin forever
}
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports.
// P1.3 - LED (push-pull output)
//
void PORT_Init (void)
{
P1SKIP = 0x08; // skip the LED pin from crossbar
P1MDOUT |= 0x08; // enable LED as a push-pull output
XBR0 = 0x00; // no digital peripherals selected
XBR1 = 0x40; // Enable crossbar and weak pull-ups
}
//-----------------------------------------------------------------------------
// Timer2_Init
//-----------------------------------------------------------------------------
//
// Configure Timer2 to 16-bit auto-reload and generate an interrupt at
// interval specified by <counts> using SYSCLK/48 as its time base.
//
void Timer2_Init (int counts)
{
TMR2CN = 0x00; // Stop Timer2; Clear TF2;
// use SYSCLK/12 as timebase
CKCON &= ~0x60; // Timer2 clocked based on T2XCLK;
TMR2RL = -counts; // Init reload values
TMR2 = 0xffff; // set to reload immediately
ET2 = 1; // enable Timer2 interrupts
TR2 = 1; // start Timer2
}
//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Timer2_ISR
//-----------------------------------------------------------------------------
// This routine changes the state of the LED whenever Timer2 overflows.
//
INTERRUPT(Timer2_ISR, INTERRUPT_TIMER2)
{
TF2H = 0; // clear Timer2 interrupt flag
LED = ~LED; // change state of LED
}
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -