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

problem with getch an rs232

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







problem with getch an rs232
PostPosted: Thu Feb 02, 2006 12:09 pm     Reply with quote

i'm tryin to make a menu, but always it executes the last IF

if (orden!='C'){
pila=150;
(int32)deltap=9000

i can send an A, B or C, but the program always executes the last if.

here is the code.

orden=getch();
if (orden!='A') {
pila=60;
(int32)deltap=2000;
}
if (orden!='B'){
pila=330;
(int32)deltap=9000;
}
if (orden!='C'){
pila=150;
(int32)deltap=9000;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 02, 2006 12:54 pm     Reply with quote

Post a small program that shows the problem.
1. Show all variable declarations.
2. Show your #use rs232() statement, etc.
3. Post your version of the compiler.
sonicdeejay



Joined: 20 Dec 2005
Posts: 112

View user's profile Send private message

PostPosted: Thu Feb 02, 2006 1:00 pm     Reply with quote



I use Max 232 to buffer between my PIC..that's connection works for me...and my RS232 code is


Code:
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)  // RS232 Configuration
Ttelmah
Guest







PostPosted: Thu Feb 02, 2006 3:31 pm     Reply with quote

As written, the code will always execute the last if, unless the character is a 'C' (also remember that if you type a 'C', by default this will be lower case, and will not be accepted).
As it stands, if 'A' arrives, it'll execute the pila=330 code, then the pila=150 code. If 'B' arrives, it'll execute the pila=60 code, and then the pila=150 code. If 'C' arrives, it'll execute the pila=60 code, then the pila=330 code. If anything else arrives, all three statements will execute.
Normally you would test for the character beng equal, rather than 'not equal', and also use the 'else' statement, so it only executes the other tests if the tests so far have failed.

Best Wishes
alfonsol
Guest







PostPosted: Thu Feb 02, 2006 4:29 pm     Reply with quote

include <18F1320.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_b1, rcv=PIN_b4)

char orden;
int32 pila,deltap;

main(void)
{
orden=getch();
if (orden!='A') {
pila=60;
(int32)deltap=2000;
}
if (orden!='B'){
pila=330;
(int32)deltap=9000;
}
if (orden!='C'){
pila=150;
(int32)deltap=9000;

}
printf("\n\rorde: %4c pila: %4ld deltap: %4ld \n\r",orden,pila,deltap);
}

this program shows what happens
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Feb 03, 2006 8:18 am     Reply with quote

It seems this should wait for a character, then execute two of the three options depending what the character is, or all three if it is an unknown character. Is this what you want to happen? What do you want this code to do?

Offhand i would say the <if (orden!='A')> is a little odd for a menu. It means that that section of code will execute if anything EXCEPT 'A' comes in. < if (orden ='A')> is more what I would expect.
_________________
The search for better is endless. Instead simply find very good and get the job done.
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 03, 2006 8:38 am     Reply with quote

Sonicdeejay: Here's a little easier and much cheaper way to do it:



You can use 10K resistors in place of the 2.2K. Complete details at http://www.botkin.org/dale/rs232_interface.htm if you want to read it.

Dale
sonicdeejay



Joined: 20 Dec 2005
Posts: 112

View user's profile Send private message

PostPosted: Fri Feb 03, 2006 8:57 am     Reply with quote

dbotkin wrote:
Sonicdeejay: Here's a little easier and much cheaper way to do it:



You can use 10K resistors in place of the 2.2K. Complete details at http://www.botkin.org/dale/rs232_interface.htm if you want to read it.

Dale


I should Hav know earlier....thx for the info...
alfonsol
Guest







PostPosted: Fri Feb 03, 2006 11:27 am     Reply with quote

thanks the problem was i used != and i should used == i copied the line from another program and i didn't see that
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