找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5027|回复: 2
打印 上一主题 下一主题
收起左侧

ARDUINO PWM库下载

[复制链接]
跳转到指定楼层
楼主
ARDUINO PWM库


单片机源程序如下:
  1. /*
  2. This library is built to support two of the AVR Architecture 'groups' that Arduino uses
  3. a) ATmega48/88/168/328,
  4. b) ATmega640/1280/1281/2560/2561
  5. */

  6. #ifndef PWM_H_
  7. #define PWM_H_

  8. #include "avr/pgmspace.h"
  9. #include "math.h"

  10. #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
  11.         #include "utility/ATimerDefs.h"
  12. #elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
  13.         #include "utility/BTimerDefs.h"
  14. #endif


  15. #if defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
  16. // 16 bit timers
  17. extern uint32_t        GetFrequency_16(const int16_t timerOffset);
  18. extern bool                SetFrequency_16(const int16_t timerOffset, uint32_t f);
  19. extern uint16_t GetPrescaler_16(const int16_t timerOffset);
  20. extern void                SetPrescaler_16(const int16_t timerOffset, prescaler psc);
  21. extern void                SetTop_16(const int16_t timerOffset, uint16_t top);
  22. extern uint16_t GetTop_16(const int16_t timerOffset);
  23. extern void                Initialize_16(const int16_t timerOffset);
  24. extern float        GetResolution_16(const int16_t timerOffset);

  25. // 8 bit timers
  26. extern uint32_t        GetFrequency_8(const int16_t timerOffset);
  27. extern bool                SetFrequency_8(const int16_t timerOffset, uint32_t f);
  28. extern uint16_t GetPrescaler_8(const int16_t timerOffset);
  29. extern void                SetPrescaler_8(const int16_t timerOffset, prescaler psc);
  30. extern void                SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
  31. extern void                SetTop_8(const int16_t timerOffset, uint8_t top);
  32. extern uint8_t        GetTop_8(const int16_t timerOffset);
  33. extern void                Initialize_8(const int16_t timerOffset);
  34. extern float        GetResolution_8(const int16_t timerOffset);

  35. #endif

  36. #if defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)

  37. // 16 bit timers
  38. extern uint32_t        GetFrequency_16();
  39. extern bool                SetFrequency_16(uint32_t f);
  40. extern uint16_t GetPrescaler_16();
  41. extern void                SetPrescaler_16(prescaler psc);
  42. extern void                SetTop_16(uint16_t top);
  43. extern uint16_t GetTop_16();
  44. extern void                Initialize_16();
  45. extern float        GetResolution_16();

  46. // 8 bit timers
  47. extern uint32_t        GetFrequency_8(const int16_t timerOffset);
  48. extern bool                SetFrequency_8(const int16_t timerOffset, uint32_t f);
  49. extern uint16_t GetPrescaler_8(const int16_t timerOffset);
  50. extern void                SetPrescaler_8(const int16_t timerOffset, prescaler psc);
  51. extern void                SetPrescalerAlt_8(const int16_t timerOffset, prescaler_alt psc);
  52. extern void                SetTop_8(const int16_t timerOffset, uint8_t top);
  53. extern uint8_t        GetTop_8(const int16_t timerOffset);
  54. extern void                Initialize_8(const int16_t timerOffset);
  55. extern float        GetResolution_8(const int16_t timerOffset);

  56. #endif

  57. //common functions

  58. extern void                InitTimers();
  59. extern void                InitTimersSafe();                                                                                //doesn't init timers responsible for time keeping functions
  60. extern void                pwmWrite(uint8_t pin, uint8_t val);
  61. extern void                pwmWriteHR(uint8_t pin, uint16_t val);                                        //accepts a 16 bit value and maps it down to the timer for maximum resolution
  62. extern bool                SetPinFrequency(int8_t pin, uint32_t frequency);
  63. extern bool                SetPinFrequencySafe(int8_t pin, uint32_t frequency);        //does not set timers responsible for time keeping functions
  64. extern float        GetPinResolution(uint8_t pin);                                                        //gets the PWM resolution of a pin in base 2, 0 is returned if the pin is not connected to a timer

  65. #endif /* PWM_H_ */
复制代码

所有资料51hei提供下载:
pwm.zip (14.53 KB, 下载次数: 95)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:614623 发表于 2019-12-14 00:36 | 只看该作者
谢谢分享
回复

使用道具 举报

板凳
ID:272235 发表于 2019-12-25 11:31 | 只看该作者
为楼主点赞,感谢技术大咖分析好资料!后续多多支持!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表