XK-1A Development Board Tutorial
s e l e c t {
c a s e t m r F w h e n t i m e r a f t e r ( t i m e F ) : > v o i d :
/* add c o d e to r e s p o n d to t i m e o u t */
b r e a k ;
c a s e t m r C w h e n t i m e r a f t e r ( t i m e C ) : > v o i d :
/* add c o d e to r e s p o n d to t i m e o u t */
b r e a k ;
}
}
r e t u r n 0;
}
Before continuing to the next part of this tutorial, create a new project using this
code.
4.2
Examine the application code
Take a look at the application code in the editor. The first statement in
main
inputs
the value of the timer
tmrF
into the variable
timeF
, and the second statement
inputs the value of the timer
tmrC
into the variable
timeC
.
In the
while
loop, the
select
statement waits for the an input on either
tmrF
or
tmrC
to become ready. It then performs the selected input and executes any code
after it up until the keyword
break
.
If more than one input becomes ready at the same time, only one is executed in a
single iteration of the loop; the other input is selected on the following iteration.
4.3
Exercise 1
To complete this part of the tutorial, perform the following tasks:
1. Modify the application so that:
·
On each input from
tmrC
, the program changes which LED is flashed, cycling
between all four LEDs in sequence.
·
On each input from
tmrF
, the program changes the state of the current LED
bewteen on and off.
Show a sample answer..
# 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 1 0 0 0 0 0 0 0
# d e f i n e C Y C L E _ P E R I O D 5 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 ) {
u n s i g n e d l e d O n = 1;
u n s i g n e d l e d V a l = 1;
X7366A