#Include XC.H
#Include XC.H
h>
#include <pic16f877a.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial
Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for
programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM
code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write
protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code
protection off)
//END CONFIG
// Définition des broches pour le LCD
#define RS RC3
#define RW RC4
#define EN RC5
char key_pressed = 0;
void lcd_initialise() {
lcd_command(0x38);
lcd_command(0x06);
lcd_command(0x0C);
lcd_command(0x01);
}
void keypad() {
key_pressed = 0;
C1 = 1; C2 = 0; C3 = 0;
C1 = 0; C2 = 1; C3 = 0;
C1 = 0; C2 = 0; C3 = 1;
void main(void) {
char motor1_on = 0;
char motor2_on = 0;
lcd_initialise();
lcd_command(0x80);
lcd_string("Entrez le mot", 13);
lcd_command(0xC0);
lcd_string("de passe:", 10);
while (1) {
for (i = 0; i < 6; i++) {
while (1) {
keypad();
if (key_pressed) {
enteredPassword[i] = key_pressed;
lcd_data('*');
break;
}
}
}
enteredPassword[6] = '\0';
if (strcmp(enteredPassword, password) == 0) {
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Mot de passe vrai", 17);
lcd_command(0xC0);
lcd_string("Choisissez M1/M2:", 17);
choice_made = true;
} else if (key_pressed == '2') {
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Motor 2 active", 15);
motor1_on = 0;
motor2_on = 1;
choice_made = true;
}
}
} else {
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Mot de passe faux", 17);
__delay_ms(2000);
lcd_command(0x01);
lcd_command(0x80);
lcd_string("KEYPAD:", 7);
lcd_command(0xC0);
key_pressed = 0;
}
}