View previous topic :: View next topic |
Author |
Message |
GSHB0760
Joined: 26 Feb 2009 Posts: 3
|
applications of lcd |
Posted: Tue Mar 03, 2009 10:30 am |
|
|
Hi everybody. I have worked about password lock program with LCD and keypad. But I can not do things what I want. I am using pic16f877. I can see the number on LCD one by one but I wanted can write them side by side. For example I will pass a password and I will see four stars on lcd and will should save on EEPROM memory and will call the password again. Thanks in advance.
Code: |
#define use_portb_lcd TRUE
#include <lcd.c>
#define sut1 pin_d0
#define sut2 pin_d1
#define sut3 pin_d2
#define sut4 pin_d3
#define sat1 pin_d4
#define sat2 pin_d5
#define sat3 pin_d6
#define sat4 pin_d7
char tus;int sonuc;
char keypad_oku()
{
output_d(0x00);
output_high(sat1);
if (input(sut1))
{delay_ms(20); tus=1;}
if (input(sut2))
{delay_ms(20); tus=2;}
if (input(sut3))
{delay_ms(20); tus=3;}
if (input(sut4))
{delay_ms(20); tus=0xA;}
output_low(sat1);
output_high(sat2);
if (input(sut1))
{delay_ms(20); tus=4;}
if (input(sut2))
{delay_ms(20); tus=5;}
if (input(sut3))
{delay_ms(20); tus=6;}
if (input(sut4))
{delay_ms(20); tus=0xB;}
output_low(sat2);
output_high(sat3);
if (input(sut1))
{delay_ms(20); tus=7;}
if (input(sut2))
{delay_ms(20); tus=8;}
if (input(sut3))
{delay_ms(20); tus=9;}
if (input(sut4))
{delay_ms(20); tus=0xC;}
output_low(sat3);
output_high(sat4);
if (input(sut1))
{delay_ms(20); tus=0xE;}
if (input(sut2))
{delay_ms(20); tus=0;}
if (input(sut3))
{delay_ms(20); tus=0xF;}
if (input(sut4))
{delay_ms(20); tus=0xD;}
output_low(sat4);
return tus;
}
int tus_tarama()
{output_d(0x00);
output_high(sut1);
if((((sut1)|(sut2))|(sut3))|(sut4))
{delay_ms(20);sonuc=1;}
output_low(sat1);
output_high(sat2);
if((((sut1)|(sut2))|(sut3))|(sut4))
{delay_ms(20);sonuc=1;}
output_low(sat2);
output_high(sat3);
if((((sut1)|(sut2))|(sut3))|(sut4))
{delay_ms(20);sonuc=1;}
output_low(sat3);
output_high(sat4);
if((((sut1)|(sut2))|(sut3))|(sut4))
{delay_ms(20);sonuc=1;}
output_low(sat4);
return sonuc;
}
void main ()
{
set_tris_b(0x01);
set_tris_d(0x0f);
lcd_init();
printf(lcd_putc,"\fbasilan tus=");
while(1)
{lcd_send_byte(0,0xc4);
if(tus_tarama()){
printf(lcd_putc,"%d%d%d%d",keypad_oku(),keypad_oku(),keypad_oku(),keypad_oku());
}
else{
printf(lcd_putc,"\nenter the password...");}}} |
|
|
![](templates/subSilver/images/spacer.gif) |
Sydney
Joined: 13 Feb 2009 Posts: 71
|
|
Posted: Tue Mar 03, 2009 12:36 pm |
|
|
Code: | if(input(sut1)||input(sut2)||input(sut3)||input(sut4)) |
The easiest way is probably to save the keypresses in a string, increment a pointer to the string, and update the display every keypress.
Here you could do
Code: | if (input(sut1)) {
delay_ms(20);
return 1;
} |
same for the other function, unless you specifically want the keypress priority in the current order. |
|
![](templates/subSilver/images/spacer.gif) |
GSHB0760
Joined: 26 Feb 2009 Posts: 3
|
|
Posted: Tue Mar 03, 2009 1:18 pm |
|
|
Thanks for your reply. But my problem is about the program's algorithm.
I can press the keys. I want to write password that has four-digits.
When I press the keypad, I want to show password as four digits.
Thanks in advance |
|
![](templates/subSilver/images/spacer.gif) |
Sydney
Joined: 13 Feb 2009 Posts: 71
|
|
Posted: Tue Mar 03, 2009 3:06 pm |
|
|
Yes I understand that, but your code is very basic, there is no switch debouncing, no repeat handling (the keys will repeat every 20ms), and it has a few simple errors.
There are already keypad drivers in the code forum, and even this example http://www.ccsinfo.com/forum/viewtopic.php?t=28022&start=14 which with a few modifications will do exactly what you want. |
|
![](templates/subSilver/images/spacer.gif) |
|