Usage And Implementation - XMOS SliceKit GPIO Gpio Example Applications

Table of Contents

Advertisement

SliceKit GPIO Example Applications
This function returns:
Returns linear interpolated Temperature value
int read_adc_value()
Read ADC value using I2C.
This function returns:
Returns ADC value

3.1.3 Usage and Implementation

The port declaration for the LEDs, Buttons and I2C are declared as below. LEDs and Buttons use 4
bit ports and I2C uses 1 bit port for SCL(I2c Clock) and SDA (I2C data).
on stdcore [ CORE_NUM ]: out port p_led = XS1_PORT_4A ;
on stdcore [ CORE_NUM ]: port p_PORT_BUT_1 = XS1_PORT_4C ;
on stdcore [ CORE_NUM ]: struct r_i2c i2cOne = {
};
The app_manager API writes the configuration settings information to the ADC as shows below.
i 2 c _ m a s t e r _ w r i t e _ r e g (0 x28 , 0 x00 , data , 1 , i2cOne ) ; // Write configuration information to
ADC
The select statement in the app_manager API selects one of the two cases in it, checks if there is
IO event or timer event. This statement monitors both the events and executes which ever event
is occurred first. The select statement in the application is listed below. The statement checks if
there is button press or not. If there is button press then it looks if the button state is same even
after 200msec. If the buton state is same then it recognises as an valid push.
select
{
case button = > p_PORT_BUT_1 when pinsneq ( button_press_1 ) : > button_press_1 : //
checks if any button is pressed
button =0;
t : > time ;
break ;
case ! button = > t when timerafter ( time + debounce_time ) : > void : // waits for 20 ms and
checks if the same button is pressed or not
p_PORT_BUT_1 : > butt on_press_2 ;
if ( but ton_pr ess_1 == but ton_press_2 )
if ( but ton_pr ess_1 == B U TT O N_ P RE S S_ V AL U E ) // Button 1 is pressed
{
REV A
XS1_PORT_1F ,
XS1_PORT_1B ,
1000
printstrln ( " Button 1 Pressed " ) ;
p_led <:( led_value ) ;
led_value = led_value < <1;
led_value |=0 x01 ;
7/24

Advertisement

Table of Contents
loading

This manual is also suitable for:

Slicekit

Table of Contents