Hi everyone, In my code receive session is not working.. what changes should i made to receive a character from my keyboard?
// 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 recieve() //Function to receive serial data { unsigned char value; while(RI==0); value=SBUF; P1=value; RI=0; } void transmit() // Funtion to transmit serial data { P2=P1-32; SBUF=P2; while(TI==0); TI=0; SBUF=P1; while(TI==0); TI=0; } void main() { while(1) { ini(); recieve(); transmit(); } }
Thank in advance
void uart_puts(char *s)
is inherently dangerous - "s" does not have to be null terminated! Better to deliver the buffer length/maximum buffer length as well.
puts() isn't really a big problem - somewhere in memory there is likely to be a zero. puts() isn't much different from printf() - also assuming that the string is zero-terminated. Just as strlen() and a huge number of other functions.
gets() on the other hand is lethal unless it is one of the non-standard implementations that takes a buffer size.
Isn't that effectively saying that all of the standard 'C' string functions are "inherently dangerous"...?!
I meant that this usage _could_ yield undesired results - not more.
I should have chosen my words more carefully!
Isn't that effectively saying that all of the standard 'C' string functions are "inherently dangerous"...?! well, replacing say 100 - I did not count - strcpy in a project with strncpy made 3 functions dysfunctional i.e. a buffer overflow was there with strcpy.
Erik