Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <p18F4550.h>
- #include <delays.h>
- #include <string.h>
- #include <math.h>
- #include <i2c.h>
- // Configuração do microcontrolador para execução de instruções
- #pragma config FOSC = HS /// EXTERN CLOCK 8MHZ
- #pragma config IESO = OFF /// INTERNAL/EXTERNAL OSCILATOR DISABLE
- #pragma config PWRT = OFF /// DISABLE POWER-UP TIMER
- #pragma config BORV = 3 /// BROWN-OUT RESET MINIMUM
- #pragma config WDT = OFF /// DISABLE WATCHDOG TIMER
- #pragma config WDTPS = 32768 /// WATCHDOG TIMER 32768s
- #pragma config MCLRE = OFF /// MASTER CLEAR PIN (RE3) DISBALE
- #pragma config LPT1OSC = OFF /// TIMER1 LOW POWER OPERATION
- #pragma config PBADEN = OFF /// PORTB.RB0,1,2,3,4 AS I/O DIGITAL
- #pragma config STVREN = ON /// STACK FULL/UNDERFLOW CAUSE RESET
- #pragma config LVP = OFF /// DISABLE LOW VOLTAGE PROGRAM (ICSP DISABLE)
- /**************** PINAGEM DO LCD****************/
- #define LCD_RS PORTCbits.RC0
- #define LCD_EN PORTCbits.RC1
- #define LCD_DATA LATD
- #define LCD_CLEAR 0x01
- #define LCD_CURSOR_OFF 0x06
- #define FIRST_ROW 0x80
- #define SECOND_ROW 0xC0
- #define SDA PORTCbits.RC2
- #define SCL PORTCbits.RC4
- /**************** PINAGEM DO TECLADO****************/
- #define Linha_1 LATBbits.LATB4
- #define Linha_2 LATBbits.LATB5
- #define Linha_3 LATBbits.LATB6
- #define Linha_4 LATBbits.LATB7
- #define Coluna_1 PORTBbits.RB3
- #define Coluna_2 PORTBbits.RB2
- #define Coluna_3 PORTBbits.RB1
- //matriz de credenciais
- char usuarios[10][4] = {"1234", "5678"};
- char senhas[10][4] = {"1234", "5678"};
- //matriz de logs
- char logs[10][8];
- /******************************************************************************/
- //variáveis auxilixares
- unsigned char ram_msg[16];
- char funcao[6] = ">";
- char cred[6] = "N:";
- char credencial[4];
- char asteriscos[6] = "";
- unsigned char senha[4] = "0000";
- int seg;
- int min;
- int hr;
- /******************************************************************************/
- /*********************Protótipos das função do LCD ****************************/
- /******************************************************************************/
- void Delay_ms(unsigned int time); //função de delay
- void Lcd4_Init(void); //função que inicia LCD
- void Lcd4_Cmd(unsigned char value);
- void Lcd4_Write(unsigned char value);
- void Lcd4_Write_Text(unsigned char msg[]);
- void Lcd4_segundaLinha(unsigned char msg[], int flag);
- unsigned char * CopyConstToRAM(unsigned char *dest, const rom unsigned char * src);
- unsigned char * CopyToRAM(unsigned char *dest, unsigned char * src);
- void Clear_Destination_Buffer(void);
- /******************************************************************************/
- /*************************** Protótipos dos Teclado ***************************/
- /******************************************************************************/
- unsigned char Varre_Teclado(unsigned char flag); //Método que varre o teclado
- /******************************************************************************/
- /************************* Protótipos do Relógio ******************************/
- /******************************************************************************/
- char le_relogio();
- void inicializa_SCL_SDA();
- void start_SCL_SDA();
- void stop_SCL_SDA();
- void indica_leitura_relogio();
- void indica_leitura_segudos();
- void indica_leitura_minutos();
- void indica_leitura_horas();
- int le_segundos();
- int le_minutos();
- int le_horas();
- char convertNumero(int numero);
- /******************************************************************************/
- /**********************Protótipos das Funções Lógicas *************************/
- /******************************************************************************/
- void selecionaFuncoes();
- void primeiraLinha(unsigned char var[]);
- void segundaLinha(unsigned char var[], int cont);
- void primeiraSegundaLinha(unsigned char var[], unsigned char var2[]);
- void cadastro();
- void acesso();
- void excluir();
- int verificaDados(char matricula[4], char senha[4]);
- void gravaLog(char matricula[4], char hora[8]);
- void metodoLogs();
- /******************************************************************************/
- /*************************** MÉTODO PRINCIPAL *********************************/
- /******************************************************************************/
- void main() {
- TRISB = 0b00001111;
- TRISC = 0b11111100;
- while (1) {
- acesso();
- }
- }
- /******************************************************************************/
- /***********************DEFINIÇÕES DAS FUNÇÕES LÓGICAS*************************/
- /******************************************************************************/
- //método que identifica função selescionada
- int verificaDados(char matricula[4], char senha[4]) {
- int flag = 0;
- int i, j, cont = 0;
- char letra, pass;
- //pecorre a matriz de credenciais
- for (i = 0; i < 10; i++) {
- for (j = 0; j < 4; j++) {
- letra = matricula[j];
- pass = senha[j];
- if (usuarios[i][j] == letra && senhas[i][j] == pass) {
- cont++;
- }
- if (cont == 4)
- i = 10;
- matricula + 1;
- senha + 1;
- }
- }
- if (cont == 4)
- flag = 1;
- return flag;
- }
- void gravaLog(char matricula[4], char hora[8]) {
- int aux = 0;
- int i, j, cont = 0;
- char letra;
- //pecorre a matriz de credenciais
- for (i = 0; i < 10; i++) {
- for (j = 0; j < 4; j++) {
- letra = matricula[j];
- if (usuarios[i][j] == letra) {
- cont++;
- }
- //para laço
- if (cont == 4)
- {
- aux=i;
- i = 10;
- }
- matricula + 1;
- }
- }
- //grava horas no log
- if (cont == 4)
- {
- logs[aux][0] = hora[0];
- logs[aux][1] = hora[1];
- logs[aux][2] = ':';
- logs[aux][3] = hora[3];
- logs[aux][4] = hora[4];
- logs[aux][5] = ':';
- logs[aux][6] = hora[6];
- logs[aux][7] = hora[7];
- }
- }
- void selecionaFuncoes() {
- int cont = 0;
- primeiraSegundaLinha("FUNCAO", ">");
- //zerando cred, senha e funcao
- for (cont = 1; cont < 6; cont++) {
- funcao[cont] = ' ';
- }
- //digitos da função
- for (cont = 1; cont < 3; cont++) {
- funcao[cont] = Varre_Teclado(0);
- segundaLinha(funcao, 6);
- }
- //cadastrar
- if (funcao[1] == '9' && funcao[2] == '9') {
- cadastro();
- }
- //excluir
- if (funcao[1] == '9' && funcao[2] == '8') {
- excluir();
- }
- //logs
- if (funcao[1] == '9' && funcao[2] == '7') {
- metodoLogs();
- }
- }
- //método que busca log
- void metodoLogs()
- {
- int cont = 0;
- int parada = 0;
- int i, j, k;
- char l[8];
- for (i = 2; i < 6; i++) {
- cred[i] = ' ';
- asteriscos[i - 2] = ' ';
- }
- primeiraSegundaLinha("MATRICULA DO LOG", "N:");
- for (i = 2; i < 6; i++) {
- if (cred[i - 1] == '#') {
- parada = 1;
- break;
- }
- cred[i] = Varre_Teclado(0);
- segundaLinha(cred, 6);
- }
- if (parada == 0) {
- for (i = 0; i < 10; i++) {
- for (j = 0; j < 4; j++) {
- if (usuarios[i][j] == cred[j + 2]) {
- cont++;
- }
- }
- if(cont == 4)
- {
- cont = 0;
- for(k=0; k<8; k++)
- {
- l[k] = logs[i][k];
- }
- }
- primeiraLinha("HORA DE ACESSO");
- segundaLinha(l, 8);
- Delay10KTCYx(90);
- break;
- }
- cont = 0;
- }
- }
- //método que imprime mensagem na primeira e segunda linha
- void primeiraSegundaLinha(unsigned char var[], unsigned char var2[]) {
- Lcd4_Init(); //inicia display
- Lcd4_Cmd(LCD_CLEAR); //zera cursos do display
- Lcd4_Cmd(LCD_CURSOR_OFF); //desliga bit do cursor
- Lcd4_Cmd(LCD_CLEAR);
- CopyConstToRAM(ram_msg, var); //método que copia string para memória do lcd
- Lcd4_Write_Text(ram_msg);
- Delay_ms(10);
- Lcd4_Cmd(SECOND_ROW); //pula uma linha
- CopyConstToRAM(ram_msg, var2);
- Lcd4_Write_Text(ram_msg);
- }
- //método que imprime mensagem na primeira linha
- void primeiraLinha(unsigned char var[]) {
- Lcd4_Init(); //inicia display
- Lcd4_Cmd(LCD_CLEAR); //zera cursos do display
- Lcd4_Cmd(LCD_CURSOR_OFF); //desliga bit do cursor
- Lcd4_Cmd(LCD_CLEAR);
- CopyConstToRAM(ram_msg, var); //método que copia string para memória do lcd
- Lcd4_Write_Text(ram_msg);
- Delay_ms(10);
- }
- //método que imprime mensagem na segunda linha
- void segundaLinha(unsigned char var[], int cont) {
- Lcd4_Cmd(SECOND_ROW); //pula uma linha
- CopyToRAM(ram_msg, var);
- Lcd4_segundaLinha(ram_msg, cont);
- }
- //método que cadastra nova credencial
- void cadastro() {
- int i, j;
- int cont;
- int parada = 0;
- ;
- //zerando cred, senha
- for (cont = 2; cont < 6; cont++) {
- cred[cont] = ' ';
- asteriscos[cont - 2] = ' ';
- }
- primeiraSegundaLinha("NOVA MATRICULA", "N:");
- for (cont = 2; cont < 6; cont++) {
- if (cred[cont - 1] == '#') {
- parada = 1;
- break;
- }
- cred[cont] = Varre_Teclado(0);
- segundaLinha(cred, 6);
- }
- //passando valores de cred para credencial
- for (i = 0; i < 4; i++)
- credencial[i] = cred[i + 2];
- if (cont == 6) {
- primeiraLinha("SENHA:");
- Lcd4_Cmd(SECOND_ROW); //pula uma linha
- CopyToRAM(ram_msg, asteriscos);
- Lcd4_Write_Text(ram_msg);
- for (cont = 0; cont < 4; cont++) {
- if (senha[cont - 1] == '#') {
- parada = 1;
- break;
- }
- senha[cont] = Varre_Teclado(0);
- asteriscos[cont] = '*';
- segundaLinha(asteriscos, 6);
- }
- if (parada == 0) {
- //preenche o vetor usuarios com um usuário novo
- for (i = 0; i < 10; i++) {
- if (usuarios[i][0] == '\0') {
- for (j = 0; j < 4; j++) {
- usuarios[i][j] = credencial[j];
- }
- if (j == 4)
- i = 10;
- }
- }
- //preenche o vetor senhas com uma senha nova
- for (i = 0; i < 10; i++) {
- if (senhas[i][0] == '\0') {
- for (j = 0; j < 4; j++) {
- senhas[i][j] = senha[j];
- }
- if (j == 4)
- i = 10;
- }
- }
- }
- }
- }
- //método de exclusão
- void excluir() {
- int cont = 0;
- int parada = 0;
- int i, j;
- for (i = 2; i < 6; i++) {
- cred[i] = ' ';
- asteriscos[i - 2] = ' ';
- }
- primeiraSegundaLinha("APAGAR MATRICULA", "N:");
- for (i = 2; i < 6; i++) {
- if (cred[i - 1] == '#') {
- parada = 1;
- break;
- }
- cred[i] = Varre_Teclado(0);
- segundaLinha(cred, 6);
- }
- if (parada == 0) {
- for (i = 0; i < 10; i++) {
- for (j = 0; j < 4; j++) {
- if (usuarios[i][j] == cred[j + 2]) {
- cont++;
- }
- }
- if (cont == 4) {
- for (j = 0; j < 4; j++) {
- usuarios[i][j] = '\0';
- senhas[i][j] = '\0';
- }
- primeiraSegundaLinha("MATRICULA", "APAGADA...");
- Delay10KTCYx(50);
- break;
- }
- cont = 0;
- }
- }
- }
- //método da função acesso
- void acesso() {
- int cont;
- int flag = 0;
- //zerando cred e senha
- for (cont = 2; cont < 6; cont++) {
- cred[cont] = ' ';
- asteriscos[cont - 2] = ' ';
- }
- primeiraSegundaLinha("MATRICULA", "N:");
- for (cont = 2; cont < 6; cont++) {
- if (cred[cont - 1] == '#') {
- selecionaFuncoes();
- break;
- }
- cred[cont] = Varre_Teclado(0);
- segundaLinha(cred, 6);
- }
- if (cont == 6) {
- primeiraSegundaLinha("SENHA:", " ");
- for (cont = 0; cont < 4; cont++) {
- if (senha[cont - 1] == '#') {
- cadastro();
- break;
- }
- senha[cont] = Varre_Teclado(0);
- asteriscos[cont] = '*';
- segundaLinha(asteriscos, 6);
- }
- //passando dados de cred para credencial
- for (cont = 2; cont < 6; cont++) {
- credencial[cont - 2] = cred[cont];
- }
- //pecorre a matriz de credenciais
- if (verificaDados(credencial, senha) == 1) {
- //ALANE
- char hora[8];
- hora[0] = convertNumero(le_segundos()/10);
- hora[1] = convertNumero(le_segundos()%10);
- hora[2] = ':';
- hora[3] = convertNumero(le_minutos()/10);
- hora[4] = convertNumero(le_minutos()%10);
- hora[5] = ':';
- hora[6] = convertNumero(le_horas()/10);
- hora[7] = convertNumero(le_horas()%10);
- //ALANE
- gravaLog(credencial, hora);
- flag = 1;
- }
- if (flag == 1) {
- primeiraSegundaLinha("ACESSO", "PERMITIDO...");
- Delay10KTCYx(50);
- } else {
- primeiraSegundaLinha("DADOS", "INCORRETOS...");
- Delay10KTCYx(50);
- }
- }
- }
- /******************************************************************************/
- /*******************************DEFINIÇÕES DO RELÓGIO**************************/
- /******************************************************************************/
- void inicializa_SCL_SDA() {
- SDA = 1;
- SCL = 1;
- }
- void start_SCL_SDA() {
- SDA = 0;
- SCL = 0;
- }
- void stop_SCL_SDA() {
- SDA = 1;
- SCL = 1;
- }
- void indica_leitura_relogio() {
- start_SCL_SDA();
- // DELAY
- SDA = 1; // BIT MSB
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 6
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 5
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 4
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 3
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 2
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 1
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT DE LEITURA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // PARADA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- }
- void indica_leitura_segudos() {
- // DELAY
- SDA = 0; // BIT MSB
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 6
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 5
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 4
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 3
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 2
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT 1
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // BIT DE LEITURA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 0; // PARADA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- }
- int le_segundos() {
- int i;
- int segundos = 0;
- int aux = 0;
- indica_leitura_segudos();
- for(i = 6; i >= 0; i++) {
- if(SDA == 1) {
- aux = (int)pow(2, i);
- segundos += aux;
- }
- }
- return segundos;
- }
- void indica_leitura_minutos() {
- // DELAY
- SDA = 1; // BIT MSB
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 6
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 5
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 4
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 3
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 2
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT 1
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // BIT DE LEITURA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 1; // PARADA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- }
- int le_minutos() {
- int i;
- int minutos = 0;
- int aux = 0;
- indica_leitura_minutos();
- for(i = 6; i >= 0; i++) {
- if(SDA == 1) {
- aux = (int)pow(2, i);
- minutos += aux;
- }
- }
- return minutos;
- }
- void indica_leitura_horas() {
- // DELAY
- SDA = 2; // BIT MSB
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // BIT 6
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // BIT 5
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // BIT 4
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // BIT 3
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // BIT 2
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // BIT 1
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // BIT DE LEITURA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- SDA = 2; // PARADA
- // CLOCK INICIO
- SCL = 1;
- // DELAY
- SCL = 0;
- // CLOCK FIM
- }
- int le_horas() {
- int i;
- int horas = 0;
- int aux = 0;
- indica_leitura_horas();
- for(i = 6; i >= 0; i++) {
- if(SDA == 1) {
- aux = (int)pow(2, i);
- horas += aux;
- }
- }
- return horas;
- }
- char le_relogio() {
- indica_leitura_segudos();
- seg = le_segundos();
- indica_leitura_minutos();
- min = le_minutos();
- indica_leitura_horas();
- hr = le_horas();
- }
- char convertNumero(int numero)
- {
- if(numero == 0)
- return '0';
- if(numero == 0)
- return '1';
- if(numero == 0)
- return '2';
- if(numero == 0)
- return '3';
- if(numero == 0)
- return '4';
- if(numero == 0)
- return '5';
- if(numero == 0)
- return '6';
- if(numero == 0)
- return '7';
- if(numero == 0)
- return '8';
- }
- /******************************************************************************/
- /**************************DEFINIÇÕES DO TECLADO*******************************/
- /******************************************************************************/
- //método que varre o teclado
- unsigned char Varre_Teclado(unsigned char flag) {
- do {
- Linha_1 = 1;
- Linha_2 = 0;
- Linha_3 = 0;
- Linha_4 = 0;
- if (Coluna_1) {
- while (Coluna_1 == 1) {
- };
- return '1';
- }
- if (Coluna_2) {
- while (Coluna_2 == 1) {
- };
- return '2';
- }
- if (Coluna_3) {
- while (Coluna_3 == 1) {
- };
- return '3';
- }
- Linha_1 = 0;
- Linha_2 = 1;
- Linha_3 = 0;
- Linha_4 = 0;
- if (Coluna_1) {
- while (Coluna_1 == 1) {
- };
- return '4';
- }
- if (Coluna_2) {
- while (Coluna_2 == 1) {
- };
- return '5';
- }
- if (Coluna_3) {
- while (Coluna_3 == 1) {
- };
- return '6';
- }
- Linha_1 = 0;
- Linha_2 = 0;
- Linha_3 = 1;
- Linha_4 = 0;
- if (Coluna_1) {
- while (Coluna_1 == 1) {
- };
- return '7';
- }
- if (Coluna_2) {
- while (Coluna_2 == 1) {
- };
- return '8';
- }
- if (Coluna_3) {
- while (Coluna_3 == 1) {
- };
- return '9';
- }
- Linha_1 = 0;
- Linha_2 = 0;
- Linha_3 = 0;
- Linha_4 = 1;
- if (Coluna_1) {
- while (Coluna_1 == 1) {
- };
- return '*';
- }
- if (Coluna_2) {
- while (Coluna_2 == 1) {
- };
- return '0';
- }
- if (Coluna_3) {
- while (Coluna_3 == 1) {
- };
- return '#';
- }
- } while (flag == 0);
- return -1;
- }
- /******************************************************************************/
- /******************************DEFINIÇÕES DO LCD*******************************/
- /******************************************************************************/
- //Delay
- void Delay_ms(unsigned int time) {
- unsigned int first;
- unsigned int second;
- for (first = 0; first < time; first++) {
- for (second = 0; second < 650; second++) {
- Delay1TCY();
- }
- }
- }
- //Controla comandos do display
- void Lcd4_Cmd(unsigned char value) {
- LCD_RS = 0;
- LCD_DATA = (value & 0xF0);
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- LCD_DATA = ((value << 4) & 0xF0);
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- Delay_ms(1);
- }
- //Escreve uma letra no lcd
- void Lcd4_Write(unsigned char value) {
- LCD_RS = 1;
- LCD_DATA = (value & 0xF0);
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- LCD_DATA = ((value << 4) & 0xF0);
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- Delay_ms(1);
- }
- //Escreve um texto no lcd
- void Lcd4_Write_Text(unsigned char msg[]) {
- while (*msg) {
- Lcd4_Write(*msg);
- msg++;
- }
- }
- //Escreve um texto no lcd
- void Lcd4_segundaLinha(unsigned char msg[], int flag) {
- int cont = 0;
- while (*msg) {
- if (cont < flag) {
- Lcd4_Write(*msg);
- msg++;
- cont++;
- } else {
- break;
- }
- }
- }
- //Inicia lcd
- void Lcd4_Init(void) {
- TRISD = 0x00;
- TRISCbits.TRISC0 = 0;
- TRISCbits.TRISC1 = 0;
- LCD_RS = 0; //Command Register
- LCD_EN = 0;
- LCD_DATA = 0x30;
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- Delay_ms(1);
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- Delay_ms(1);
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- Delay_ms(1);
- Delay_ms(1);
- LCD_DATA = 0x20; // Four bit mode
- LCD_EN = 1;
- Delay_ms(1);
- LCD_EN = 0;
- Delay_ms(1);
- Lcd4_Cmd(0x28);
- Lcd4_Cmd(0x0C);
- Lcd4_Cmd(0x01);
- Lcd4_Cmd(0x06);
- }
- //Copia para a memória do lcd
- unsigned char * CopyConstToRAM(unsigned char *dest, const rom unsigned char * src) {
- Clear_Destination_Buffer();
- for (; *dest++ = *src++;)
- ;
- return dest;
- }
- //Copia para a memória do lcd
- unsigned char * CopyToRAM(unsigned char *dest, unsigned char * src) {
- Clear_Destination_Buffer();
- for (; *dest++ = *src++;)
- ;
- return dest;
- }
- //Apaga memória do lcd
- void Clear_Destination_Buffer() {
- unsigned char i;
- for (i = 0; i < 16; i++) {
- ram_msg[i] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement