CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ABOUT START END CHARACTERS ON RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sebastian



Joined: 01 Dec 2003
Posts: 21
Location: Milan Italy

View user's profile Send private message Send e-mail

ABOUT START END CHARACTERS ON RS232
PostPosted: Thu Nov 24, 2005 4:46 am     Reply with quote

HI ALL

I HAVE WRITE THIS CODE BUT I HAVE A PROBLEM

#if defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
#endif

#include <input.c>

void main() {

int value;
char string;

// int value1=0b00000000; // DEC 0
int value2=0b00000001; // DEC 1

set_tris_B(0x00);
set_tris_D(0xFF);

while (TRUE){

output_b(0x00);
value=input_d();


if (value==value2){

printf("?0001wdloa;1; ?");

delay_ms(500);

gets(string);
{
if ( strcmp(string,?00011;AD?))
output_b(0x0F);
}
}
}
}


IN THIS LINE
printf("?0001wdloa;1; ?");
MPLAB NOT PERMIT TO INSERT THE CHARACTER ASCII HEX 02
SYM STX THE SAME WITH CHARACTER 03HEX SYM ETX
AFTER SAVE FILE EXIT PROJECT AND REOPEN MPLAB REPLACE
THE CARACTERS WITH ?

THERE IS ONE WAY TO PREVENT THIS ??
CAN I TRANSMIT CHARACTERS ON RS 232 IN 8 BIT FORMAT ?

THANK YOU ....
Ttelmah
Guest







PostPosted: Thu Nov 24, 2005 5:42 am     Reply with quote

This is not MPLAB, but standard C.
An ASCII control character, has to be declared using an 'escape sequence'. These are:
\0 = ASCII '0'
\nnn = ASCII 'nnn', in octal
\xhh = ASCII 'hh' in hex
\a = 'alert' (bell) character
\b = 'backspace'
\f = 'formfeed'
\n = 'newline'
\r = 'carriage return'
\t = 'horizontal tab'
\v = 'vertical tab'
\\ = the 'backslash' character itself
\? = Question mark
\' = the 'single quote' character
\" = the 'double quote' character

So for the STX character you need (start of transmission), you need to use either \x02 or \002 i the string declaration, and for ETX, \x3 or \003.
Remember that C is designed so that you might well be typing it in using a terminal, and you obviously cannot type a STX, or ETX code into a string, since it would start/stop the actual transmission...

Best Wishes
Sebastian



Joined: 01 Dec 2003
Posts: 21
Location: Milan Italy

View user's profile Send private message Send e-mail

more of 1 character
PostPosted: Thu Nov 24, 2005 7:58 am     Reply with quote

Ttelmah wrote:
This is not MPLAB, but standard C.
An ASCII control character, has to be declared using an 'escape sequence'. These are:
\0 = ASCII '0'
\nnn = ASCII 'nnn', in octal
\xhh = ASCII 'hh' in hex
\a = 'alert' (bell) character
\b = 'backspace'
\f = 'formfeed'
\n = 'newline'
\r = 'carriage return'
\t = 'horizontal tab'
\v = 'vertical tab'
\\ = the 'backslash' character itself
\? = Question mark
\' = the 'single quote' character
\" = the 'double quote' character

So for the STX character you need (start of transmission), you need to use either \x02 or \002 i the string declaration, and for ETX, \x3 or \003.
Remember that C is designed so that you might well be typing it in using a terminal, and you obviously cannot type a STX, or ETX code into a string, since it would start/stop the actual transmission...

Best Wishes



Thanks for reply


But in my code i have 15 characters in line
and if i write

printf("\x20001wdloa;1; \x3);
i think is not correct
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group