XK-1A Development Board Tutorial
Follow these steps:
2. At the top of your source file, include the header file
stdio.h
.
3. Define an input port named
but1
and initialize it with the value
XS1_PORT_1K
.
4. In the
select
statement, add the following case statement:
case but1 when pinseq(0) :> void:
5. In the body of this case, first call the function
printf
to display the first message;
then input from the button when the value sampled on the pin equals 1; and
then call
printf
again to display the second message.
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 ;
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;
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 :
l e d V a l
< <= 1;
if ( l e d V a l == 0 x10 )
l e d V a l = 1;
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 b u t 1 w h e n p i n s e q (0) : > v o i d :
p r i n t f ( " P r e s s e d \ n " ) ;
b u t 1 w h e n p i n s e q (1) : > v o i d ;
p r i n t f ( " R e l e a s e d \ n " ) ;
X7366A