Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F877A RS232 eblock data transfer

Status
Not open for further replies.

oodes

New Member
Hi guys,
I'm transmitting data from the PIC using the RS232 serial block using a Hyperterminal. Problem is that when my data hits a value like 26(in ascii) it causes an EOF or a value like 13(cr) it corrupts my data stream. I am aware that the first 32 codes in ascii are control codes, but the majority of my data is low values for wind speed and temperature, is there any way around this.
I'm exporting the data to a txt file and opening in EXcel to manage the data and the little bits of corrupt data are casing havoc when i convert back to decimal .
Are there any settings i can change in the hyperterminal window to stop this happening?

Thanks in advance
DEs
 
Easiest way is to simply send it as ASCII in the first place, so 26 would be sent as '2' followed by '6'.

If you check my tutorials there are suitable routines there for doing this.
 
Easiest way is to simply send it as ASCII in the first place, so 26 would be sent as '2' followed by '6'.

If you check my tutorials there are suitable routines there for doing this.
Sorry nigel , assembly is not my strong point (or C for that matter:D) , am programming in C as shown below. Problem is when the functions which are temp,dir,revolutions ever happen to land on like 13 which is cr it corrupts the data stream

RX_UART();
while(pir1.RCIF)//keep reading in case user types number of keys
RX_UART(); //Must read or RCIF will be set again..cleared when RCREG empty

TX_UART(0x44); // transmitt the Letter D for direction
delay_ms(2); // 2 ms delay
TX_UART(0x2C); // transmitt a comma
delay_ms(200); // 200 ms delay
TX_UART(dir); // transmitt the data for direction
delay_ms(2); // 2 ms delay
TX_UART(0x2C); // transmitt a comma
delay_ms(2); // 2 ms delay

TX_UART(0x54); // transmitt the Letter T for Temperature
delay_ms(2); // 2 ms delay
TX_UART(0x2C); // transmitt a comma
delay_ms(200); // 200 ms delay
TX_UART(temp); // transmitt the date for temperature
delay_ms(2); // 2ms delay
TX_UART(0x2C); // transmitt a comma
delay_ms(2); // 2 ms delay

TX_UART(0x52); // transmitt the Letter R for Revolutions
delay_ms(2); // 2 ms delay
TX_UART(0x2C); // transmitt a comma
delay_ms(200); // 200 ms delay
TX_UART(revolutions); //transmitt the data for revolutions
delay_ms(1);


TX_UART(0x0D); //carriage return
delay_ms(1);
TX_UART(0x0A); //line feed
delay_ms(1);


delay_s(8); //delay 8 seconds to aloow for stop capture of text
 
Sorry nigel , assembly is not my strong point (or C for that matter:D) , am programming in C as shown below. Problem is when the functions which are temp,dir,revolutions ever happen to land on like 13 which is cr it corrupts the data stream

Like I said, send it as ASCII, it should be even easier in C - simply convert the variable to a string.
 
In C we tend to use printf().... This is one of the library functions (some people try not to use these functions as it takes quite a bit of code and data ) but on the plus side... its quick.

ie...

Code:
  char loop = 0;
  char buffer[20];
  int dir = 24;
  int temp = 37;
  int revolutions = 8;
  sprintf(buffer,"D,%d,T,%d,R,%d,\n\r",dir,temp,revolutions);
  while(buffer[loop] != 0)
     {
      TX_UART(buffer[loop++];
     delay_ms(20);
      }

if you add a putch(); function in your code then the line will convert and send your buffer as well...
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top