Hi guys, Here is the situation I've 89c51 microcontroller board which I want to connect with PC as well as GSM but as everybody knows it(8051) has only one UART so one solution is try using 87xx or 83xx series of controller but that means I'll have to change my programmer. So what I'm thinking is I'll use simple mux/demux for Tx/Rx of 8051. I want to know will it be o.k.? Can simple AND or OR gates can handle data rate of 9600bps?
Thank you very much in advance.
I guess I'm doing some stupid mistake I'll have to rectify it
Can anybody let me know what should following programing do? Is main in keil is reentrant? even with for loop following pogram work infinitely
//program to transmit a chaaracter #include<reg51.h> sbit Select = P3^2; void Delay(void); void main(void) { int i; SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TR1 = 1; for(i=0; i<21; i++) { Select = 0; SBUF = 'p'; while(TI == 0){} TI = 0; P2 = 'p'; Delay(); Delay(); Delay(); Delay(); Delay(); Select = 1; SBUF = 'q'; while(TI == 0){} TI = 0; P2 = 'q'; Delay(); Delay(); Delay(); Delay(); Delay(); } } void Delay(void) { unsigned char i; for(i=0;i<=200;i++) {} return; }
Is main in keil is reentrant This has nothing to do with Keil. main is 'reentrant' in the sense that it is entered after each reset, but in no other respect.
if you do not have an unbreakable loop in in your program will just 'overflow' at the end of main().
This is EMBEDDED and in EMBEDDED you do not exit from (the root) main(). ONLY if you have code with a main() that call code with a main() (a very construed construct) could you have a returning main().
Erik
Then why would above program work infinitely instead of only 21 times it transmits p and q infinitely
That depends on the startup code.
If the startup code immediately returns to main() or performs a watchdog-reset or a "pseudo-reset", your program will continue to send data.
If you want your program to perform 21 interations and then stop, you should add an infinite loop at the end of the program. For processors who support it, the infinite loop could contain a sleep instruction, to conserve power.
Thank you very much Per Westermark. That worked well when I put while(1){} anyway what is this start up code - keil used to ask every time do you want to copy and stuff but I don't understand it much. Can you please guide me where can I read about it or so I would like to gain more knowledge
The erased state of EPROM is FF - which is the opcode for MOV R7,A
So your could could run off the end of main(), then execute all the erased EPROM locations as MOV R7,A until the address spaces wraps around and it returns to the reset vector at C:0x0000
The delay due to executing these MOV R7,A instructions is likely to be imperceptible, giving the impression that main() is just executing continuously...
Please guys don't go for that success tag in future if somebody want to do so. I guess this method is failure anyway will let you know for sure in a day or two When I put incremental characters i.e. a,b,c,d,e,.... in transmission i got at receiver is random characters still I'll try for a day or two
"Can you please guide me where can I read about it"
It should come as no surprise to find that you can read all about it in the compiler's Manual!
http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm
Thanks Andy
It's a good idea keeping infinite loop at the end of 21 iterations and solving your problem....
If you want to send 21 characters the next time you should reset the controller.......
n secondly you couldn't get a clear answer why it is going to infinite loop.....
How about writing your for loop in the infinite loop and using some flag option to get out of that infinite loop.....
use the data Tx pin of controller and set the flag whenever a trnsition occurs on this pin.....
n moreover your program is not flexible first it sends character to first PC and then to second .... for suppose if the controller wants to send data to same PC it can't....u have to RESET the controller....