ToolStick Led Blink 프로그램은 다음과 같다. 프로그램코드는 제공되는 CD안에 들어있으며, 역시 인터넷으로 Silabs 홈페이지에서 검색하여 사용이 가능하다. 컴파일은 Keil C51을 사용하였다.
--- 프로그램코드 ---
//----------------------------------------------------------------------------- // BLINK_LED.c //----------------------------------------------------------------------------- // Copyright (C) 2005 Silicon Laboratories, Inc. // // AUTH: PB // DATE: 20 JUN 05 // // This program flashes the red and green LEDs (P0.2 & P0.3) on the tools demo // board about 2.5 times a second using the interrupt handler for Timer2. // // Target: C8051F300 (Tools Demo Board) // // Tool chain: KEIL Eval 'c' //
//----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- #include <c8051f300.h> // SFR declarations
//----------------------------------------------------------------------------- // Global CONSTANTS //----------------------------------------------------------------------------- sbit REDLED = P0^2; // REDLED='1' means ON sbit GRNLED = P0^3; // GRNLED='1' means ON
//----------------------------------------------------------------------------- // MAIN Routine //----------------------------------------------------------------------------- void main (void) {
PCA0MD &= ~0x40; // WDTE = 0 (disable Watchdog Timer) SYSCLK_Init (); // Initialize System Clock PORT_Init (); // Initialize Crossbar and GPIO REDLED = 1; // Turn REDLED ON GRNLED = 0; // Turn GRNLED OFF
Timer2_Init (); // Init Timer2 to generate // interrupts at a 5Hz rate.
EA = 1; // Enable global interrupts
while (1) { // Spin forever } }
//----------------------------------------------------------------------------- // SYSCLK_Init //----------------------------------------------------------------------------- // // This routine initializes the system clock to use the internal oscillator // 24.5MHz / 8 as its clock source. Also enables missing clock detector reset. // void SYSCLK_Init (void) { OSCICN = 0x04; // Set SYSCLK as Int Osc (24.5 MHz)/8 RSTSRC = 0x04; // Enable missing clock detector }
//----------------------------------------------------------------------------- // Interrupt Service Routines //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- // Timer2_ISR //----------------------------------------------------------------------------- // This routine inverts the state of the LED pins whenever Timer2 overflows. // void Timer2_ISR (void) interrupt 5 { static int T2_Overflow_Count = 0; // Counter for Timer2 interrupts