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

push buttons interfacing
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 09, 2005 3:04 pm     Reply with quote

Quote:
even if i dont press key it shows me text inside the pressed key if loop.

That's because when the key is pressed, the PIC reads a logic '0'
on the pin. When the key is not pressed (the normal state) it reads
a logic '1'.

So you need to change your test. Look for a logic '0'.
Change it to this:

if(input(PIN_B4) == 0 )
{



}
csshah



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

pushbuttons are low to high
PostPosted: Thu Mar 10, 2005 8:37 am     Reply with quote

hey Mark
thanks for ur help so far. the pushbuttons, I am using are kept low and when pressed they go high, so i think that logic is ok but I think I having trouble with the delay after the button is pressed.

one question
the crystal on board is 19.6 MHz and in the program i specified clock as 20000000, so can it create problem?? i tried changing it to 19600000 but then I am not getting proper characters on the LCD.

I am pasting my code here I dont where there is delay mismatch. it is displaying message but sometimes in between it shows the message inside the button press for loop and even when i press it, the message is displayed 3-4 times instead of 1.

Code:

#include <18F8720.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

#include <stdio.h>
#include <LCD_4bit.c>
setup_adc_ports(NO_ANALOGS);
//output_B(0x00);
//SET_TRIS_B(0xFF);

void main() {
   
 
   
   short int i,X=1,Y=1,current,page;
   lcd_init();
   delay_ms(800);
   output_low(PIN_B4);
   
   


  Xa: delay_ms(80);
      lcd_putc("\f    ** text1 **\n");
      lcd_putc("       text2");
      delay_ms(80);


while(1)
  {
   //output_low(PIN_B4);
   
   if(input(PIN_B4))       // Read the switch pin.
   {
   delay_ms(80); 
   lcd_putc("\f pressed"); 
    delay_ms(80);
   output_low(PIN_B4);
   delay_ms(80);
   goto Xa;
   }
   

   else{   
        goto Xa;   
//lcd_putc("\f    ** text1 **\n");
   //lcd_putc("       text2");
//   delay_ms(100);
  }
//output_low(PIN_B4);
}

}



mosofo
Guest







re
PostPosted: Tue Aug 11, 2009 12:26 am     Reply with quote

maby you can try "trisb = 1" to force "b6" t be an input;
just try it. Rolling Eyes
Gabriel



Joined: 03 Aug 2009
Posts: 1085
Location: Panama

View user's profile Send private message

PostPosted: Tue Aug 11, 2009 9:51 am     Reply with quote

hi,

for debouncing what ive used succesfully a few times is the following logic:


read a pin, save the state, and repeat... if you get 5 consecutive reads and they are all the same.. the switch is debounced... if i remember correctly i only waited for 3 consecutive "same_state" reads..and it worked fine... i guess it might depend on your hardware... and if you have any issues wait 7 or 8 reads instead...

that way you avoid using delays.. which might bring the added bonus of your program running faster ("ms" if anything)...since your not using a speculated delay.
no one "really" knows how long a switch takes to debounce...since no switch is alike...so the debounce delay is speculated...

hope that helps...

Gabriel
_________________
CCS PCM 5.078 & CCS PCH 5.093
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 Previous  1, 2
Page 2 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