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

Enter the correct code to turn led on... problem

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



Joined: 26 Aug 2011
Posts: 6

View user's profile Send private message

Enter the correct code to turn led on... problem
PostPosted: Mon Sep 26, 2011 1:30 pm     Reply with quote

The objective of my project is to turn led c0 when I enter the correct code so first I'm trying code of one character ("5") on keypad but its not working. Another question what if I have to enter for example the code "123" on keypad to turn the led on ? What do I have change in my code?
Code:

#include<16f887.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=2000000)

#define use_portb_kbd TRUE
#include<lcd.c>
#include<kbd.c>

void main()
{
char k;

lcd_init();
kbd_init();
lcd_putc("\f ready....\n");

while (true)
{
 k=kbd_getc();
 if(k!=0)
    if(k=='*')
       lcd_putc('\f');
    else
       lcd_putc(k);
         
if(k=='5')
  output_high(pin_c0);
else
  output_low(pin_c0);
}
}

_________________
AYMAN
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 3:01 pm     Reply with quote

Quote:
#use delay(clock=2000000)

You have this set for 2 MHz. You probably want 20 MHz.
Hint: it's easier and more reliable to do it this way:
Code:

#use delay(clock=20M)
 


Quote:

What if I have to enter for example the code "123" on keypad to turn the led on ?

Keypad password demo program:
http://www.ccsinfo.com/forum/viewtopic.php?t=45935
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 3:52 pm     Reply with quote

Quote:
The objective of my project is to turn led c0 when I enter the correct code so first I'm trying code of one character ("5") on keypad but its not working.
Just a hint for why your program might not work as expected: your led is blinking so fast that you won't see it. Try adding a delay. Not the perfect solution, but it will do for a simple test:
Code:
if(k=='5')
{
  output_high(pin_c0);
  delay_ms(300);
}
else
  output_low(pin_c0);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 4:03 pm     Reply with quote

Another option would be to change it so '5' turns the LED on and '4' turns
it off:
Code:

if(k=='5')
  output_high(pin_c0);
if(k=='4')
  output_low(pin_c0);
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