top of page

Algoritmo do projeto

Para quem se interessa, um pouco de nosso algoritmo que controla o projeto

//------------------------------------------------------------------------------

//############################### DEFINIÇÕES ###############################

//------------------------------------------------------------------------------

#define LED33_OFF PORTC.RC0 = 0 //RC0 = NÍVEL BAIXO 0V

#define LED33_ON PORTC.RC0 = 1 //RC0 - NÍVEL ALTO 5V

#define LED66_OFF PORTC.RC1 = 0 //RC1 = NÍVEL BAIXO 0V

#define LED66_ON PORTC.RC1 = 1 //RC1 = NÍVEL ALTO 5V

#define LED100_OFF PORTC.RC2 = 0 //RC2 = NÍVEL BAIXO 0V

#define LED100_ON PORTC.RC2 = 1 //RC2 = NÍVEL ALTO 5V

//------------------------------------------------------------------------------

//############################# CONFIG. DISPLAY #############################

//------------------------------------------------------------------------------

// configurações dos pinos do lcd

sbit LCD_RS at RB0_bit;

sbit LCD_EN at RB1_bit;

sbit LCD_D4 at RB2_bit;

sbit LCD_D5 at RB3_bit;

sbit LCD_D6 at RB4_bit;

sbit LCD_D7 at RB5_bit;

// direções dos pinos

sbit LCD_RS_Direction at TRISB0_bit;

sbit LCD_EN_Direction at TRISB1_bit;

sbit LCD_D4_Direction at TRISB2_bit;

sbit LCD_D5_Direction at TRISB3_bit;

sbit LCD_D6_Direction at TRISB4_bit;

sbit LCD_D7_Direction at TRISB5_bit;

//------------------------------------------------------------------------------

//############################# VARIÁVEIS #############################

//------------------------------------------------------------------------------

unsigned char led33, led66, led100,contador;

//------------------------------------------------------------------------------

//############################# CONFIG. INICIAL #############################

//------------------------------------------------------------------------------

void PIC_INIT(void){

TRISC = 0b00000000; //0 -> SAÍDA 1 -> ENTRADA

TRISD = 0b00000111; //0 -> SAÍDA 1 -> ENTRADA

PORTC = 0b00000000; //0 -> 0V 1 -> 5V

PORTD = 0b00000000; //0 -> 0V 1 -> 5V

ADCON0 = 0b00000000;

ADCON1 = 0b00000110; // DEFINE TODOS OS PORTS COM ENTRADA ANALÓGICA EM DIGITAL

LCD_Init();

Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Cmd(_LCD_CLEAR);

led33 = 1; //inicia com 1 para acender na primeira vez que pressionar o botão

led66 = 1; //inicia com 1 para acender na primeira vez que pressionar o botão

led100 = 1; //inicia com 1 para acender na primeira vez que pressionar o botão

contador = 0;

}//PIC_INIT

//------------------------------------------------------------------------------

//############################# VERIFICA TECLA #############################

//------------------------------------------------------------------------------

void VerificaTecla(void){

if (!RD0_BIT){

while(!RD0_BIT){}

switch(led33){

case 0:

LED33_OFF;

led33 = 1;

if (contador > 0){contador --;}

break;

case 1:

LED33_ON;

led33 = 0;

if (contador < 4){contador ++;}

break;

}

}//!RD0_BIT

if (!RD1_BIT){

while(!RD1_BIT){}

switch(led66){

case 0:

LED66_OFF;

led66 = 1;

if (contador > 0){contador --;}

break;

case 1:

LED66_ON;

led66 = 0;

if (contador < 4){contador ++;}

break;

}

}//!RD1_BIT

if (!RD2_BIT){

while(!RD2_BIT){}

switch(led100){

case 0:

LED100_OFF;

led100 = 1;

if (contador > 0){contador --;}

break;

case 1:

LED100_ON;

led100 = 0;

if (contador < 4){contador ++;}

break;

}

}//!RD2_BIT

}//VerificaTecla

//------------------------------------------------------------------------------

//############################ FUNÇÃO ESCREVE_LCD ############################

//------------------------------------------------------------------------------

void EscreveLCD(void){

switch (contador){

case 0: default:

Lcd_Out(2,13," 0%");

break;

case 1:

Lcd_Out(2,13," 33%");

break;

case 2:

Lcd_Out(2,13," 66%");

break;

case 3:

Lcd_Out(2,13,"100%");

break;

}

}

//------------------------------------------------------------------------------

//############################# FUNÇÃO PRINCIPAL #############################

//------------------------------------------------------------------------------

void main(){

PIC_INIT();

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"PROJETO USF ");

Lcd_Out(2,1,"LAMPADAS EM: ");

while (1){

VerificaTecla();

EscreveLCD();

}// while(1)

}// main


bottom of page