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 <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();
- while(1)
- {
- Lcd4_Set_Cursor(1,1);
- Lcd4_Write_String("electroSome LCD Hello World");
- 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