Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef F_CPU
- #define F_CPU 1000000UL // 16 MHz clock speed
- #endif
- #define D4 eS_PORTD4
- #define D5 eS_PORTD5
- #define D6 eS_PORTD6
- #define D7 eS_PORTD7
- #define RS eS_PORTC6
- #define EN eS_PORTC7
- #include <string.h>
- #include <stdio.h>
- #include <avr/io.h>
- #include <util/delay.h>
- #include "lcd.h" //Can be download from the bottom of this article
- int main(void)
- {
- DDRD = 0xFF;
- DDRC = 0xFF;
- int i;
- Lcd4_Init();
- int result_h;
- int result_l;
- unsigned char output_l;
- unsigned char output_h=0b00000000;
- DDRB = 0xFF;
- //Configure the ADC module of the ATmega16
- ADMUX = 0b00000011; //REFS1:0 = 01 -> AVCC as reference
- //ADLAR = 0 -> Right adjust
- //MUX4:0 = 00011 -> ADC3 as input
- ADCSRA = 0b10000100;
- while(1)
- {
- ADCSRA |= (1 << ADSC);
- while(ADCSRA & (1 << ADSC)){;}
- output_l = ADCL;
- result_l = ADCL;
- output_h = ADCH | output_h;
- result_h = output_h;
- result_h = (output_h << 8) | output_l;
- float voltage = (result_h )*4/1024;
- int c = voltage * 100;
- int b = c / 10;
- int a = b/10;
- a = a % 10;
- b = b % 10;
- c = c % 10;
- Lcd4_Set_Cursor(1,1);
- Lcd4_Write_Char(a + '0');
- Lcd4_Write_Char('.');
- Lcd4_Write_Char(b + '0');
- Lcd4_Write_Char(c + '0');
- PORTB = result_h;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment