Content originally posted in LPCWare by Novato on Wed May 26 12:19:59 MST 2010
Thanks for replying, i upgrade to 3.3.4.201004081702. posting an example to help me, I just need to show me what would be the basic functions to read the ADC and write it into the UART. Thanks
code:
/*****************************************************************************
* Value read from BNC is written to the OLED display (nothing graphical
* yet only value).
*
* Copyright(C) 2009, Embedded Artists AB
* All rights reserved.
*
******************************************************************************/
#include "type.h"
#include "uart.h"
#include "stdio.h"
#include "timer32.h"
#include "i2c.h"
#include "gpio.h"
#include "ssp.h"
#include "adc.h"
#include "oled.h"
static uint8_t buf[10];
static void intToString(int value, uint8_t* pBuf, uint32_t len, uint32_t base)
{
static const char* pAscii = "0123456789abcdefghijklmnopqrstuvwxyz";
int pos = 0;
int tmpValue = value;
// the buffer must not be null and at least have a length of 2 to handle one
// digit and null-terminator
if (pBuf == NULL || len < 2)
{
return;
}
// a valid base cannot be less than 2 or larger than 36
// a base value of 2 means binary representation. A value of 1 would mean only zeros
// a base larger than 36 can only be used if a larger alphabet were used.
if (base < 2 || base > 36)
{
return;
}
// negative value
if (value < 0)
{
tmpValue = -tmpValue;
value = -value;
pBuf[pos++] = '-';
}
// calculate the required length of the buffer
do {
pos++;
tmpValue /= base;
} while(tmpValue > 0);
if (pos > len)
{
// the len parameter is invalid.
return;
}
pBuf[pos] = '\0';
do {
pBuf[--pos] = pAscii[value % base];
value /= base;
} while(value > 0);
return;
}
int main (void)
{
uint32_t val = 0;
GPIOInit();
init_timer32(0, 10);
UARTInit(115200); //---------------------------------here ?
UARTSendString((uint8_t*)"BNC - OLED\r\n"); //------here?
I2CInit( (uint32_t)I2CMASTER, 0 );
SSPInit();
ADCInit( ADC_CLK ); //--------------------------------here ?
oled_init();
oled_clearScreen(OLED_COLOR_WHITE);
oled_putString(1,1, (uint8_t*)"BNC: ", OLED_COLOR_BLACK, OLED_COLOR_WHITE);
while(1) {
/* analog input connected to BNC */
val = ADCRead(5); // ----------------------------------here ??
/* output values to OLED display */
intToString(val, buf, 10, 10);
oled_fillRect((1+6*6),1, 80, 8, OLED_COLOR_WHITE);
oled_putString((1+6*6),1, buf, OLED_COLOR_BLACK, OLED_COLOR_WHITE);
/* delay */
delay32Ms(0, 200);
}
}