BT atmel code
/*
* Project name:
BLUETOOTH MODULE
* Copyright
(c) Researchdesignlab.com
* Description:
* Test configuration:
MCU: AT89S52
Dev.Board: 8051
Oscillator: 11.0592 MHz
Software: Keil uVision3
*/
#include<reg51.h>
#define LCD_PORT P2 // LCD D0-D7 PINS connected P2
sbit rs=P3^5; // LCD RS PIN connected P3.5
sbit en=P3^7; // LCD EN PIN connected P3.7
sbit D7=P2^7;
sbit rw=P3^6; // LCD RW PIN connected P3.6
void busy(); //LCD busy
void CMD_WRT(unsigned char); //To write the commands to the LCD
void DATA_WRT(unsigned char); //To write the data to the LCD
void LCD_WRT(unsigned char *);
void DELAY();
void TRANSMIT(unsigned char *);
void transmit_byte(unsigned char );
unsigned char SCI_ReceiveByte( void );
void main()
{
unsigned char CMD[]={0x38,0x01,0x0f,0x06,0x80},TEMP1,i,RX;
for(i=0;i<5;i++)
{
TEMP1=CMD[i]; //write the commands to the LCD
CMD_WRT(TEMP1);
}
TMOD=0X20; //TIMER 1 , MODE 2
TH1=0XFD; //9600 BAURD RATE //SERAIL INIT
SCON=0X50;
TR1=1; //TIMER1 ON
DELAY();
DELAY();
DELAY(); //DELAY
DELAY();
TRANSMIT("MC 1 "); // trasmit the data to BLUETOOTH
while(1)
{
RX=SCI_ReceiveByte(); // RECIVING DATA from BLUETOOTH AND DISPLAY ON LCD
DATA_WRT(RX);
}
}
void DELAY()
{ //delay of 3ms
unsigned int X=800000;
while(X--);
}
void busy()
{
D7=1;
rs=0; //cmd mode
rw=1; //read
while(D7!=0) //wait till LCD is ready
{
en=0;
en=1; // low to high latch
}
}
void CMD_WRT(unsigned char val)
{
busy();
LCD_PORT=val; //write cmd to P2
rs=0; //cmd mode
rw=0; //write
en=1;
en=0; //high to low latch
}
void DATA_WRT(unsigned char ch)
{
busy();
LCD_PORT = ch; //write cmd to P2
rs=1; //data mode
rw=0; //write
en=1;
en=0; //high to low latch
}
void transmit_byte(unsigned char byte) // TRANSIMITT SERIAL DATA
{
SBUF=byte; //TRANSMIT DATA FROM BYTE TO SBUF
while(!TI); // WAIT TILL DTA GET TRANSMITTED
TI=0;
}
void TRANSMIT(unsigned char *string)
{
while(*string)
transmit_byte(*string++);
}
unsigned char SCI_ReceiveByte( void )
{ // RECIVING SERIAL DATA
unsigned char byte;
// RI=0;
while(RI!=1); // WAIT TILL RI IS HIGH
byte = SBUF; //RECIVE DATA FROM SBUF TO BYTE
RI=0;
return byte; // RETURN THE DATA
}