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.

please check my program code (serial communication)

Status
Not open for further replies.

katsmiley

Newbie level 4
Joined
Jan 20, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
mumbai
Activity points
1,326
serial communication

hey guys plz help me out.....here i have done program for serial transmition..i am using keil compiler...my problem is i can not see string"ATKT" in the serial window.i am sending it char by char using putchar ....whai is wrong inthis??plz help..........





#include<stdio.h>
#include <REG51.H>

void send(unsigned char []);
void delay();
void serialint(void);

unsigned char prati[]="ATKT";

void main()
{

serialint();
while(1)
{

send(prati);
delay();
}
}



void serialint(void)
{

SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x21; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xf3; /* TH1: reload value for 2400 baud */
TR1 = 1; /* TR1: timer 1 run */
TI = 1;


}

void delay(void)
{

TH0=0XEE;
TL0=0XE0;
TR0=1;
while(!TF0);
TF0=0;


}



void send(unsigned char *p)
{
int val=0;
while(*p!='\n')
{
val=*p;
putchar(val);
delay();
p++;



}


}

:cry::cry:
 

Re: serial communication

Try this code.....


#include"reg51f.h"

void DelayMs(unsigned int period)
{
unsigned int i,j,k=0;
period<<=1;
for(i=0;i<period;i++)
{
for(j=0;j<0x14;j++)
{
k++;
}
}
}
void init_serial()
{
TMOD = 0x20;
TH1 = 0xFD; // For 9600 Baud Rate
SCON = 0x50;
TR1 = 1;
}
void send_char(unsigned char ch)
{
SBUF = ch;
while( !TI );
TI = 0;
}
void send(unsigned char *temp)
{
while(*temp)
{
send_char(*temp);
DelayMs(10);
temp++ ;
}
}
void main()
{
init_serial();
send("HELLO WORLD") ;
while(1);
}

-----

If you want to use serial communication with serial Interrupt





---
Gurpreet Singh
www.embeddedcraft.org
 

serial communication

thnx for ur reply....but tell me what is wrong in my code?in my code i want to use putchar to see its working.....so can anybody tel me what is wrong?can anybody modify my code???



come on!! plz tel me......
 

Re: serial communication

I tested your program on Keil and found it working fine. I do see the ATKT for the first four characters.
 

    katsmiley

    Points: 2
    Helpful Answer Positive Rating
serial communication

thnx a lot....really its workin????but i cant see anything ......what will be the reason??
 

what serial window you were looking at.

I used the generic simulator for 8052 in Keil and the serial 1 window.

I do see ATKT and then some non-displayable characters values. I think your string is not properly null terminated.
 

Re: serial communication

katsmiley said:
void send(unsigned char []);

void send(unsigned char *p)

I think this is the mistake..
initially you have declared the parameter as unsigned char and then as a pointer.
IMO it should be

void send(unsigned char *p);

........

void send(unsigned char *p)
{
//your code;
}

:D
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top