Вы находитесь на странице: 1из 5

Tranca Eletrnica utilizando o

PIC16F877A

A fechadura eltrica (usada nos portes eletrnicos) ser aberta caso o usurio
digitar a senha correta. A senha um nmero entre 0 e 999999. O usurio
possuir um nmero limitado de tentativas (3 tentativas), e aps o sistema ir
entrar em bloqueio( led vermelho acender). A senha ter que ser definida na
primeira vez. Pressione o boto S1, digite a senha e aperte a tecla ENTER. Voc
poder
alterar
a
senha
quantas
vezes
quiser.
A fechadura chaveada pelo rel.
A tecla C do teclado usado para limpar os dgitos do display.

Nesse projeto utilizou-se um teclado 4x3, um display LCD 20x2 e para o


microcontrolador
foi
utilizado
um
clock
de
4Mhz.

DOWNLOAD:
Projeto: Tranca_Eletronica.rar
CDIGO-FONTE: (Compilador MikroC PRO PIC)
1. sbit
2. sbit
3. sbit
4. sbit
5. sbit
6. sbit
7. sbit
8. sbit
9. sbit
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.

LCD_RS at RC4_bit;
LCD_EN at RC5_bit;
LCD_D4 at RC0_bit;
LCD_D5 at RC1_bit;
LCD_D6 at RC2_bit;
LCD_D7 at RC3_bit;
LCD_RS_Direction at TRISC4_bit;
LCD_EN_Direction at TRISC5_bit;
LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
char keypadPort at PORTD;
char
char
char
char
char

kp;
cliques = 0;
tentativas = 0;
*senha = "000000";
*textos[6] = {"
Senha OK
",
"
Senha Errada
",
"
Nova Senha OK
",
"
Digite a senha
",
" Digite a nova senha",
"
Fim
"};

char *Ptr1, *Ptr2;

28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.

char CompararSenha()
{
char i = 0;
for(i=0; i < 6; i++)
{
if(senha[i] != Eeprom_Read(i)) return(0);
}
return (1);
}
void GravarSenhaNaEeprom()
{
char i;
for(i=0; i < 6; i++)
{
Eeprom_Write(i, senha[i]);
}
}
void LimparSenha()
{
char i;
for(i=0; i < 6; i++)
{
senha[i] = '0';
}
}
void main()
{
char i;
TRISB=0b10000000;
PORTB=0;
Keypad_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Ptr2 = textos[3];
Lcd_Out(1, 1, Ptr2);
while(1)
{
if(tentativas < 3)
{
kp = Keypad_Key_Click();
if(kp)
{
if(kp % 4 == 0)
{
//Faz Nada
}
else if(kp == 13) //Limpar
{
LimparSenha();
cliques = 0;

89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.

}
else if(kp == 15) //Enter
{
cliques = 0;
if(PORTB.F7 == 1) //Verificar entrada da senha
{
if(CompararSenha()) //Sucesso
{
PORTB.F0 = ~PORTB.F0;
Ptr1 = textos[0];
LimparSenha();
}
else
//Senha errada
{
tentativas++;
Ptr1 = textos[1];
LimparSenha();
}
}
else //Gravar nova senha
{
GravarSenhaNaEeprom();
Ptr1 = textos[2];
LimparSenha();
}
Lcd_Out(1, 1, Ptr1);
Delay_ms(2000);
}
else //Numeros
{
switch(kp)
{
case 1: kp = 49; break; //1
case 2: kp = 50; break; //2
case 3: kp = 51; break; //3
case 5: kp = 52; break; //4
case 6: kp = 53; break; //5
case 7: kp = 54; break; //6
case 9: kp = 55; break; //7
case 10: kp = 56; break;//8
case 11: kp = 57; break;//9
case 14: kp = 48; break;//0
}
if(cliques < 6)
{
//Digitando a senha
for(i=0; i < 5; i++)
senha[i] = senha[i+1];
senha[5] = kp;
}
}
}
else
{
if(PORTB.F7) Ptr2 = textos[3];
else Ptr2 = textos[4];
}
}

150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.

else
{
Ptr2 = textos[5];
PORTB.F1 = 1;
}
Lcd_Out(1,1, Ptr2);
Lcd_Out(2,8, senha);
Delay_ms(100);
}
}

Вам также может понравиться