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(); } } /
void main() { ini(); transmit(); while(1); }
As Per points out, the program must return somewhere. Without the 'forever' loop, the code would proceed to la- la land. So, Keil placed a default jump to start code that is added by compiler just for the many beginners that leave out the forever loop. When you removed your while(1), Keil just added one for you. It may not restart and loop where your code should loop but it will loop.
Bradford
OOPs, I haven't read Dan Henry lately.