XK-1A Development Board Tutorial
3. On your XK-1A, verify that all four LEDs are illuminated, and then click the
Terminate
button () to stop your application running.
3
Flash an LED
This part of the tutorial shows you how to flash an LED at a fixed rate, using an XC
timer and an input statement.
3.1
Create a new project
3.2
Add the application code
The program below flashes a single LED on an XK-1A.
# i n c l u d e < xs1 . h >
# d e f i n e F L A S H _ P E R I O D 2 0 0 0 0 0 0 0
out p o r t led = X S 1 _ P O R T _ 4 F ;
int m a i n ( v o i d ) {
t i m e r tmr ;
u n s i g n e d i s O n = 1;
u n s i g n e d t ;
tmr : > t ;
w h i l e (1) {
led <: i s O n ;
t += F L A S H _ P E R I O D ;
tmr w h e n t i m e r a f t e r ( t ) : > v o i d ;
i s O n = ! i s O n ;
}
r e t u r n 0;
}
Copy and paste the code into your project, and then choose
File
·
Save
() to save
your changes to file.
3.3
Examine the code
Take a look at the code in the editor. The declaration
timer tmr;
declares a variable named
tmr
, and allocates an available hardware timer. The L1
provides 10 timers, which can be used to determine when an event happens, or to
delay execution until a particular time. Each timer contains a 32-bit counter that is
incremented at 100MHz and whose value can be input at any time.
The statement
tmr :> t;
X7366A