Advertisement
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;
- //result_h = ADCH;
- output_h = ADCH | output_h;
- result_h = output_h;
- //result_h = result_h << 8;
- //result_h = result_h | result_l;
- //output_h = output_h << 6;
- //output_l = output_l >> 2;
- //output_h = output_h | output_l;
- float voltage = ((output_h << 8) | output_l )*4/1024;
- //char outLED[10];
- //char vt[] = "voltage:";
- //gcvt(voltage, 3, outLED);
- //sprintf(outLED,"voltage:%1.2f",voltage);
- //1.65
- int a = (int)voltage;
- int b = (int)(voltage * 10);
- int c = (int)(voltage * 100);
- a = a % 10;
- b = b % 10;
- c = c % 10;
- unsigned char num_1 = a + '0';
- unsigned char num_2 = b + '0';
- unsigned char num_3 = c + '0';
- Lcd4_Set_Cursor(1,1);
- /*for(int i=0;i<8;i++ ){
- Lcd4_Write_Char(vt[i]);
- }
- */
- Lcd4_Write_Char(num_1);
- Lcd4_Write_Char('.');
- Lcd4_Write_Char(num_2);
- Lcd4_Write_Char(num_3);
- PORTB = output_l;
- //Lcd4_Write_String("electroSome LCD Hello World");
- //Lcd4_Write_String(outLED);
- /*
- for(i=0;i<15;i++)
- {
- _delay_ms(250);
- // Lcd4_Shift_Left();
- }
- for(i=0;i<15;i++)
- {
- _delay_ms(250);
- // Lcd4_Shift_Right();
- }
- Lcd4_Clear();
- //Lcd4_Set_Cursor(2,1);
- //Lcd4_Write_Char('e');
- //Lcd4_Write_Char('S');
- _delay_ms(1000);
- */
- }
- /*
- //long long int result_h;
- //long long int result_l;
- //unsigned char output_l;
- //unsigned char output_h;
- //DDRB = 0xFF;
- //Configure the ADC module of the ATmega16
- //ADMUX = 0b00000011; //REFS1:0 = 01 -> AVCC as reference
- //ADLAR = 0 -> Right adjust
- //MUX4:0 = 00000 -> ADC0 as input
- //ADCSRA = 0b10000100; //ADEN = 1 : enable
- //ADSC = 0 :
- while(1)
- {
- ADCSRA |= (1 << ADSC);
- while(ADCSRA & (1 << ADSC)){;}
- output_l = ADCL;
- result_l = ADCL;
- result_h = ADCH;
- output_h = ADCH;
- result_h = result_h << 8;
- result_h = result_h | result_l;
- output_h = output_h << 6;
- output_l = output_l >> 2;
- output_h = output_h | output_l;
- float voltage = (result_h)*4/1024;
- PORTB = ~output_h;
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement