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 CCS Technical Support

kbhit() use

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



Joined: 16 Jun 2005
Posts: 2

View user's profile Send private message

kbhit() use
PostPosted: Fri Jun 17, 2005 12:03 am     Reply with quote

I am trying to address Port D when send[code]ing 2 through RS232 to the PIC 16F877. I am still a very beginner and I am trying to modify an example from a CCS book, however I don't know how to modify it. The following is giving me an error when compiled by CCS.

[code]
#include <16F877.h>
#use delay (clock=20000000)
#fuses HS,NOWDT,NOPROTECT
#use rs232 (baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=RS232,bits=8)
#include <stdio.h>
#include <stdlib.h>

char ch;

void main()
{
[/code]
while(1)
{
if (kbhit())
{
ch=getchar();

if ch()==2;

output_D (~ch);

printf ("\n\r You pressed %c", ch);
}

}
}
[code]

Can anyone help in modifying this code so it works the way I want to work. Thanks!
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 12:32 am     Reply with quote

Code:
 if (kbhit())
{
ch=getchar();

if ch()==2;

output_D (~ch);

printf ("\n\r You pressed %c", ch);
}


can i make a suggestion?

before you go any further, pick up a copy of the following:
The C Programming Language
by Brian W. Kernighan and Dennis M. Ritchie.
Prentice Hall, Inc., 1988.
ISBN 0-13-110362-8 (paperback), 0-13-110370-9 (hardback).

you will need this book for the rest of your embedded C programming life. with it you can learn the basic constructs of C and avoid the type of mistakes you are making above.

we can give you fish, or teach you to fish -- you'll find the latter is much more useful and a lot less frustrating.

jds-pic

Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 7:48 am     Reply with quote

Code:


#include <16F877.h>
#fuses NOWDT,XT, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use delay (clock=20000000)
#use rs232 (baud=9600,xmit=PIN_C6,rcv=PIN_C7)


char ch;

void main()
{
 printf("\r\n TEST\r\n");
 
 while(1)
      {
       if(kbhit())
          {
           ch = getc();
           delay_ms(5);
           
           printf ("\r\nYou pressed  ASCII: %C  Hex: 0x%X  Dec: %u",ch,ch,ch);
             
           if( ch == '2' )
             {
              output_D(~ch);
             }
             
          }   
      }
}



Humberto
Telecomguy



Joined: 16 Jun 2005
Posts: 2

View user's profile Send private message

Thanks
PostPosted: Fri Jun 17, 2005 6:20 pm     Reply with quote

Thanks a lot Humberto, you managed to solve my problem.
Telecomguy



Joined: 16 Jun 2005
Posts: 2

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 6:27 pm     Reply with quote

jds-pic I really really wish to do it the way you suggested. No body like to end up frustrated the way I am. However I was misguided in my school project and loads of efforts were wasted. I am here trying to solve administration problems imposed on me. I'm frustrated and bagging information otherwise due to course deliverance mismanagement I am loosing my certification. I appreciate your suggestion and I am spending whole nights practicing examples from 'Embedded C Programming and the microchip PIC' which is a very good book and I intend to keep practicing after I finish this project.

Best regards to all

Telecomguy
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