User`s guide
23
A.3.2 – The buttons
The buttons are also connected to the P7-connection and can be used in the following manner:
void Init_Buttons(void){
EALLOW;
GpioMuxRegs.GPAMUX.bit.C1TRIP_GPIOA13=0; //Button B3
GpioMuxRegs.GPAMUX.bit.C2TRIP_GPIOA14=0; //Button B2
GpioMuxRegs.GPAMUX.bit.C3TRIP_GPIOA15=0; //Button B1
GpioMuxRegs.GPADIR.bit.GPIOA13=0; //Read
GpioMuxRegs.GPADIR.bit.GPIOA14=0;
GpioMuxRegs.GPADIR.bit.GPIOA15=0;
//Read BUTTONS ON or OFF:
GpioDataRegs.GPADAT.bit.GPIOA13=1; //Pull-up
GpioDataRegs.GPADAT.bit.GPIOA14=1;
GpioDataRegs.GPADAT.bit.GPIOA15=1;
EDIS;
}
Bool ButtonDown(int buttonNbr){
if (buttonNbr==1 && GpioDataRegs.GPADAT.bit.GPIOA15==0) return TRUE;
if (buttonNbr==2 && GpioDataRegs.GPADAT.bit.GPIOA14==0) return TRUE;
if (buttonNbr==3 && GpioDataRegs.GPADAT.bit.GPIOA13==0) return TRUE;
else return FALSE;
}
A.3.3 – Analog inputs and ADC
The 16 analog inputs are marked A1-A8 and B1-B8. However, this is somewhat misleading,
since their function calls are done using ADCINA0-ADCINA7 (from P9) and ADCINB0-
ADCINB7 (P5) respectively.
To understand how the ADC works and how to use it, the sample program
Example_281xAdcSoc (found in SPRC097) is highly recommended. The program measures
at analog inputs ADCINA2 and ADCINA3 (ie, A3 and A4 in our case)
Below is a particularly interesting segment of the code:
// Configure ADC
AdcRegs.ADCMAXCONV.all = 0x0001; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup ADCINA2 as 2nd SEQ1 conv.
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
The first line indicates how many channels that are to be measured, (how much memory to be
freed in order to perform measurements) - if more inputs are desired, the value 0x0001 should
be increased. The next two lines sets which inputs are to be converted. Very logical, replace
0x3 against another value should ADCINA3 not be the preferred input.