Getting readings from the Ventricle port and convert the reading into a string

0 views
Skip to first unread message

Qian Keybo (12 B)

unread,
Oct 20, 2011, 4:24:54 PM10/20/11
to 3K04 project grp
The converted string is a number between "0000" and "5000"
representing the voltage reading in units of mV. For example, string
"3450" mean 3.45V or 3450mV.

This posted code includes the initialization and start function calls.
The implementations of these functions are to be found in the original
ADC.c

//First, modified int-string conversion function
/* Convert an integer to string, similar to printf("%0nd", i) */
char *intstr(unsigned int i, char n) {
static char buf[4];
char j;
int k;

/* Get the least significant digit */
buf[3] = '0' + i % 10;
//buf[5] = 0;

/* Get the rest digits */
for (k=2;k>=0;k--) {
i /= 10;
buf[k] = '0' + i % 10;
}
return buf;
}

//how u actually use thes functions
//adc initialization
adc_init();

//start converter
adc_start();

// integer v holds the mV reading
unsigned int v;

//scaling from the original adc reading into the voltage in mV
v = (int)(5000.0 * adc_get() / 65535.0);

//put the char.s into the tx buffer; functioin BUF_ADDSTR is defined
in the orignial adc.c
BUF_ADDSTR(txbuf, intstr(v, 0));

//...do something to send out this buffer

Reply all
Reply to author
Forward
0 new messages