-
Notifications
You must be signed in to change notification settings - Fork 5
/
reading-humidity-sensor-pic16f877a.c
50 lines (37 loc) · 1.2 KB
/
reading-humidity-sensor-pic16f877a.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
#define LCD_RW RB6_bit
#define LCD_BL RB7_bit
void main()
{
char Humidity[15];
float ADC_float = 0.0;
float Humidity_float = 0;
TRISB6_bit=0; //set both RB6 and RB7 pin as output
TRISB7_bit=0;
LCD_BL = 1; //turn on Backlight
LCD_RW = 0; //set LCD in write mode
Lcd_Init(); //this function initialize all LCD configuration
//including the pin direction configuration
Lcd_Cmd(_LCD_CURSOR_OFF); //turn off LCD cursor
ADC_Init();
Lcd_Out(1,1,"Humidity (%RH):");
while(1)
{
ADC_float=(float)ADC_Get_Sample(0);
Humidity_float=10.0+((ADC_float*5.0/1024.0)-0.75)*32.0;
FloatToStr(Humidity_float,Humidity);
Lcd_Out(2,1,Humidity);
Lcd_Out_CP(" ");
}
}