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
| // LCD module connections
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;
void main()
{
unsigned int temp_ADCresult;
char i, y=6, x=12;
char *intro[] = {"W","e","l","c","o","m","e"};
float volt;
char txt[14];
TRISA = 0xff;
TRISC = 0x00; // set direction to be output
PORTC = 0x00;
//LCD config
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
for(i=0; i<=6; i++)
{
Lcd_Out(1,x, intro[y]);
y--;
x--;
Delay_ms(400);
}
Lcd_Out(1,13, "!");
Delay_ms(1200);
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
temp_ADCresult = ADC_Read(2);
PORTC = temp_ADCresult;
volt = temp_ADCresult;
volt = (temp_ADCresult*4.8/1023) * 4.2;
if(temp_ADCresult <= 60)
{
Lcd_Out(1,8,"0");
Lcd_Out(1,9,"V");
}
else
{
FloatToStr(volt, txt);
Lcd_Out(1,7, txt);
Lcd_Out(1,16,"V");
}
Lcd_Out(1,1,"ToTAL:");
}
} |