
XK-1A Development Board Tutorial
·
After the button is released, output a value 0 to this channel.
3. In the function
flashLEDs4bitPort
:
·
Add a parameter declaration
chanend c
.
·
Add a variable declaration
unsigned direction
and initialize to 0.
·
Add a case to the
select
statement that inputs from channel
c
, and in the
body of this case update the variable
direction
.
·
Modify the body of the case statement that inputs from
tmrC
so that the next
LED flashed depends upon the value of the variable
direction
.
Show a sample answer..
# i n c l u d e < xs1 . h >
# i n c l u d e < s t d i o . 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 ;
in p o r t b u t 1 = X S 1 _ P O R T _ 1 K ;
v o i d f l a s h L E D s 4 b i t P o r t ( out p o r t led , c h a n e n d c , int f l a s h P e r i o d , int
>
c y c l e P e r i o d ) {
/* C o d e to f l a s h 4 L E D s c o n n e c t e d to a 4 - bit p o r t in a c y c l e */
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;
u n s i g n e d d i r e c t i o n = 0;
t i m e r tmrF , t m r C ;
u n s i g n e d timeF , t i m e C ;
t m r F : > t i m e F ;
t m r C : > t i m e C ;
w h i l e (1) {
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 :
l e d O n = ! l e d O n ;
if ( l e d O n )
led <: l e d V a l ;
e l s e
led <: 0;
t i m e F += F L A S H _ P E R I O D ;
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 :
if ( d i r e c t i o n ) {
l e d V a l
< <= 1;
if ( l e d V a l == 0 b 1 0 0 0 0 )
l e d V a l = 1;
}
e l s e {
l e d V a l
> >= 1;
if ( l e d V a l == 0)
l e d V a l = 0 b 1 0 0 0 ;
}
t i m e C += C Y C L E _ P E R I O D ;
b r e a k ;
c a s e c : > int x :
X7366A