Advertisement
gabrielaozegovic

Untitled

Dec 13th, 2017
104
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. #include <avr/interrupt.h>
  6.  
  7. static uint16_t delayCnt;
  8. static uint16_t step = 5;
  9.  
  10. void delay(uint16_t t){
  11. uint8_t i;
  12.  
  13. for(i=0; i<t; i++){
  14. _delay_ms(1);
  15. }
  16. }
  17.  
  18. void aktivnost(){
  19.  
  20. PORTA = PORTA << 1;
  21. if(PORTA != 0xfe && PORTA != 0b11111100){
  22. PORTA |= 0x01;
  23. }
  24.  
  25. }
  26.  
  27. int main(void){
  28.  
  29. PORTA = 0xff;
  30. DDRA = 0xff;
  31.  
  32. DDRB = 0;
  33. PORTB = _BV(0) | _BV(1);
  34.  
  35. while (1) {
  36.  
  37. if(bit_is_clear(PINB, 0)){
  38. if(delayCnt + step < 500)
  39. delayCnt += step;
  40. }
  41. if(bit_is_clear(PINB, 1)){
  42. if(delayCnt + step > 100)
  43. delayCnt -= step;
  44. }
  45.  
  46. aktivnost();
  47. delay(delayCnt);
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement