to make it easier to understand i include the source code. part of it
i did connect the connection to rx-tx and tx - rx
- CODE: SELECT_ALL_CODE
//Include files
#include <p18f4520.h>
#include <delays.h>
//Configuratio
//_CONFIG(0x3F32); // would like to know know what am i suppose to include for this part?
//Define
#define D PORTDbits.RD0 //define port d 0 as DATA In pin
#define A0 PORTDbits.RD3 //define port d 3 as selector pin 0
#define A1 PORTDbits.RD4 //define port d 4 as selector pin 1
#define A2 PORTDbits.RD5 //define port d 5 as selector pin 2
#define LE PORTDbits.RD1 //define port d 1 as active low enable pin
#define BRGH TXSTAbits.BRGH
#define TXEN TXSTAbits.TXEN
#define CREN RCSTAbits.CREN
#define SPEN RCSTAbits.SPEN
#define TXIF PIR1bits.TXIF
#define RCIF PIR1bits.RCIF
#define TX9 TXSTAbits.TX9
#define SYNC TXSTAbits.SYNC
//Function Prototype
void init (void);
void display (unsigned char c);
unsigned char receive (void);
void string (rom char *ptr);
unsigned char a;
rom char *msg1 = " Wellcome";
rom char *msg2 = "Bluetooth Control Panel Board";
rom char *msg3 = " Control Menu";
rom char *msg4 = " 1/2 : Lighting";
rom char *msg5 = " 3/4 : Fan";
rom char *msg6 = " 5/6 : Output 1";
rom char *msg7 = " 7/8 : Output 2";
rom char *msg8 = " on/off";
rom char *mag9 = "Please insert your option";
void string (rom char *ptr) //display string
{
while(*ptr)
{
display(*ptr);
ptr++;
}
}
void init (void) //initialize sub routine
{
TX9=0; //setting to 8 bit transmission
SYNC=0; //asynchronous mode
SPBRG=10; //setting baud rate as 115200 baud
BRGH=1; //High speed baud rate select
TXEN=1; //Transmit enabled
CREN=1; //Enables continuous receive
SPEN=1; //Serial port enabled (configures RC7 and RC6 pins as serial port pins)
TRISD=0; //define ports as output
// TRISCbits.TRISC6=1; //output to KC21
// TRISCbits.TRISC7=1; //input from KC21
// TXSTA=0b00100100;
// RCSTA=0b10010000;
// SPBRG=10;
}
void display (unsigned char c) //subroutine to display text on screen
{
//TXSTA=0x24;
//SPBRG=10;
//TXEN=1;
//SPEN=1;
while (!TXIF);
TXREG=c;
}
unsigned char receive (void) //subroutine to receive command from pc
{
//RCSTA=0x90;
//SPBRG=10;
while (!RCIF);
a=RCREG;
return a;
}
//Main Function
void main (void)
{
init();
while(1)//wait for "ok" to be entered
{
a=receive();
if (a=='o')
{
a = receive();
if(a=='k')
break;
}
}
//Text will be display on Hyperterminal after 'ok' is entered
string(msg1);
display(0x0a); //next line
display(0x0d);
string(msg2);
display(0x0a);
display(0x0d);
string(msg3);
display(0x0a);
display(0x0d);
string(msg4);
display(0x0a);
display(0x0d);
string(msg5);
display(0x0a);
display(0x0d);
string(msg6);
display(0x0a);
display(0x0d);