Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <avr/io.h>
- #include "hd44780/HD44780.hpp"
- #define LED1 PB5 // LED1 deifnition
- #define LED2 PB4 // LED2 deifnition
- #define LED3 PB3 // LED2 deifnition
- #define LED4 PB2 // LED2 deifnition
- #define SW1 PD0 // BUTTON deifnition
- #define SW2 PD1 // BUTTON deifnition
- #define SW3 PD2 // BUTTON deifnition
- #define SW4 PD3 // BUTTON deifnition
- #define ADCIN PC0 // ADCIN (wejœcie ADC)
- void ADC_Init(void);
- int main(void)
- {
- // IO configuration
- DDRB |= (1<<LED1) | (1<<LED2) | (1<<LED3) | (1<<LED4); // configuration of LED pins as outputs
- DDRC &=~ (1<<ADCIN); // ADC pin as input
- DDRD= 0xff; // not used pins in port D as outputs
- DDRD &=~ (1<<SW1); // button pin as input
- PORTD |= (1<<SW1); // Pull up button pin
- ADC_Init();
- LCD_Initalize();
- // main loop
- for(;;)
- {
- // IF is executed when button is pressed
- if(!(PIND & (1<<SW1))){
- LCD_Clear();
- LCD_GoTo(9,0);
- ADCSRA |= (1<<ADSC); // ADC - Start Conversion
- while(ADCSRA & (1<<ADSC)); // wait for finish of conversion
- // use ADC register to
- // * display value on the screen
- // * send it to the computer with uart
- // * blink led dependign on the
- }
- }
- }
- void ADC_Init(void){
- // ADC configuration register
- ADCSRA = (1<<ADEN)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
- //ADEN - ADC Enable
- //ADPS2:0 - prescaler (128 in this case)
- // multiplexer selectrion register
- ADMUX = (1<<REFS1) | (1<<REFS0);
- //REFSW:0: Reference Selection Bits -> Internal 1.1V Voltage Reference with external capacitor at AREF pin
- //Input Channel Selections (ADC0 - PC0 )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement