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

Display at LCD

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



Joined: 09 Jan 2012
Posts: 45

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

Display at LCD
PostPosted: Mon Jan 09, 2012 7:24 am     Reply with quote

I made a code to flash a Led at one speed and when a switch is closed the Led changes the speed of flashing. The code was a success. Now I want to display this on an LCD 16x2. When the switch is not closed and led is flashing faster will display on the LCD-Fast and when the switch is closed display on LCD - Slow. But when I simulate it, it only displays Fast even if the switch is closed or not. Here is the code:
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include "flex_lcd.c"
#include <stdio.h>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
lcd_init();  // Always call this first.
#define TRUE 1
#define FALSE 0
 
void main()
{
lcd_init();  // Always call this first.
if(PIN_C0==TRUE)

printf(lcd_putc,"\SLOW\n");
else (PIN_C0==FALSE);
{
printf(lcd_putc,"\FAST\t");
}
{

}
while(1) // Keep checking switch
{
if(!input(PIN_C0)) // Siren while switch ON

{
output_high(PIN_C1); // Sound sequence
delay_ms(300);
output_low(PIN_C1);
delay_ms(300);


}
else(input(PIN_C0));
output_high(PIN_C1); // Sound sequence
delay_us(500);
output_low(PIN_C1);
delay_us(500);
}
}
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Jan 09, 2012 7:59 am     Reply with quote

Code:

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
// Delete the following line  - you can't call anything here.
lcd_init(); // Always call this first.

// The follwoing two lines are redundant. TRUE and FALSE are already defined for you.
#define TRUE 1
#define FALSE 0

void main()
{
    lcd_init(); // Always call this first.
    // There's no need to compare pins to TRUE or FALSE. They are already true or false.
    // Also PIN_C0 is a constant "pointer" to the pin. To read the state of the pin you must do input(PIN_C0) which returns true or false.
    // The next line should be: if (input(PIN_C0))
    if(PIN_C0==TRUE)
        printf(lcd_putc,"\SLOW\n");
    // Else should not have anything in brackets after it. Its simply: else
    else (PIN_C0==FALSE);
    // This is always executed as its outside the if-else which ended at the semi-colon in the line above.
    {
        printf(lcd_putc,"\FAST\t");
    }

    // This next block does nothing: its empty.
    {

    }

    // Everything above happens only once. Everything inside this while block is done over and over.
    while(1) // Keep checking switch
    {
        // Correct pin input syntax this time.
        if(!input(PIN_C0)) // Siren while switch ON
        {
            output_high(PIN_C1); // Sound sequence
            delay_ms(300);
            output_low(PIN_C1);
            delay_ms(300);
        }
        // Else is wrong here too. Also nothing will be executed as the else block ends at the semicolon.
        else(input(PIN_C0));

        // This is NOT part of the if-else. Its totally separate and is ALWAYS executed.
        output_high(PIN_C1); // Sound sequence
        delay_us(500);
        output_low(PIN_C1);
        delay_us(500);
    }
}


I doubt this code compiles. If it does I really doubt it does what you want it to. I suspect you need something more like this pseudo-code:

Code:

while (1)
{
    if (input(PIN_C0)
    {
        // Do something when PIN_C0 is one.
    }
    else
    {
        // Do something else when PIN_C0 in NOT one, i.e. its zero.
    }
}


RF Developer
colesha



Joined: 09 Jan 2012
Posts: 45

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

PostPosted: Mon Jan 09, 2012 11:48 pm     Reply with quote

Thanks RF_Developer,
The code compiles but it does not do what I want as you said, fine I can use the if-else function but I just need to no how to do it. I made several attempts and appeared to be well but the problem I get is that the LED flash sequnce is affected.
All I need is to flash the LED at a different speed when the switch is closed and display fast or slow on the LCD. I can use the if-else function but maybe just can't figure out the best way to do it.

Some assistance Please.
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