Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <avr/interrupt.h>
  2. uint32_t count=0;
  3. uint8_t overTimer=0;
  4. float valor=0;
  5. float A=234375/1048576; //constante de ajuste
  6. void setup() {
  7. // put your setup code here, to run once:
  8. //setup timer 1
  9. TIMSK1=(1<<TOIE1); //habilita o timmer 1(16b)
  10. TCNT1=0x00; //valor inicial do contador
  11. TCCR1B = (1<<CS12); //prescale 256
  12. //setup int0
  13. EICRA = (1 << ISC01)| (1 << ISC00); // set INT0 to trigger on ANY logic change
  14. EIMSK |= (1 << INT0); // Turns on INT0
  15. sei();
  16. }
  17.  
  18. void loop() {
  19. // put your main code here, to run repeatedly:
  20. PORTB=0x10;
  21. //atualiza o lcd
  22. valor=(0xffffff-count)*A;
  23. //print valor LCD
  24. delay(100);
  25. }
  26. //interrupção do timer
  27. ISR(TIMER1_OVF_vect) {
  28. overTimer++;
  29. }
  30.  
  31. //interrupção externa(encoder)
  32. ISR(INT0_vect){
  33. count=(((TCNT1*overTimer)/12)+count)>>1;
  34. TCNT1=0;
  35. overTimer=1;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement