Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <avr/io.h>
  4. #include "hd44780/HD44780.hpp"
  5.  
  6. #define LED1 PB5 // LED1 deifnition
  7. #define LED2 PB4 // LED2 deifnition
  8. #define LED3 PB3 // LED2 deifnition
  9. #define LED4 PB2 // LED2 deifnition
  10. #define SW1 PD0 // BUTTON deifnition
  11. #define SW2 PD1 // BUTTON deifnition
  12. #define SW3 PD2 // BUTTON deifnition
  13. #define SW4 PD3 // BUTTON deifnition
  14. #define ADCIN PC0 // ADCIN (wejœcie ADC)
  15.  
  16. void ADC_Init(void);
  17.  
  18. int main(void)
  19. {
  20. // IO configuration
  21. DDRB |= (1<<LED1) | (1<<LED2) | (1<<LED3) | (1<<LED4); // configuration of LED pins as outputs
  22. DDRC &=~ (1<<ADCIN); // ADC pin as input
  23. DDRD= 0xff; // not used pins in port D as outputs
  24. DDRD &=~ (1<<SW1); // button pin as input
  25. PORTD |= (1<<SW1); // Pull up button pin
  26.  
  27. ADC_Init();
  28. LCD_Initalize();
  29.  
  30. // main loop
  31. for(;;)
  32. {
  33. // IF is executed when button is pressed
  34. if(!(PIND & (1<<SW1))){
  35. LCD_Clear();
  36. LCD_GoTo(9,0);
  37.  
  38. ADCSRA |= (1<<ADSC); // ADC - Start Conversion
  39. while(ADCSRA & (1<<ADSC)); // wait for finish of conversion
  40.  
  41. // use ADC register to
  42. // * display value on the screen
  43. // * send it to the computer with uart
  44. // * blink led dependign on the
  45. }
  46. }
  47. }
  48.  
  49. void ADC_Init(void){
  50. // ADC configuration register
  51. ADCSRA = (1<<ADEN)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
  52. //ADEN - ADC Enable
  53. //ADPS2:0 - prescaler (128 in this case)
  54.  
  55. // multiplexer selectrion register
  56. ADMUX = (1<<REFS1) | (1<<REFS0);
  57. //REFSW:0: Reference Selection Bits -> Internal 1.1V Voltage Reference with external capacitor at AREF pin
  58. //Input Channel Selections (ADC0 - PC0 )
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement