Hi, I am using P89V51RD2 NXP micro controller. I tried this code and able to transmit the char 's' for infinite time. Now i want to print/transmit it once. After removing the while(1) it print infinite time. What should i change in my program to transmit for one time?
// Program to test serial communication of controller with PC using hyper terminal #include<reg51.h> void ini() // Initialize Timer 1 for serial communication { TMOD=0x20; //Timer1, mode 2, baud rate 9600 bps TH1=0XFD; SCON=0x50; TR1=1; } void transmit() // Funtion to transmit serial data { SBUF='s'; while(TI==0); TI=0; } void main() { ini(); while(1) { transmit(); } } /
If you remove the while loop - maybe you could tell this forum where you think your application will go after having completed the transmit() call?
void main() { ini(); transmit(); }
Do you think there is a catcher waiting with a pillow to stop any program that runs out of main()? Have you seen any command line prompt or any nice GUI that your microprocessor may reach after the program ends? Do you think your processor (who only knows how to process machine instructions) do know that your C program leaves main() and will then automatically stop processing machine instructions?
By the way - you do have access to a debugger - have you tried to switch to assembly mode and continue to trace your application after it leaves main()? Maybe you should. It is normally considered "undefined behaviour" for an embedded program - but if you design a program explicitly assuming it ok to leave main(), it might be a good idea for you to check up what really do happen.