Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #define F_CPU   16000000UL
  2. //#include "mydelay.h"
  3. #include <avr/io.h>
  4. #include "kernel.h"
  5. #include <util/delay_basic.h>
  6.  
  7. #define NULL (void *) 0
  8.  
  9. #ifndef __HAS_DELAY_CYCLES
  10. #define __HAS_DELAY_CYCLES 1
  11. #endif
  12.  
  13. // Base frequency for the buzzer
  14. #define BASE_FREQ   200
  15.  
  16. int pwm_val = 0;
  17. int pwm_val2 = 0;
  18. unsigned adc_val = 0;
  19. long __tmp;
  20.  
  21. void
  22. _my_delay_ms(long __ms)
  23. {
  24.     uint16_t __ticks;
  25.  
  26.     #if !__HAS_DELAY_CYCLES || (__HAS_DELAY_CYCLES && !defined(__OPTIMIZE__)) || defined (__DELAY_BACKWARD_COMPATIBLE__)
  27.     __tmp = ((F_CPU) / 4000) * __ms;
  28.     if (__tmp < 1)
  29.         __ticks = 1;
  30.     else if (__tmp > 65535)
  31.     {
  32.         //  __ticks = requested delay in 1/10 ms
  33.         __ticks =  (uint16_t)(__ms * 10);
  34.         while(__ticks)
  35.         {
  36.             // wait 1/10 ms
  37.             _delay_loop_2(((F_CPU) / 4e3) / 10);
  38.             __ticks --;
  39.         }
  40.         return;
  41.     }
  42.     else
  43.         __ticks = (uint16_t)__tmp;
  44.        
  45.     _delay_loop_2(__ticks);
  46. #endif
  47. }
Add Comment
Please, Sign In to add comment