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.

Problem with communication between PC and LED

Status
Not open for further replies.

ermtariq

Newbie level 5
Joined
Apr 1, 2008
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,446
communication problem

Hi all,

I am working on led display project,
i am using AT89S53(8051) for programming(keil C) . from last three days i
am facing serious problem with communication. I want to communicate PC to LED
there is another IC on board provided me, that is MAX1487 and there are only two wire conneting(RXD,TXD) to it. iam connectint only two wire from com port.

problem is that i am not able to read or write data from SBUF even keil debugger is going write but there is no hardware response. my progamme setting for this is as follows:

void main(void)
{
SCON=0X50;
ET2=1;
TCLK=1;
RCLK=1;
C_T2=0;
RCAP2H=0XFF; //baud rate 9600
RCAP2L=0XB2;
TR2=1;
TR1=1;
PS=0;
ES=1;
EA=1;
RI=0;
SM2=0;
}

void rxd(void) interrupt 4
{
unsigned char UART_DATA;

if(RI==1)
{
RI=0;
TR2=0;
UART_DATA=SBUF;
}
}

is this write???????
SBUF is not working well.
is there any programmatic error plese help me to right it

I have additional code for displaying charcter on led in function main() as well as in rxd(). i am sending you only the settings.

is there any requirment of reg52.h ,reg53.h,regs58.h i have included first two in code.

there is no right response from led. I think there is communication error from PC to MAX1487 or MAX1487 to microcontroller!!!!!!!

plese help me if you have idea of MAX1487 pins connection with microcontroller.
i am using 9600,N,8,1.
 

Re: communication problem

Hi,
Max 1487 is an RS 485 IC, I suppose what you need to connect to PC is a MAX 232, RS232 IC.
Regards,
Laktronics
 

communication problem

Could u please tell me if u are able to do a loop back to check if the port is working properly. There are times when SBUF in the simulator do not show output, but the actual transmission in reality works.

Please come back after checking the port of the computer, then i will suggest you further. Let us go step by step, so that we dont miss anything in debugging the problem.
 

Re: communication problem

Hi all,

Yes my friend , comm port is working well, what i did, I joined both receiver and transmitter cable and it returns me whatever i send by VB utility. it is not working with SBUF.

what is problem with MAX1487,is interfacing with 8051 is not right???

why SBUF is not put value in variable ??????????????

plese answer all queries

Thanks and regard
BY Mohd.Tariq
 

Re: communication problem

please do this simple exercise

void main(void)
{
unsigned char UART_DATA; //a[10]= {"my friend"};
SCON=0X50;
ET2=1;
TCLK=1;
RCLK=1;
C_T2=0;
RCAP2H=0XFF; //baud rate 9600
RCAP2L=0XB2;
TR2=1;
TR1=1;
PS=0;
ES=1;
EA=1;
RI=0;
SM2=0;
while(1)
{
if (!RI); // or use if(RI==0);
{
UART_DATA=SBUF;
RI = 0;
//TR2 = 0;
//Insert transmit program here
SBUF = UART_DATA;
if(!TI); //or if (TI==0);
{
TI=0;
}

}
}
}


PLease check output on simulator, open serial window / hyperterminal window and type some character and see if they come in SBUF. if u cannot make out then write a Transmit routine below the as shown. and check the output. if u get it now either on serial window in simulator or on hyperterminal then we can use VB code to send the data.

thanks and bye
shivaram
Also specify which controller in specific u r using?
 

Re: communication problem

Hi,

Thanks for your coopration..................

I tried your code, in beggining it work well SBUF is read and write successful in keil debugger. but i cannt understand why are you checking RI==0 because it will perform only once and does not go in checking again and also it is not guarnteed that it will give hardware respons when condition true.

after all I loaded your code in microcontroller(8051) W77E58 and there is no output.

I have made four changes in your code :-(I numbered them)

void main(void)
{
unsigned char UART_DATA; //a[10]= {"my friend"};
Initialize(); /// this function is to initialize led (change=1)
SCON=0X50;
ET2=1;
TCLK=1;
RCLK=1;
C_T2=0;
RCAP2H=0XFF; //baud rate 9600
RCAP2L=0XB2;
TR2=1;
TR1=1;
PS=0;
ES=1;
EA=1;
RI=0;
SM2=0;

LoadString("AB",2,0); //This is for load string what ever we want to display on led
// this function take string to load(here AB) ,its lenth(here
//2),and language type(here 0 for english) (change=2)
while(1)
{

if (RI==1); // or use if(RI==0); //I change RI==0 to RI==1 φ(see sign
//below)
//(change=3)
{
UART_DATA=SBUF;
RI=0;



LoadString(&(UART_DATA),1,0);

SBUF = UART_DATA;

if(!TI); //or if (TI==0);
{
TI=0;
}

}
LoopDisplay();//this function is used to load pattern of charcters and display them
//change=4
}

}


φ Here keil debugger is also stopped and also I lost control form debugging.
from this line i cant move in debugging process.

