BT arm code
/*
* Project name:
BLUETOOTH MODULE
* Copyright
(c) Researchdesignlab.com
* Description:
* Test configuration:
MCU: LPC2129
Dev.Board: LPC2129 mini
Oscillator: 12 MHz
Software: Keil uVision3
*/
#include<stdio.h>
#include"lpc21xx.h" // header file
#include<string.h>
//*******************************************************************
void SEND_CMD_2_LCD(unsigned char); // function protoype
void SEND_2_LCD(unsigned char *, unsigned char);
void DISPLAY_ON_LCD(unsigned char DATA);
unsigned char RECIVE_DATA(void);
void TRANSMIT_UART0_BYTE(unsigned char P);
void TRANSMIT_UART0(unsigned char *P);
#define sw4 0x00010000
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 RX;
//*******************************************************************
int main()
{
unsigned char LCD_CMD[]={0X20,0X28,0X0f,0X06,0X01,0X80},COUNT,i; // LCD commands
IODIR0|=LCD_DATA_LINES;
IODIR1=0X03300000;
for(COUNT=0;COUNT<6;COUNT++)
SEND_CMD_2_LCD(LCD_CMD[COUNT]); // LCD INIT function call
PINSEL0 = 0X00050000;
PINSEL1=0X15400000; // UART INIT
U1LCR = 0X83; // 8bit data setting
U1DLL = 0X61;
U1LCR = 0X03; // 9600 baud rate setting
U1FCR = 0X01; // FIFO enable
PINSEL0|=0X00000005;
U0LCR=0X83;
U0DLL=0X61;
U0DLM=0X00;
U0LCR=0X03;
DELAY();
DELAY();
DELAY();
TRANSMIT_UART0("MC 1"); //TRANSMITT DATA TO BLUE TOOTH
while(1)
{
RX=RECIVE_DATA(); // RECIVING BLUE TOOTH DATA DISPLAY ON LCD
DISPLAY_ON_LCD(RX);
i++;
}
}
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();
}
void TRANSMIT_UART0(unsigned char *P)
{
while(*P){
U0THR=*P;
while(!(U0LSR&0X20));
P++;}
}
void TRANSMIT_UART0_BYTE(unsigned char P)
{
U0THR=P;
while(!(U0LSR&0X20));
}
unsigned char RECIVE_DATA(void)
{
while(!(U0LSR&0X01));
RX=U0RBR;
return(RX);
}