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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
| *
* Created: Mon Jul 14 2014
* Processor: PIC16F877A
* Compiler: HI-TECH C for PIC10/12/16
*/
#include <htc.h>
#include <pic.h>
// Lcd module connections
#define RS RC4
#define EN RC5
#define D4 RC0
#define D5 RC1
#define D6 RC2
#define D7 RC3
#include "lcd.h"
#define _XTAL_FREQ 8000000
//Declarations
int Madc;
int Tadc;
int Padc;
int Sadc;
float Mval;
float Tval;
float Pval;
float Sval;
#define DECIMAL_PLACES (100) // 2 digits after decimal
void displayFloat(float value) // Assume value = 123.456
{
float a = value; // a = 123
value = (value - (float)a) * (DECIMAL_PLACES); // value = 45.6
float b = value; // b = 45
display(a);
display('.');
display(b);
}
unsigned int ADC_Read(unsigned char channel)
{
if(channel > 7) //If Invalid channel selected
return 0; //Return 0
ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D Conversion
while(GO_nDONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void main()
{
// Initializations
ADCON1 = 0xF0; // AN1-AN4 are inputs
Lcd8_Init(); // Initialize Lcd
Lcd8_Clear(); // Clear display
Lcd8_Set_Cursor(1,1);
Lcd8_Write_String("Welcom"); // Display welcome message
__delay_ms(1000);
TRISA = 0xFl; // PORTA is input
TRISB = 0XFF; // PORTB is input
// ADC conversions
Lcd8_Clear();
Madc= ADC_Read(1);
Tadc = ADC_Read(2);
Padc = ADC_Read(3);
Sadc= ADC_Read(4);
//Computations
Tval = Tadc*0.004887;
Mval = Madc*0.004887;
Pval = Padc*0.004887;
Sval = Sadc*0.004887;
// String Conversions
#define z1 RB1
#define z2 RB2
#define z3 RB3;
#define z4 RB4;
#define zall RB5;
do {
//display
if(z1==0|zall==0)
{
Lcd8_Clear();
Lcd8_Set_Cursor(1,1);
Lcd8_Write_String("M");
Lcd8_Set_Cursor(1,1);
Lcd8_Write_String(dispalyFloat(Mval));
__delay_ms(2000);
}
else
Lcd8_Clear();
if (z2==0|zall==0)
{
Lcd8_Clear();
Lcd8_Set_Cursor(1,1);
Lcd8_Write_String("T:");
Lcd8_Set_Cursor(2,9);
Lcd_Write_String(displayFloat(Tval));
__delay_ms(2000);
}
else
Lcd8_Clear();
if (z3==0|zall==0)
{
Lcd8_Clear();
Lcd8_Set_Cursor(3,1);
Lcd8_Write_String("P:");
Lcd8_Set_Cursor(3,9);
Lcd8_Write_String(displayFloat(Pval));
__delay_ms(2000);
}
else
Lcd8_Clear();
if (z4==0|zall=0)
{
Lcd8_Clear();
Lcd8_Set_Cursor(4,1);
Lcd8_Write_String("S:");
Lcd8_Set_Cursor(4,9);
Lcd8_Write_String(displayFloat(Sval));
__delay_ms(2000);
}
else
Lcd8_Clear();
if (z1 == 1)and(z2 == 1)and(z3 == 1)and(z4 == 1)and(zall == 1))
{
Lcd8_Clear();
Lcd8_Set_Cursot(1,1);
Lcd8_Write_String("Please Press");
Lcd8_Set_Cursor(2,1);
Lcd8_Write_String("a Button");
__delay_ms(2000);
}
else
Lcd8_Clear();
}
while(1);
//END
} |