-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
88 lines (59 loc) · 1.18 KB
/
code.c
File metadata and controls
88 lines (59 loc) · 1.18 KB
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
#define F_CPU 1000000UL
#define D4 eS_PORTD4
#define D5 eS_PORTD5
#define D6 eS_PORTD6
#define D7 eS_PORTD7
#define RS eS_PORTB6
#define EN eS_PORTB7
#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"
void Adcinit()
{
DDRC= 0b00000000; // make port c as input
ADMUX=0b01000100; // using Avcc with external capacitor at vref and 10bit
//ADMUX=0b01100000;
ADCSRA = (1<<ADEN);
}
float AdcRead(int a)
{
unsigned short x;
//ADMUX=0b01100000 + a;
ADMUX=0b01000000 + a;
ADCSRA = ADCSRA|(1<<ADSC);
while (ADCSRA & (1<<ADSC));
//x=ADCH;
x = ADC;
return x ;
}
float y_axis,b;
int i;
char *n = "weight(g)";
int main(void)
{
DDRB=0xFF;
DDRD=0xFF;
Adcinit();
Lcd4_Init();
while (1)
{
b = 0;
for (i = 1; i < 1000; ++i)
{
y_axis=AdcRead(4);
y_axis=(y_axis*11 -2939);
_delay_ms(1);
b = b + y_axis ;
}
b = ((b/999)-116);
char *y="00000";
itoa(b,y,10);
Lcd4_Clear();
Lcd4_Set_Cursor(1,0);
Lcd4_Write_String(n);
Lcd4_Set_Cursor(2,0);
Lcd4_Write_String(y);
_delay_ms(1000);
}
}