We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to have some leds in P2.0~2.3 and show off the "ON" lamp in VB6.0 program though RS232 during the sensors are +5V output to P1.0~1.3 89S52 MCU. But it appears many errors and doesn't work in PC. Please advise me the comments for the following code. Thanks a lot!!
Sorry!
void delayms(unsigned int time); main() { TMOD=0x20; TH1=230; TL1=230; TR1=1; SCON=0x70; RI=0; TI=0; ES=1; EA=1; while(1) { while(P3==0xff); switch(P3) { case 0xfb: { P1_0=0; SBUF=P1; break; } case 0xf7: { P1_0=1; SBUF=P1; break; } case 0xef: { P1_1=0; SBUF=P1; break; } case 0xdf: { P1_1=1; SBUF=P1; break; } } delayms(100); while(P3!=0xff); } } void scon_int (void) interrupt 4 { if(RI==1) { RI=0; switch(SBUF) { case 0xfb: { P1_0=0; SBUF=P1; break; } case 0xf7: { P1_0=1; SBUF=P1; break; } case 0xef: { P1_1=0; SBUF=P1; break; } case 0xdf: { P1_1=1; SBUF=P1; break; } } } else TI=0 ; } void delayms(unsigned int time) { unsigned int n; while(time>0) { n=120; while(n>0) n--; time--; } }
#include<REGX52.H> #include<STDIO.H> main() { TMOD=0x20; TH1=230; TL1=230; TR1=1; SCON=0x70; while(1) { RI=0; TI=0; SBUF=P1 | 0xf0; while(TI==0); while(RI==0); if(SBUF==0xfe) P1=0x3f; else if(SBUF==0xfd) P1=0xcf; else if(SBUF==0xfb) P1=0x0f; else if(SBUF==0xf7) P1=0xff; } }
I want to output the signal through RS232 to PC(VB6.0) (just show ON/Off lamp on VB6.0)during the switch on/off. Please advise me how to write Keil C in addition base on the above code or provde some information for my reference. Thanks a lot!!
http://www.keil.com/books
www.8052.com/.../RS232gd.pdf
http://www.8052.com/faqs - there's a whole section titled, "Serial Communications Questions"
Thanks! But I want to have more related examples for my reference!!
But what you need first is to get a firm, foundational understanding of the principles.
If you just want examples, there are tons available all over the internet - serial comms must be one of the commonest tasks on an 8051!
There are even plenty of examples on this very site: http://www.keil.com/download/list/c51.htm
The most basic example of serial comms is, of course, the classic "Hello, world" program - see: http://www.keil.com/support/man/docs/uv4/uv4_ex_hello.htm
See also: http://www.keil.com/support/man/docs/uv4/uv4_ex_measureovw.htm
Thanks! If i have the following codes, how to write the code through RS232 to PC?? Please advise it!!
Please re-read the entire thread from the top. Nobody here is going to do your homework.
Do you actually understand what it's doing?
If you do, then put in comments to show your understanding.
If not, then clearly that is your basic problem!
Why don't you just start with "Hello World", get to understand it, and work from there?
PS
Your layout is still messy; don't use TABs - they don't work on (most) internet forums - use only spaces for indenting.
Note that any decent editor (including uVision) can be set to insert spaces when you press the TAB button:
Edit > Configuration > Editor > Insert spaces for tabs
I just want to ask the related questions, hope someone can help me. Why you say that!! how come the rules to do it!! If I can solve it, i dont need to post my questions!!
I know it's messy for you!! But now I m very urgent to know how to do it!! In fact, if i can't do it, I ll be worst!! I
If I can solve it, i dont need to post my questions!!
No. You should have posted:
"If I cannot solve it, I need to read the documentation and to debug".
"I'm very urgent to know how to do it!!"
There are no shortcuts! If you want to know how to do it, then you need to spend time learning the principles involved!
IF this is a homework assignment, then it is assumed that a capable student should be able to do it. If you really can't do it, then you need to speak to your tutors about either getting some additional tuition, or switching to another course...
But you're not listening to the answers!
Hey!! you are not me!!
I always know no shortcut!!