View previous topic :: View next topic |
Author |
Message |
mpardinho
Joined: 16 Jul 2008 Posts: 8 Location: Mexico
|
rs232 and getc |
Posted: Wed Nov 05, 2008 4:57 am |
|
|
i can't work 'if"
if ((letra[5] == 'O') && (letra[4] == 'F')){
}................
Code: |
#include <18F252.h>
#FUSES HS
#FUSES WDT
#FUSES WDT128
#FUSES NOLVP
#FUSES CPB
#FUSES PROTECT
#use delay(clock = 8000000)
#use rs232(baud = 9600, parity = N, xmit = PIN_C6, rcv = PIN_C7, bits = 8)
#define Led PIN_A0
char letra[7];
//*---------------------------------------------------------------------------*/
void main() {
set_tris_a( 0b00000000 );
set_tris_b( 0b01111111 );
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED, 0, 1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
output_high( Led );
delay_ms( 1000 );
printf ( "\n\r\START\n\r" );
output_low( Led );
while (true) {
letra[6] = getc();
for (i = 1; i < 6; ++i) letra[i] = letra[i + 1];
if ((letra[5] == 'O') && (letra[4] == 'N') ) && (letra[3] == 'N') ) {
printf("ON");
};
if ((letra[5] == 'O') && (letra[4] == 'F') ) && (letra[3] == 'F') ) {
printf("OFF");
};
};
}
|
Last edited by mpardinho on Wed Nov 05, 2008 6:01 am; edited 1 time in total |
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 05, 2008 5:32 am |
|
|
Of course it won't....
You are writing each character to the location 'letra[6]'. Getc, gets _one_ character.
Best Wishes |
|
|
mpardinho
Joined: 16 Jul 2008 Posts: 8 Location: Mexico
|
|
Posted: Wed Nov 05, 2008 5:37 am |
|
|
i put caracter 2 in 1, 3 in 2
for (i = 1; i < 6; ++i) letra[i] = letra[i + 1];
i get 1 caracter in 6 and put i 5
if i test in proteus is 100% code works |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Wed Nov 05, 2008 5:40 am |
|
|
if ((letra[5] == 'O') && (letra[4] == 'N') ) && (letra[3] == 'N') ) {
printf("ON);
};
if ((letra[5] == 'O') && (letra[4] == 'F') ) && (letra[3] == 'F') ) {
printf("OFF);
};
two many brackets in wrong places! Change to this:
if (letra[5] == 'O' && letra[4] == 'N' && letra[3] == 'N' ) {
printf("ON);
};
if (letra[5] == 'O' && letra[4] == 'F' && letra[3] == 'F' ) {
printf("OFF);
}; |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Wed Nov 05, 2008 5:43 am |
|
|
Oh, and the printf's are wrong too. Missing quotes, change:
printf("OFF);
to this:
printf("OFF");
and the same with ON |
|
|
mpardinho
Joined: 16 Jul 2008 Posts: 8 Location: Mexico
|
|
Posted: Wed Nov 05, 2008 6:03 am |
|
|
i change code......i post without "
the problem is in if(
if(letra=='o' ...........
IN PROTEUS WORK |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed Nov 05, 2008 6:05 am |
|
|
You must be sending "NO" and "FFO" ?
if you send "ON"
"O" ->
letra[6] = "O"
"N"->
letra[5] = letra[6] ('O')
letra[6] = "N"
so your check would be if ((letra[5] == 'O') && (letra[6] == 'N'))
You have extra ; at the end of your if braces aswell. Won't hurt but don't need them!
if (...)
{
} // <-- No ; required |
|
|
|