in beginning(without change) I input value from serial window and SBUF is giving me right values. But after once it does not going again.

I want that at least once it is going without any input , and when it come again to if condition i will input from serial window for this purpose it should go agian and agian in if conditon .

I hope I success to make you clear what happening.......

REGARDS
By TARIQ(Mumbai)
 

Re: communication problem

Hey Tariq,
Your question why I make RI =0; you know it is serial interrupt flag. When TI or RI is 0; that means that the communication is going either the bits are transmitted or received in the bus. when 8th bit is transmitted then TI or RI flag is made high automatically by the controller. u should never make it high. u need to just start the condition and check for flag to become 1. when it is 1, it means that the transmission or reception is over and controller will not process any further data. then again make it zero, controller will handle the 2 byte of data. so put this in a loop.

just see this simple program u will understand the concept without any doubt. PLease run this and see the output in serial window after running the program. PLease dont debug step by step it will not work. Also go to target in project window and right click select option for target, in that change the crystal from 24 MHz to 11.0592. save and then run the program.
NOTE: please comment the transmit part and run and see the buffer and uncomment and run it and see the output. You will get the idea.

If u r not in a hurry then we can go step by step which will help u in learning how to debug the problem
// program

#include<reg51.h>
#include<stdio.h>
main()
{
unsigned char i;
char a[8];//= {"shivaram"};
TMOD = 0X20;
SCON = 0x50;
TH1 = 0xFD;
TR1 = 1;
while(1)
{
for (i=0;i<=7;i++)
{

while(RI == 0);
a= SBUF;
RI=0;

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



}
}
}

try this program
 

Re: communication problem

Hi,

It's Hard Luck.......................

I am not asking about RI=0,but I am asking about RI==0 . which you are "comparing" in "if" condition in previous mail,but now you are using :
while(RI==0)

My question is concern to this point, :?:why you comparing RI==0 , because when we send something by serial port RI automatic converted in 1.(as you admitted)

SO it will never allow to enter in this loop(while RI==0).

clear me changes in setting after void????????????

your code is working well it is also giving me output in seril window what I input.
I set osc as you suggested.

what is difference between reg51.h & reg52.h & reg58.h

Ofcourse I am not in hurry:D:D

Thanks
Tariq
 

Re: communication problem

Hey tariq;

i think u did not get my point . Ok no problem.



while(RI==0);

comparing RI with 0

a semi colon at the end means that stay in the same line till the condition is true.

it is something like

loop: JNB RI, loop

no bit means the value in RI is 0 till RI =0 i.e no bit jump in the loop and once RI becomes 1 come out of the loop.

while RI == 0; means the same . Recieve interrupt means that interrupt the receiver. when should it interrupt, 0 after coming out of loop then again it starts the reception of new data. for receiveing new data RI should be 0.
port will become 1 only if u send some data otherwise controller has to wait till it gets data, and controller does not know when the data will come so u have to make RI 0 and make the controller to wait for a data. If u need to send the data again then again the RI flag must be 0. if it is 1 it will not receive the data.

Since it is going long i will post this and continue in the next post.



I will suggest u one thing comment only TI part in code. when u run the program please open serial window from view tab. then put break point at while (RI == 0);
and RI=0; in the next line
and run the program. the control will come and stop till u type a single character
in the serial window. In the peripheral window open serial port where u can see the serial comm registers. observe the RI flag. once u type, u can see RI flag becomes high. Till that time RI =0 i.e. it is unchecked. when RI becomes high after u type the program and run the program without resetting. u can see the control will come out of while loop and execute RI=0. then in the peripheral window u can see RI =0. and the loop is repeated.

Added after 23 minutes:

Hi tariq,
please forgive me if u find my explanaition lengthy and boring. I am used to give such lengthy explaination whenever i give corporate training or clear doubts of my students.

regarding the reg51.h, reg52.h and any other header files.

Tariq again i want u to do few things for me.
1. I think I am giving u many assignmants rather than giving u solution.
if u see the keil window in the right hand side u have a project window. u can see the C file u have added. it will have a plus mark indicating that u can expand it. just expand it u can see startup.s expand that and see how the 8051 is configured.
2. Get the cursor on the reg header file and right click on it and select open regXX.h. It will show u the memory allocation for all the registers,port, interrupts, etc. So u can u know the features and its mem location info in it.

please send ur ph number. Any week ends we can talk to clear ur doubts

thanks and regds
Shivaram
 

Re: communication problem

Hi shivaram,

I couldnt mail you because of off.

your concept ( while(RI==0); ) is cleared , I want to tell you that everthing is OK. serial window is giving right terms, debugging is working absolutely fine.

BUT

hardware is still not giving desirable output (but it start to display), I send you code for explane you everthing please read it line by line:

