free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
say2paul
Fri Jul 04 2008, 11:39AM
 User Offline
Registered Member #8461
Joined: Tue Jun 17 2008, 10:56AM

Posts: 123
Thanked 6 times in 6 posts
I know my post might look weird as I am noob, but believe me I only got time to learn uC's at night as I am really very busy in daytime with Symbian C++.

Please look at the following code and let me know the mistake, here I am trying to print back a character to the hyper terminal in window OS. I wrote the code in such a way so that it can detect the character entered by user in hyper terminal and then send the same back to the hyper terminal.

I know I must be doing something wrong that is why I am unable to type anything on the Hyper Terminal

CODE:
#include<P89V51Rx2.h>
#include<intrins.h>
#include<string.h>

void delay()

   {
    int i;
 for(i=0;i<9000;i++);
 }
 
void serial_send(unsigned char dat){
        while(!TI);
        TI = 0;
        SBUF = dat;
}
unsigned char serial_read(){
        while(!RI);
        RI = 0;
        return SBUF;
}          
                   
 void main()
   {
unsigned char i,data1;        
    TMOD=0x20;
    SCON=0x50;
    TH1=0xfd;
    TL1=0xfd;
    TR1=1;
  while(1)
        {
                char a = serial_read();
                delay();
                serial_send(a);
        }       
}              
 






Back to top


Ajay
Mon Jul 07 2008, 08:01AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 4035
Thanked 751 times in 710 posts
I am not sure how you're able to compile it

coz you are using C now.. not c++ so

this thing is not possible within the program..
CODE:
char a = serial_read();


As per ANSI C you have to define the character at the top of program.

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


Ajay
Mon Jul 07 2008, 08:02AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 4035
Thanked 751 times in 710 posts
I am moving your post in 8051 discussion section

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


sashijoseph
Mon Jul 07 2008, 07:47PM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 648
Thanked 137 times in 130 posts
void serial_send(unsigned char dat){
while(!TI);
TI = 0;
SBUF = dat;
}


Change to ...

void serial_send(unsigned char dat){
SBUF = dat;
while(!TI);
TI = 0;

}

Let there be music........
Back to top


Ajay
Tue Jul 08 2008, 08:01AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 4035
Thanked 751 times in 710 posts
Sashi what paul wrote is fine just the problem is he declared the variable within the function which is not valid in C

he is used to of c++ a lot i guess

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


say2paul
Tue Jul 08 2008, 08:38AM
 User Offline
Registered Member #8461
Joined: Tue Jun 17 2008, 10:56AM

Posts: 123
Thanked 6 times in 6 posts
Its fact... and its difficult to follow C Standards...

But I will get use to it
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems