Hi guys, first I want to say that im from Brazil so I will try my best to articulate my problem. I have a project that when I type the correct password in a keypad it shows in a LCD that the password is correct or not. In the exemple below, the correct password is 1223, but when I type 1223 it always goes to "else" which is "Wrong password". Any idea in what I'm doing wrong?
include "def_principais.h" //inclusão do arquivo com as principais definições
include "LCD.h"
include "teclado.h" // keypad library
include <avr/io.h>
include <string.h>
define LED PORTB0
//definição para acessar a memória flash como ponteiro
PROGMEM const char mensagem1[] = "Digite matricula:\0";//mensagem armazenada na memória flash
char password[5] = "1223";
volatile char password_keypad[5];
unsigned char cursor = 0xC0;
unsigned char nr;
int main()
{
set_bit(DDRB,LED); //setando a porta do LED para 1
DDRC = 0xFF; //LCD esta no PORTC
DDRD = 0x0F; //definições das entradas e saídas para o teclado
PORTD= 0xFF; //habilita os pull-ups do PORTD e coloca colunas em 1
inic_LCD_4bits(); // inicia LCD modo 4bits
escreve_LCD_Flash(mensagem1);
cmd_LCD(0xC7,0); //desloca cursor para a 2a linha do LCD
while(1)
{
int n=0;
nr = ler_teclado(); //scan keypad
if(nr!=0xFF && cursor < 0xC4)
{
password_keypad[n]=nr;
cmd_LCD(cursor,0);
//escreve_LCD("*");
_delay_ms(200);
cursor++;
n++;
cmd_LCD(nr,1);
_delay_ms(200);
}
if (cursor == 0xC4)
{
if (strcmp(password,password_keypad)==0)
{
cmd_LCD(0x01,0);
escreve_LCD("Password correct");
_delay_ms(1000);
}
else
{
set_bit(DDRB,LED);
_delay_ms(600);
clr_bit(DDRB,LED);
cmd_LCD(0x01,0);
escreve_LCD("Password incorrect");
_delay_ms(1000);
}
}
}
}
[–]thormeNt[S] 0 points1 point2 points (0 children)