void main()
{
unsigned char i;

Initialize(); //this function is Initialize LED

TMOD = 0X20;
SCON = 0x50;
TH1 = 0xFD;
TR1 = 1;

while(1)
{
while(RI==0); // While control is here I type "1" in serial window in debugging procces
{
i=SBUF; // here i=0x31(which is hex and ascii of 1) and RI become 1
RI=0; //RI is cleared
SBUF=i; //SBUF and i both showing 0x31
if(i==0x31) //you can see this condition must true because(i==0x31)
{
DISPLAY :- YES // this must go to display 1 on led
}
else
{
DISPLAY: NO // when "if" fails
}
}

}
}


as I say above:

if(i==0x31)
{
DISPLAY :- YES
}

This condtion must be satisfy and go to display 1 , but this doesnt happens.
however debugging is going absolutely right to display 1.(I am sending 1 by cmd)

I think I have hardware problem that's why i was asking about ATMEL AT89S53 configuration with comm and reg files.

do you think communication problem is not there ???????????????????????
I think SO because there is some blink on CNP when I send something by command prompt to led.(I am using cmd to communicate after success of this we will use VB ) also led output(undesirable) is recevied.

Absolutly you are not boring me :D but i am thankful to you that you have time for me and taking interest in my work. I have learn many things from you ......

THANKS again:D
Tariq
Mumbai

Added after 5 minutes:

Hi shivaram,

send me your personal Email ID , so that Isend you my PH.no.

THANKS again:D
Tariq
Mumbai

Added after 1 minutes:

listen,

do you think communication problem is not there ???????????????????????
I think SO because there is some blink on CNP when I send something by command prompt to led.(I am using cmd to communicate after success of this we will use VB ) also led output(undesirable) is recevied.

Bye
Tariq
 

Re: communication problem

could you post your updated code to me. I will see to it and reply to you at the earliest. If u dont mind please send me your ph no. so that in case i want some clarification i could call u. everytime posting may take lot of your time,.

Added after 1 minutes:

u cannot give here then do a pm to me or mail me the details to shivaram.cunchala@wipro.com and in cc ckshivaram@rediffmail.com

Added after 1 hours 2 minutes:

try this code.

#include<reg51.h>
//void Initialise();

unsigned char a[15] = {"The number is 1"};
unsigned char b[20] = {"The number is not 1"};
void main()
{
unsigned char i;

//Initialize(); //this function is Initialize LED

TMOD = 0X20;
SCON = 0x50;
TH1 = 0xFD;
TR1 = 1;

while(1)
{
while(RI==0); // While control is here I type "1" in serial window in
//debugging procces
{
i=SBUF; // here i=0x31(which is hex and ascii of 1) and SBUF=0x00 and
// RI become 1
RI=0; //RI is cleared
SBUF=i; //SBUF and i both showing 0x31
if(i==0x31) //you can see this condition must true because(i==0x31)
{

for (i=0;i<15;i++)
{
while(!TI);
SBUF = a;
TI=0;
}
// DISPLAY :
//- YES // this must go to display 1 on led
}
else
{

for (i=0;i<20;i++)
{
while(!TI);
SBUF = b;
TI=0;
}

// DISPLAY:// NO // when "if" fails
}
}

}
}

Added after 1 hours 44 minutes:

#include<regS53.h>
//void Initialise();

unsigned char a[15] = {"The number is 1"};
unsigned char b[20] = {"The number is not 1"};
void main()
{
unsigned char i;

//Initialize(); //this function is Initialize LED

//T2MOD = 0X02;
T2CON = 0x70;
SCON = 0x50;
TH1 = 0xFD;
TR2 = 1;

while(1)
{
while(RI==0); // While control is here I type "1" in serial window in
//debugging procces
{
i=SBUF; // here i=0x31(which is hex and ascii of 1) and SBUF=0x00 and
// RI become 1
RI=0; //RI is cleared
SBUF=i; //SBUF and i both showing 0x31
while(!TI);
SBUF = i;
TI=0;

if(i==0x31) //you can see this condition must true because(i==0x31)
{

for (i=0;i<15;i++)
{
while(!TI);
SBUF = a;
TI=0;
}
// DISPLAY :
//- YES // this must go to display 1 on led
}
else
{

for (i=0;i<20;i++)
{
while(!TI);
SBUF = b;
TI=0;
}

// DISPLAY:// NO // when "if" fails
}
}

}
}
 

Re: communication problem

#include <AT89X51.H>

unsigned int del,i,x,temp;

char getCharacter (void)
{
char chr; // variable to hold the new character
while (RI != 1) {;}
chr = SBUF;
RI = 0;
return(chr);
}
void send (char a)
{
SBUF = a;
while (TI != 1);
TI=0;
}

void main (void){
char chr;
int i=0,j=0,count=0,inc=47;//inc=47
int index=0;
P1=0X00;
P2=0X00;

SCON = 0x50; // mode 1, 8-bit uart, enable receiver
TMOD = 0x20; // timer 1, mode 2, 8-bit reload
TH1 = 0XE6; // 1200
TL1 = 0XE6;
TR1 = 1;
TI = 0;
SBUF =0;

while(1){

your code

}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top