Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

zigbee node interfaced with P89V51RD2 8051 micro-controller

Status
Not open for further replies.

mayhem

Newbie level 4
Joined
Mar 15, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,381
Hello,
Copied below is a code that i'm using for my final year project. Since i'm not having the proper components with me i just need someone to check and verify if my code will work properly.
My aim is to send and recieve data over zigbee instantaneously. i've used serial interrupt for receiving. I've interfaced LCD and keypad to 8051. whatever i'll type it'll first be written on LCD and then send over zigbee via serial port. whatever i'll receive will also be displayed on LCD. kindly help me.

// including the headerfiles
#include<stdio.h>
#include<reg51.h>
#include<math.h>
#include<string.h>

// Lcd initial settings
#define ENT_MODE 0x38
#define CURSOR 0x0C
#define CLEAR 0x01
#define POS 0x80
unsigned int y;
unsigned int x;
unsigned char msg[]={"+++"};
unsigned char msg1[]={"ATDL3000"};
unsigned char msg2[]={"ATWR"};
unsigned char msg3[]={"ATCN"};


//Interfacing the keypad with 89c51rd2 microcontroller
sbit ROW0=P2^3;
sbit ROW1=P2^2;
sbit ROW2=P2^1;
sbit ROW3=P2^0;
sbit COL0=P2^7;
sbit COL1=P2^6;
sbit COL2=P2^5;
sbit COL3=P2^4;

// Lcd data and control pins
sbit lcd_EN = P1^0;
sbit lcd_RW = P1^1;
sbit lcd_RS = P1^2;

int kbinput();

// Function Prototyping
void init_lcd(void);
void cmd_lcd(unsigned char);
void write_lcd(unsigned char);
void display_lcd(unsigned char *);
void delay_ms(unsigned int);
void send(unsigned char );
void addr1();
void delay();
//void serrx();
//void zigtx(unsigned char *);
//int encrypt(unsigned int);


unsigned int keypad[4][4]={'1','2','3','4',
'5','6','7','8',
'9','0'};
unsigned char z;
unsigned char r;

// Main program starts here
void main(void)
{



TMOD=0x20; // timer1 in mode2
SCON=0x50; // Serial mode1(8 bit data,1 stop bit, 1 start bit)
IE=0x90; // interrupt enable for serial communication
TH1=0xfd; // settting the baud rate(9600)
TR1=1; // start timer1

init_lcd(); // Initialize lcd
display_lcd("Keypad"); // calling the lcd display function
cmd_lcd(0xc4);
display_lcd("Interfacing"); // calling the lcd display function
delay_ms(60);
cmd_lcd(0x01); // calling the function to clear the lce screen
cmd_lcd(0x80);

x=kbinput();
if(x=='1')
{
addr1();
} // calling the function to move the cursor to beginning



while(1)
{
x=kbinput();
write_lcd(x);
send(x);
}



// y=encrypt(x);
// write_lcd(x ) ; // calling the function to write the data on lcd
//send(x); // callin the function to send the data serially


}


//--------------------------------------------------------------------------
// KEYPAD SCANNING
//--------------------------------------------------------------------------

int kbinput()
{
unsigned int check,rowloc;
while(1)
{
do
{

check=0;
ROW0=0;
ROW1=0;
ROW2=0;
ROW3=0;
}
while(COL3!=1 || COL2!=1 || COL1!=1 || COL0!=1);

while(1)
{
do

{
do
{


delay_ms(20);
}

while(COL3==1 && COL2==1 && COL1==1 && COL0==1);
delay_ms(20);

}

while(COL3==1 && COL2==1 && COL1==1 && COL0==1);
while(1)
{
ROW0=0;
ROW1=1;
ROW2=1;
ROW3=1;
if(COL3!=1 || COL2!=1 || COL1!=1 || COL0!=1)
{
check=1;
rowloc=0;
break;
}
ROW0=1;
ROW1=0;
ROW2=1;
ROW3=1;
if(COL3!=1 || COL2!=1 || COL1!=1 || COL0!=1)
{
check=1;
rowloc=1;
break;
}
ROW0=1;
ROW1=1;
ROW2=0;
ROW3=1;
if(COL3!=1 || COL2!=1 || COL1!=1 || COL0!=1)
{
check=1;
rowloc=2;
break;
}
ROW0=1;
ROW1=1;
ROW2=1;
ROW3=0;
if(COL3!=1 || COL2!=1 || COL1!=1 || COL0!=1)

{
check=1;
rowloc=3;
break;
}
}
if(check==1)
break;
}
if(COL3==0)
return(keypad[rowloc][3]);
else if(COL2==0)
return(keypad[rowloc][2]);
else if(COL1==0)
return(keypad[rowloc][1]);
else
return(keypad[rowloc][0]);
}

}


