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

Switch toggle High/Low
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Switch toggle High/Low
PostPosted: Thu Nov 02, 2006 3:05 pm     Reply with quote

Hi i want to to toggle push button high and low but i can't make it what's wrong with code

Code:
while(true){
   static int  mm = 0;
   printf(lcd_putc,"\f Status ");
   switch (input(pin_C0)== mm){
   case 0:
   printf(lcd_putc,"\n Low ");
   delay_ms(500);
   break;
   case 1:
   printf(lcd_putc,"\n High ");
   delay_ms(500);
   mm = 0 ; // reset variable mm
   break;
   }
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Nov 02, 2006 3:26 pm     Reply with quote

Code:

while(true)
{
  printf(lcd_putc,"\f Status ");
  if (!input(pin_C0))
    printf(lcd_putc,"\n Low ");
  else
    printf(lcd_putc,"\n High ");
  delay_ms(500);
}
Guest








PostPosted: Thu Nov 02, 2006 3:34 pm     Reply with quote

thanks but i want the status stays for each press like when i press first time the status goes high and stay high when i press another time to go low and stay low like normal switch but in push button
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Nov 02, 2006 4:04 pm     Reply with quote

Code:

int state = 0;
while(true)
{
  while (!input(pin_C0));
  printf(lcd_putc,"\f Status ");
  if (state)
  {
    state = 0;
    printf(lcd_putc,"\n Low ");
  }
  else
  {
    state = 1;
    printf(lcd_putc,"\n High ");
  }
}
Guest








PostPosted: Thu Nov 02, 2006 4:19 pm     Reply with quote

it dosen't work Rolling Eyes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Nov 02, 2006 5:10 pm     Reply with quote

post your complete program
Guest








PostPosted: Fri Nov 03, 2006 7:36 am     Reply with quote

it's a test program for toggling a button this whole program except the headers
Humberto



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

View user's profile Send private message

PostPosted: Fri Nov 03, 2006 7:58 am     Reply with quote

The code posted by Mark should work.

What about your hardware:
does the uC oscillator is running ?
can you blink a LED to see that it is alive ?
can you write a single word in the LCD ?
did you connect pull up resistors in the push buttons ?


Humberto
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Nov 03, 2006 8:07 am     Reply with quote

Anonymous wrote:
it's a test program for toggling a button this whole program except the headers


Obivously then you do not want any help since you cannot do what is asked. I'm done....Bye
Guest








PostPosted: Fri Nov 03, 2006 8:11 am     Reply with quote

Humberto all thing is allright i can do anything with lcd the xtal is ok and the board is ok

Mark i can't understand you this is the main of my program so it's my whole program i use PIC 16F876A and 20 Mhz xtal anyway thanks .. Rolling Eyes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Nov 03, 2006 9:25 am     Reply with quote

Anonymous wrote:
Humberto all thing is allright i can do anything with lcd the xtal is ok and the board is ok

Mark i can't understand you this is the main of my program so it's my whole program i use PIC 16F876A and 20 Mhz xtal anyway thanks .. Rolling Eyes


What can't you understand about posting a COMPLETE program that compiles. I don't want bits and pieces or psudeo code or even something typed out which is close to the test program. I want a cut and paste of your program. Is that clear enough? Did ya understand that? I've been at this quite a while and have wasted plenty of time because of other problems else where in the code.
Guest








PostPosted: Sat Nov 04, 2006 3:55 am     Reply with quote

Ok here's the Code

Code:
#include <16F876A.h>
#fuses XT,NOWDT
#use delay(clock=2000000)
#include "LCD.c"
void main()
{
   lcd_init();

while(true){
   static int  mm = 0;
   printf(lcd_putc,"\f Status ");
   switch (input(pin_C0)== mm){
   case 0:
   printf(lcd_putc,"\n Low ");
   delay_ms(500); //Debounce
   break;
   case 1:
   printf(lcd_putc,"\n High ");
   delay_ms(500); //Debounce
   mm = 0 ; // reset variable mm
   break;
   }

}
}

jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sat Nov 04, 2006 4:45 am     Reply with quote

I don't think you're using the code that was written for you.

I don't follow your logic in using a SWITCH statement for an either/or condition?

Also:

Quote:
20 Mhz xtal


!=

Code:
#use delay(clock=2000000)


That is one very good reason to post the WHOLE program.

If you'd like the pros to help you, let them.
Guest








PostPosted: Sat Nov 04, 2006 4:53 am     Reply with quote

jecottrell Thanks For Xtal note really i was working on the program without notice the xtal value

Thanks again but i use the same technique in Borland C++ Builder to perform two action with same button !! and here it's not working
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sat Nov 04, 2006 4:57 am     Reply with quote

You need to figure out what you're doing. Are you trying to get code working on a PIC or what?

If you're using a 20MHz crystal should also use the HS fuse and not the XT.

A 500mS debounce delay is too long also.

Make some effort here and give a detailed account of what you are doing. Otherwise you're going to on your own.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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