gabrielaozegovic

7SEG + ADC

Jan 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #define F_CPU 7372800UL
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5.  
  6. uint8_t values[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
  7. uint8_t data[4] = {0, 0, 0, 0};
  8.  
  9. void brData(uint16_t broj){
  10. for(int i = 3; i >= 0; i--){
  11. data[i] = broj%10;
  12. broj = broj/10;
  13. }
  14. }
  15.  
  16. void funkcija(){
  17. brData(ADC);
  18. for(int i = 0; i < 4; i++){
  19. PORTD = values[data[i]];
  20. PORTB = _BV(i+4);
  21. _delay_ms(1);
  22. }
  23.  
  24. }
  25.  
  26. int main(void){
  27. DDRB = 0xff;
  28.  
  29. DDRD = 0xff;
  30. PORTD = 0xff;
  31.  
  32. ADMUX = _BV(REFS0) | 0;
  33. ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS0);
  34.  
  35. while (1) {
  36.  
  37. ADCSRA |= _BV(ADSC);
  38.  
  39. while(!(ADCSRA & _BV(ADIF)));
  40.  
  41. funkcija();
  42. }
  43. }
Add Comment
Please, Sign In to add comment