Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Meu primeiro projeto, feito em 2012: Termômetro Digital
//Pinos do LCD
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
unsigned long value;
unsigned char d1, d2, d3, d4;
void Print() {
Lcd_Out(2, 1, "Temperatura: ");
Lcd_Chr_CP(d1 + 48);
Lcd_Chr_CP(d2 + 48);
Lcd_chr_CP(d3 + 48);
Lcd_chr_CP(44);
Lcd_chr_CP(d4 + 48);
}
void main() {
TRISA = 0xFF;
TRISB = 0b11000000;
Lcd_Init();
Delay_ms(100);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 3, "MICROCONTROLANDOS");
while (1) {
value = ADC_Read(0);
value = (value * 500 / 1023) * 10;
//Celsius
if (PORTB.F6 == 0 && PORTB.F7 == 0) {
d1 = value / 1000;
d2 = (value % 1000) / 100;
d3 = ((value % 1000) % 100) / 10;
d4 = ((value % 1000) % 100) % 10;
Print();
Lcd_chr_CP(223);
Lcd_Out_CP("C");
}
//Fahrenheit
else if (PORTB.F6 == 0 && PORTB.F7 == 1) {
value = (value * 1.79) + 32;
d1 = value / 1000;
d2 = (value % 1000) / 100;
d3 = ((value % 1000) % 100) / 10;
d4 = ((value % 1000) % 100) % 10;
Print();
Lcd_chr_CP(223);
Lcd_Out_CP("F");
}
//Kelvin
else if (PORTB.F6 == 1 && PORTB.F7 == 0) {
value = value + 273;
d1 = value / 1000;
d2 = (value % 1000) / 100;
d3 = ((value % 1000) % 100) / 10;
d4 = ((value % 1000) % 100) % 10;
Print();
Lcd_Out_CP("K");
}
//Rankine
else {
value = (value * 1.8) + 32 + 460;
d1 = value / 1000;
d2 = (value % 1000) / 100;
d3 = ((value % 1000) % 100) / 10;
d4 = ((value % 1000) % 100) % 10;
Print();
Lcd_chr_CP(223);
Lcd_Out_CP("R");
}
Delay_ms(20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.