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

PIC 16F84A communicate with Hyperterminal

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



Joined: 10 Oct 2008
Posts: 2

View user's profile Send private message MSN Messenger

PIC 16F84A communicate with Hyperterminal
PostPosted: Sat Oct 11, 2008 12:03 am     Reply with quote

Can anyone tell me what are the codes in C Programming that represent [ENTER], [SPACE],[CTRL+Z] on computer keypad?

I wrote a segment of program in PWC:

Code:

if(input(PIN_A0))
   {
    output_high(PIN_B0);
    printf("Connected,%x,A1");
    printf("Serial Communication Is Effective,%x,0D");
    }
   else
   {
    output_low(PIN_B0);
   }

But as I compile there is error in the printf statements...

Crying or Very sad I've tried this too
Code:

(input(PIN_A0))
   {
    output_high(PIN_B0);
    printf("Connected\r");
    printf("Serial Communication Is Effective"^z);
    }
   else
   {
    output_low(PIN_B0);
   }

But it failed too...

Did i get the code wrong or it's the format ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Oct 11, 2008 2:23 am     Reply with quote

I suggest, to spend some time to understand the C language printf syntax. There's nothing CCS C specific in the shown code errors.

In the first example, the arguments for the %x specifier are missing. For each format specifier, a comma separated function parameter is expected. Provided, A1 is a variable name, the correct syntax is:
Code:
printf("Connected,%x",A1);

The code implies, that the value of A1 is displayed in hexadecimal format, e. g.
Code:
Connected,b7


If you intend to insert an arbitrary character code to the line, %c would be the correct format specifier. Special character constants can be inserted by a different syntax.

In the second example, ^z isn't a defined character in C language, cause ^ is a reserved operator.
Ttelmah
Guest







PostPosted: Sat Oct 11, 2008 2:46 am     Reply with quote

'Enter', on the PC, with terminals etc., usually returns two characters, not one. Carriage return, Line feed (CRLF).
In C, you can generate control characters in a whole sequence of ways. So:
Code:

#define LF ('\n')
#define CR (0xD)

//The both do similar jobs, showing two different ways of coding such
//values.

putc(LF); //Will send the LF character

printf("Showing another way %c%c",CR,LF);

//This will send both CR, and LF. Note that for each '%' definition, there
//_must_ be a variable or constant given after the string

printf("The normal way\n\r");

//Including the constants in the string.


There are a lot of standard '\' escapes available, a look in a C reference book will find these.
You can also send just about any byte, using:

putc('\015');

This sends the _octal_ character defined by 015 - Carriage return.

putc('\x0D;);

Sends the same character, but defining it in hex.
These defines can also be used in the printf string.

With putc, you can also just use a number. So:

putc(13);

Again sends the carriage return.

The _one_ character you have to be very careful with, is the '\0' byte. In C, '\0' (ASCII 'NUL'), is the end of string terminator character. So, though you can send this as a single character using putc, you cannot include it 'inside' a string.

Look at a site like: www<dot>bbdsoft<dot>com<slash>ascii<dot>html

Which will give all the standard ASCII codes and names.
For your CTRL-Z, you could use:

putc('\x1A');

Best Wishes
Cathee Ncqueen



Joined: 10 Oct 2008
Posts: 2

View user's profile Send private message MSN Messenger

PostPosted: Sat Oct 11, 2008 10:41 am     Reply with quote

thank you guys so much...
so i have tried this just now:
Code:

if(input(PIN_A0))
  {
   output_high(PIN_B0);
   printf("Connected%C",0x0D);
   printf("correct!%C",0x1A);
  }
else
  {
   output_low(PIN_B0);
  }
}

After I burned the program in PIC and connect it to the hyperterminal, the words "connected correct!" came out continuously without stopping. The CTRL+Z is supposed to be stop the text ...it's supposed to be like this:
connected[ENTER]
correct![END]

So I still don't know what's wrong yet ...
Ttelmah
Guest







PostPosted: Sat Oct 11, 2008 12:42 pm     Reply with quote

You keep sending.......
The CTRL-Z, is a command that a _receiving_ device, can send to a _transmitting_ device that understands it, to tell _it_ to stop sending.
In your case, so long as pin A0 is high, you keep sending, so hyperterminal keeps displaying. If you want to handle control characters like this, you would have to add handling to _your_ program.

Best Wishes
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