Giter VIP home page Giter VIP logo

pic's People

Watchers

José Elias Gomes de Lima avatar

pic's Issues

Chocobom

// Lcd pinout settings
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D4 at RB2_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB2_bit;

//DTH22 pin
sbit DHT22_Pin at RD0_bit;
sbit DHT22_Pin_Direction at TRISD0_bit;

// Software I2C connections
sbit Soft_I2C_Scl at RB1_bit;
sbit Soft_I2C_Sda at RB0_bit;
sbit Soft_I2C_Scl_Direction at TRISB1_bit;
sbit Soft_I2C_Sda_Direction at TRISB0_bit;

/* VARIAVEIS E TEXTOS */
char version[] = "Choco Bom V001";

//hora e data
char ajTemp[] = "Ajuste Temp";
char time[] = " Hora: 00:00:00"; //18 campos=> preencher 10 11 13 14 16 17
char date[] = " Data: 00/00/00"; //18 campos=> preencher 10 11 13 14 16 17
//fim hora e data

//Temperatura e humidade
char temp[] = " Temp: . C"; //16 campos=> preencher 11 12 14
char humd[] = "Humidade: . %"; //16 campos=> preencher 10 11 12 14
const char degree[] = {14,10,14,0,0,0,0,0};
unsigned humidity, temperature;
unsigned long value;
//Fim temp e humid

//menu
unsigned short screen = 0x01;
char t_up = 0;
char t_down = 0;

/*PROTOTIPOS DE FUNCOES */
void informa();
void DHT22_Read();
void degreeChar(char pos_row, char pos_char);
void informa();
void readButtons();
void ajusteTemperatura();

void main() {

 ADCON0 = 0x00;        //Configura pinos AN como I/O
 ADCON1 = 0x0F;       //Configura pinos AN como digital
 CMCON |= 7;           //Desabilita comparador

 //0 SAIDA             1 ENTRADA
 TRISB |= 0b00000011;
 //TRISA = 0x0F;
 
 TRISA0_bit = 1;  //A0 como entrada
 TRISA1_bit = 1;  //A1 como entrada
 TRISD1_bit = 0;

 PORTD.RB1 = 0;
 lcd_Init();

 Lcd_Cmd(_LCD_CLEAR);          //limpa o lcd
 Lcd_Cmd(_LCD_CURSOR_OFF);   //desativa o cursor

 lcd_Out(1,5,version);
 delay_ms(2000);
 
 while(1){
    readButtons();
    switch(screen){
         case 0x01: informa(); break;
         case 0x02: ajusteTemperatura(); break;
    }
    delay_ms(1000);
 }

}

void informa(){
//TEMPERATURA E HUMIDADE
Lcd_Cmd(_LCD_CLEAR); //limpa o lcd
Lcd_Out(1,1,time);
Lcd_Out(2,1,date);

 //TEMPERATURA E HUMIDADE
    DHT22_Read();
 }

void ajusteTemperatura(){
Lcd_Cmd(_LCD_CLEAR); //limpa o lcd
Lcd_Out(1,1,"Ajuste de Temperatura");
}

void readButtons(){
if(!PORTA.RB0) t_up = 0x01;
if(!PORTA.RB1) t_down = 0x01;

 if(PORTA.RB0 && t_up){
    delay_ms(50);
    t_up = 0x00;
    Lcd_Cmd(_LCD_CLEAR);
    screen++;
    if(screen > 0x02) screen = 0x01;
 }

 if(PORTA.RB1 && t_down){
    delay_ms(50);
    t_down = 0x00;
    Lcd_Cmd(_LCD_CLEAR);
    screen--;
    if(screen < 0x01) screen = 0x02;
 }

}

void degreeChar(char pos_row, char pos_char) {
char i;
Lcd_Cmd(64);
for (i = 0; i<=7; i++) Lcd_Chr_CP(degree[i]);
Lcd_Cmd(_LCD_RETURN_HOME);
Lcd_Chr(pos_row, pos_char, 0);
}

void DHT22_Read(){
value = DHT22_readData();
if(value==0x63636363){
Lcd_Out(3,1,"Sensor nao responde");
}
if (value == 0x58585858){
Lcd_Out(3,1,"CheckSun error");
}
if((value!=0x63636363) && (value != 0x58585858)){
temperature = value & 0xFFFF; //pega 16 bits
value = value >> 16; //vai para o 17bit
humidity = value & 0xFFFF; //pega mais 16 bits
Lcd_Out(3,1,humd); //17 colunas (0-16);
Lcd_Out(4,1,temp); //17 colunas (0-16);
degreeChar(4,15); //posiciona na coluna 15
if(temperature>0x8000){
Lcd_Out(4,10,"-"); //se a temperatura for negativa
temperature = temperature & 0x7FFF;
}
Lcd_Chr(4,11,48+((temperature/100)%10));
Lcd_Chr(4,12,48+((temperature/10)%10));
Lcd_Chr(4,14,48+(temperature%10));
if(humidity==1000)
Lcd_Chr(3,10,48+((humidity/1000)%10));
Lcd_Chr(3,11,48+((humidity/100)%10));
Lcd_Chr(3,12,48+((humidity/10)%10));
Lcd_Chr(3,14,48+(humidity%10));
}
// delay_ms(1000);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.