Force Sensor ARM Code
/*
* Project name:
FORCE SENSOR
Copyright
(c) Researchdesignlab.com
* Description:
* Test configuration:
MCU: LPC2129
Dev.Board: LPC2129 mini
Oscillator: 12 MHz
Software: Keil uVision3
*/
#include
#include"lpc21xx.h" // header file
#include
//*******************************************************************
void SEND_CMD_2_LCD(unsigned char); // function protoype
void SEND_2_LCD(unsigned char *, unsigned char);
void DISPLAY_ON_LCD(unsigned char DATA);
void DELAY(void);
void LCD_DELAY(void);
unsigned int LCD_RS=0X01000000; // pin declerations
unsigned int LCD_EN=0X02000000;
unsigned int LCD_DATA_LINES=0X00003C00;
unsigned char buf[16] = {0};
//*******************************************************************
int main()
{
unsigned char LCD_CMD[]={0X20,0X28,0X0f,0X06,0X01,0X80},COUNT; // LCD commands
unsigned int adc_value1;
IODIR0|=LCD_DATA_LINES;
IODIR1=0X03300000;
for(COUNT=0;COUNT<6;COUNT++)
SEND_CMD_2_LCD(LCD_CMD[COUNT]); // LCD INIT function call
DELAY();
DELAY();
while(1)
{
IOPIN0=0X000000D0; //op pin
DELAY();
ADCR=0x01240001;
while((ADDR&0X80000000)!=0X80000000);
adc_value1=(ADDR>>6)&0X000003FF;
DELAY();
sprintf((char *)buf, "x=:%d ", adc_value1);
SEND_CMD_2_LCD(0X01);
SEND_2_LCD(" FORCE ",0X80);
SEND_2_LCD(buf,0XC6); // checking sensor1
DELAY();
}
}
void DELAY(void)
{
unsigned int X=800000;
while(X--);
}
void LCD_DELAY(void)
{
unsigned int X=20000; // delay calculation subroutine
while(X--);
}
void SEND_CMD_2_LCD(unsigned char DATA)
{
unsigned int TEMP; // LCD command write function
IOCLR0=LCD_DATA_LINES;
TEMP=DATA;
TEMP=((TEMP&0xf0)<<6);
IOCLR1=LCD_RS;
IOSET0=TEMP;
IOSET1=LCD_EN;
LCD_DELAY();
LCD_DELAY();
IOCLR1=LCD_EN;
IOCLR0=LCD_DATA_LINES;
LCD_DELAY();
TEMP=DATA;
TEMP=((TEMP&0x0f)<<10);
IOCLR1=LCD_RS;
IOSET0=TEMP;
IOSET1=LCD_EN;
LCD_DELAY();
LCD_DELAY();
IOCLR1=LCD_EN;
IOCLR0=LCD_DATA_LINES;
}
void DISPLAY_ON_LCD(unsigned char DATA)
{
unsigned int TEMP;
IOCLR0=LCD_DATA_LINES;
TEMP=DATA; //LCD data write function
TEMP=((TEMP&0xf0)<<6);
IOSET1=LCD_RS;
IOSET0=TEMP;
IOSET1=LCD_EN;
LCD_DELAY();
LCD_DELAY();
IOCLR1=LCD_EN;
IOCLR0=LCD_DATA_LINES;
LCD_DELAY();
TEMP=DATA;
TEMP=((TEMP&0x0f)<<10);
IOSET1=LCD_RS;
IOSET0=TEMP;
IOSET1=LCD_EN;
LCD_DELAY();
LCD_DELAY();
IOCLR1=LCD_EN;
IOCLR0=LCD_DATA_LINES;
}
void SEND_2_LCD(unsigned char *PTR, unsigned char POS)
{
SEND_CMD_2_LCD(POS);
while(*PTR)
{ // sending the data to LCD data line function
DISPLAY_ON_LCD(*PTR);
PTR++;
}
LCD_DELAY();
LCD_DELAY();
}

