In C(like unix/systems) I need to write the code for void bitslider. #include <s
ID: 672934 • Letter: I
Question
In C(like unix/systems) I need to write the code for void bitslider.
#include <stdlib.h>
#include <stdio.h>
const char ZERO = 0;
const char ONE = 1;
#define TWO (ONE + ONE)
const char NIBBLE_WITH_ALL_BITS_ON = 0xF;
const int BYTE_WITH_ALL_BITS_ON = 0xFF;
const int NUM_BITS_PER_NIBBLE = 4;
const int NUM_BITS_PER_BYTE = 8;
const int NUM_NIBBLES_PER_BYTE = 2;
const int NUM_BYTES_PER_WORD = sizeof(int);
#define NUM_NIBBLES_PER_WORD (NUM_BYTES_PER_WORD * NUM_NIBBLES_PER_BYTE)
#define NUM_BITS_PER_WORD (NUM_BYTES_PER_WORD * NUM_BITS_PER_BYTE)
#define NUM_BITS_PER_WORD_MINUS_ONE (NUM_BITS_PER_WORD - ONE)
#define NUM_BITS_PER_BYTE_PAIR (NUM_BITS_PER_BYTE * 2)
const int TEXT_LEN = 64;
Explanation / Answer
#include "msp430.h"
#include "CTS_Layer.h"
void data_frame_send(void); // TouchPro Data Logger
void UART_send_byte(unsigned char data2send);
#define Custom_Counts //If defined custom counts displayed else Slider position
#define DataHead 0x55AA //Data Header
#ifdef Custom_Counts
#define SENSOR_NUM 4 //Defines the number of data channels for display in TouchPro tool
//for delta counts
#else
#define SENSOR_NUM 1 //Defines the 1 data channel for display for slider position
#endif
uint16_t count[SENSOR_NUM];
#define TXD BIT1 //P1.1 Bit banging this pin to send out the data to TouchPro tool
#define TXDOUT P1OUT //Output value
#define TXDDIR P1DIR //P1.1
unsigned int SliderPos = 0;
/*
* Function sets up the DCO and SMCLK clocks and GPIO ports
*/
void config(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set range to 1MHz
DCOCTL = CALDCO_1MHZ; // Set DCO to 1MHz. Declared in msp430g2553.h
BCSCTL2 |= DIVS_2; // Set SMCLK Divider to 4 (250kHz). Sets scan time to 2.048ms. (512/250KHz)
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
P1DIR = 0xFF;
P1OUT = 0; //Output is low
P2DIR = 0xFF; //Set P2 registers as the traces for the 3 elements are connected to Port 2 pins
P2SEL = 0;
P2SEL2 = 0;
P2OUT = 0;
TXDOUT = 0; //For touchPro tool
TXDOUT |= TXD; //For TouchPro tool
TXDDIR |= TXD; //For touchPro tool
}
/*
* Function initializes and updates baseline for slider and monitors the changes in capacitance to
* determine touch or no touch.determine touch or no touch.
*
*/
void main(void) {
#ifndef Custom_Counts
static const int channelIndex =0;
#endif
config();
TI_CAPT_Init_Baseline(&slider);
TI_CAPT_Update_Baseline(&slider,10);
while(1) {
#ifdef Custom_Counts
TI_CAPT_Custom(&slider, count); //Changes in capacitance
#else
SliderPos = TI_CAPT_Slider(&slider); //Get the slider position
if (SliderPos == 0XFFFF){
SliderPos = 80; //Set upper limit for no touch. Based on points set in structure.c
}
count[channelIndex] = SliderPos;
#endif
data_frame_send(); //Send data
}
}
#include "structure.h"
const struct Element sliderElement1 = {
.inputPxselRegister = (unsigned char *)&P2SEL,
.inputPxsel2Register = (unsigned char *)&P2SEL2,
.inputBits = BIT1,
.maxResponse = 97,
.threshold = 15
};
const struct Element sliderElement2 = {
.inputPxselRegister = (unsigned char *)&P2SEL,
.inputPxsel2Register = (unsigned char *)&P2SEL2,
.inputBits = BIT2,
.maxResponse = 78,
.threshold = 15
};
const struct Element sliderElement3 = {
.inputPxselRegister = (unsigned char *)&P2SEL,
.inputPxsel2Register = (unsigned char *)&P2SEL2,
.inputBits = BIT3,
.maxResponse = 84,
.threshold = 15
};
const struct Element sliderElement4 = {
.inputPxselRegister = (unsigned char *)&P2SEL,
.inputPxsel2Register = (unsigned char *)&P2SEL2,
.inputBits = BIT4,
.maxResponse = 89,
.threshold = 15
};
//*** Sensor *******************************************************/
// This defines the grouping of sensors, the method to measure change in
// capacitance, and the function of the group
const struct Sensor slider =
{
.halDefinition = RO_PINOSC_TA0_WDTp,
.numElements = 4, //total number of elements that make up the slider
.baseOffset = 0, //is a cumulative count of the number of elements
//defined in this application.
// Pointer to elements
.arrayPtr[0] = &sliderElement1, // point to first element
.arrayPtr[1] = &sliderElement2, // point to first element
.arrayPtr[2] = &sliderElement3, // point to first element
.arrayPtr[3] = &sliderElement4, // point to first element
// Timer Information
.measGateSource= GATE_WDT_SMCLK, // 0->SMCLK, 1-> ACLK
.accumulationCycles= WDTp_GATE_512, //512
.points = 32,
.sensorThreshold = 1
};