-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitignore
106 lines (95 loc) · 2.34 KB
/
.gitignore
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
/*
LCD DATA port----PORT D
signal port------PORT B
rs-------PB0
rw-------PB1
en-------PB2
*/
#define F_CPU 16000000UL
#include<avr/io.h>
#include<util/delay.h>
#define LCD_DATA PORTD //LCD data port
#define ctrl PORTB
#define en PB2 // enable signal
#define rw PB1 // read/write signal
#define rs PB0 // register select signal
void ADC_init()
{
ADMUX = (1<<REFS0) ; // Reference Voltage to Avcc= Vcc= 5 V
ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0);
}
void init_LCD(void)
{
LCD_cmd(0x38); // initialization of 16X1 LCD in 8bit mode
_delay_ms(1);
LCD_cmd(0x01); // clear LCD
_delay_ms(1);
LCD_cmd(0x0E); // cursor ON
_delay_ms(1);
LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position
_delay_ms(1);
return;
}
int ADC_read( uint8_t channel)
{
channel = channel & 0b00000111; // Making sure that channel value is less than 7
ADMUX|= channel; // Assigning channel value to MUX bits of ADMUX
ADCSRA|= (1<<ADSC); // Start Conversion
while( ! ( ADCSRA & (1<<ADIF) ) ); // Wait till the conversion completes
ADCSRA|= (1<<ADIF); // Clear the ADIF bit by writing ‘1’
return ADC;// Return the converted Digital value to the function
}
void LCD_cmd(unsigned char cmd)
{
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return;
}
void LCD_write(unsigned char data)
{
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return ;
}
void LCD_write_string(unsigned char *str) //store address value of the string in pointer *str
{
int i=0;
char a;
while(str[i]!='\0') // loop will go on till the NULL character in the string
{
LCD_write(str[i]); // sending data on LCD byte by byte
i++;
}
a=248;
LCD_write(a);
a=67;
LCD_write(a);
return;
}
int main()
{
DDRD=0xff;
DDRB=0x07;
_delay_ms(50); // delay of 50 mili seconds
ADC_init(); // initialization of ADC
/*variable init*/
float value;
int temp;
char str[5];
while(1)
{
init_LCD(); // initialization of LCD
value=ADC_read(0); // function to read the Adc value
temp=(value/1023)*5*100; // temp=100*voltage
sprintf(str, "%d", temp); // function to convert int to string
LCD_write_string(str); // function to print string on LCD
_delay_ms(1000); // delay for visual
}
return 0;
}