//-------------------------------------------------------------------------------
// LCD_INTERFACING
//-------------------------------------------------------------------------------

void init_lcd (void)
{
cmd_lcd(ENT_MODE);
cmd_lcd(CURSOR);
cmd_lcd(CLEAR);
cmd_lcd(POS);
}

void write_lcd (unsigned char dat)
{
lcd_EN = 1;
lcd_RW = 0;
lcd_RS = 1;
P0 = dat;
delay_ms (20);
lcd_EN = 0;
lcd_RW = 1;
}

void cmd_lcd(unsigned char dat)
{
lcd_EN = 1;
lcd_RW = 0;
lcd_RS = 0;
P0 = dat;
delay_ms (20);
lcd_EN = 0;
lcd_RW = 1;
}

void display_lcd(unsigned char *s)
{
while(*s)
write_lcd(*s++);
}


//---------------------------------------------------------------------------------
// DELAY CALLING
//----------------------------------------------------------------------------------

void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++)
{
;
}
}
}


//---------------------------------------------------------------------------------
// SERIAL COMMUNICATION
//---------------------------------------------------------------------------------

void send(unsigned char a)
{
SBUF=a;
while(TI==0);
TI=0;
delay_ms(10);
}

void serial0() interrupt 4
{
if (RI)
{
r=SBUF;
write_lcd(r);
RI=0;
}
}

// void serrx()
//{



// while(RI==0);
// write_lcd(SBUF);
// RI=0;

//}

// void zigtx(unsigned char *p)
//{
// while(*p)
// send(*p++);
//}
//---------------------------------------------------------------------------------
//encryption
//---------------------------------------------------------------------------------
//int encrypt(unsigned int p1)
//{
// int p=2,q=11,r,n,e=3,d=1,x,c1;
// n=p*q;
// r=(p-1)*(q-1);
// while(1)
// {
// x=d*e;
// if(x%r==1)
// break;
// else
// d=d+1;
// }
//c1=(p1*p1*p1)%n;

//return(c1);
//}

void addr1()
{
for(z=0;z<3;z++)
{
SBUF=msg[z];
while(TI==0);
TI=0;
}


delay();
delay();
delay();
//delay();
//delay();

SBUF=13;
while(TI==0);
TI=0;

for(z=0;z<8;z++)
{
SBUF=msg1[z];
while(TI==0);
TI=0;
}

SBUF=13;
while(TI==0);
TI=0;


delay();
delay();
//delay();
//delay();



for(z=0;z<4;z++)
{
SBUF=msg2[z];
while(TI==0);
TI=0;
}

SBUF=13;
while(TI==0);
TI=0;




delay();
delay();
//delay();
//delay();



for(z=0;z<4;z++)
{
SBUF=msg3[z];
while(TI==0);
TI=0;
}

SBUF=13;
while(TI==0);
TI=0;

delay();
delay();
return;
//delay();
//delay();

//while(1)
// {
// x=kbinput();
// write_lcd(x);
// send(x);
//serrx();


}


//x:goto x;

//}

void delay()
{
int i,j;
for(i=0;i<=250;i++)
for(j=0;j<=250;j++);
return;
}
 

do you want to see that it compiles properly or not?? or what is your requirement... what do you mean by not having proper tools??? for tesing or compiling?>?????
 

do you want to see that it compiles properly or not?? or what is your requirement... what do you mean by not having proper tools??? for tesing or compiling?>?????

yea, i have compiled it but i'm not able to test it..please do the needful.
 

dear mayhem...
please be clear of the requirement.. test it where??????.. on the hardware??/ then we should have hardware to test it with your configuration. and that is not possible... you can test the program on simulator of keil,,, what is the problem??? but testing on hardware with others will never work out as someone has to build the hardware to test you program.....

Dont think this would be possible by anyone here...................
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top