STM8L之Timer2产生PWM,可供参考。
上传时间: 2017-11-21
上传用户:my_lcs
深联华集成电路有限公司推出一款防破解,堵漏洞的单片机,可以很好的保护到您的知识产权, 此单片机兼容51系列,且与51系列内置相似。我们产品的优势: 1.在同样振荡频率下,较之传统的8051芯片它具有运行更快,性能更优越的特性; 2.这些特性包括内置256字节RAM和2个16位定时器/计数器,1个UART和外 部中断INT0和INT1; 3.可兼容8052芯片的16位定时器/计数器(Timer2)。包括适合于程序和数据的 62K字节Flash存储器。 4.集成了EUART,SPI等标准通讯模块,还集成了具有内建比较功能的ADC,PWM定时器以及模拟比 较器(CMP)等模块; 5.内建看门狗定时器,采用低电压复位、低电压检测、振荡器失效检测等功能,提供了2种低功耗省电模式; 6.高达32位的密码生成器-1/50亿(1/1G)的破解概率; 7.白噪声密码,没有规律可循,加密后原厂也无法破解;每颗芯片都有自己的 密码,同样的密码不可重用; 8.程序有防盗措施,即使破解后获得芯片中的程序也是乱码。
标签: 规格书
上传时间: 2013-10-14
上传用户:维子哥哥
PIC系列单片机手册 第1 章 简介 1-1简介 ................................................................................................................................................................. 1-2本手册的宗旨 ................................................................................................................................................... 1-3器件结构 .......................................................................................................................................................... 1-4开发支持 .......................................................................................................................................................... 1-6器件种类 .......................................................................................................................................................... 1-7格式和符号的约定 ......................................................................................................................................... 1-12相关文档 ........................................................................................................................................................ 1-14相关应用笔记 ................................................................................................................................................. 1-17版本历史 ........................................................................................................................................................ 1-18第2 章 振荡器 2-1简介 ................................................................................................................................................................. 2-2振荡器配置 ...................................................................................................................................................... 2-2晶体振荡器 / 陶瓷谐振器 ................................................................................................................................. 2-4外部RC 振荡器 ............................................................................................................................................. 2-124MHz 内部 RC 振荡器 ................................................................................................................................... 2-13休眠模式对片内振荡器的影响 ........................................................................................................................ 2-17器件复位对片内振荡器的影响 ........................................................................................................................ 2-17设计技巧 ........................................................................................................................................................ 2-18相关应用笔记 ................................................................................................................................................. 2-19版本历史 ........................................................................................................................................................ 2-20第3 章 复位 3-1简介 ................................................................................................................................................................. 3-2上电复位、上电延时定时器、 起振定时器、欠压复位和奇偶校验错误复位 ...................................................... 3-4寄存器和状态位的值 ...................................................................................................................................... 3-10设计技巧 ........................................................................................................................................................ 3-16相关应用笔记 ................................................................................................................................................. 3-17版本历史 ........................................................................................................................................................ 3-18 第4 章 架构 4-1简介 ................................................................................................................................................................. 4-2时序图/ 指令周期 ............................................................................................................................................ 4-5指令流/ 流水线 ................................................................................................................................................ 4-6I/O 端口描述 .................................................................................................................................................... 4-7设计技巧 ........................................................................................................................................................ 4-12相关应用笔记 ................................................................................................................................................. 4-13版本历史 ........................................................................................................................................................ 4-14 第5 章 CPU 和ALU 5-1简介 ................................................................................................................................................................. 5-2指令的一般格式 ............................................................................................................................................... 5-4中央处理单元(CPU) .................................................................................................................................... 5-4指令时钟 .......................................................................................................................................................... 5-4算术逻辑单元(ALU) .................................................................................................................................... 5-5状态寄存器 ...................................................................................................................................................... 5-6OPTION_REG 寄存器 ..................................................................................................................................... 5-8电源控制寄存器 ............................................................................................................................................... 5-9设计技巧 ........................................................................................................................................................ 5-10相关应用笔记 ................................................................................................................................................. 5-11版本历史 ........................................................................................................................................................ 5-12第6 章 存储器构成 6-1简介 ................................................................................................................................................................. 6-2程序存储器构成 ............................................................................................................................................... 6-2数据存储器构成 ............................................................................................................................................... 6-8初始化 ........................................................................................................................................................... 6-14设计技巧 ........................................................................................................................................................ 6-16相关应用笔记 ................................................................................................................................................. 6-17版本历史 ........................................................................................................................................................ 6-18第7 章 数据EEPROM 7-1简介 ................................................................................................................................................................. 7-2控制寄存器 ...................................................................................................................................................... 7-3EEADR ............................................................................................................................................................ 7-4EECON1 和EECON2 寄存器 .......................................................................................................................... 7-4从EEPROM 数据存储器中读数据 .................................................................................................................... 7-5向EEPROM 数据存储器中写数据 .................................................................................................................... 7-5写校验 ............................................................................................................................................................. 7-6误写操作保护 ................................................................................................................................................... 7-7代码保护配置下的数据EEPROM 操作 ............................................................................................................. 7-7初始化 ............................................................................................................................................................. 7-7设计技巧 .......................................................................................................................................................... 7-8相关应用笔记 ................................................................................................................................................... 7-9版本历史 ........................................................................................................................................................ 7-10第8 章 中断 8-1简介 ................................................................................................................................................................. 8-2控制寄存器 ...................................................................................................................................................... 8-5中断响应延时 ................................................................................................................................................. 8-10INT 和外部中断 .............................................................................................................................................. 8-10中断的现场保护 ............................................................................................................................................. 8-11初始化 ........................................................................................................................................................... 8-14设计技巧 ........................................................................................................................................................ 8-16相关应用笔记 ................................................................................................................................................. 8-17版本历史 ........................................................................................................................................................ 8-18第9 章 I/O 端口 9-1简介 ................................................................................................................................................................. 9-2PORTA 和TRISA 寄存器 ................................................................................................................................ 9-4PORTB 和TRISB 寄存器 ................................................................................................................................ 9-6PORTC 和TRISC 寄存器 ................................................................................................................................ 9-8PORTD 和TRISD 寄存器 ................................................................................................................................ 9-9PORTE 和TRISE 寄存器 ............................................................................................................................... 9-10PORTF 和 TRISF 寄存器 ............................................................................................................................... 9-11PORTG 和TRISG 寄存器 .............................................................................................................................. 9-12GPIO 和TRISGP 寄存器 ............................................................................................................................... 9-13I/O 编程注意事项 ........................................................................................................................................... 9-14初始化 ........................................................................................................................................................... 9-16设计技巧 ........................................................................................................................................................ 9-17相关应用笔记 ................................................................................................................................................. 9-19版本历史 ........................................................................................................................................................ 9-20第10 章 并行从动端口 10-1简介 ............................................................................................................................................................... 10-2控制寄存器 .................................................................................................................................................... 10-3操作 ............................................................................................................................................................... 10-4休眠模式下的操作 ......................................................................................................................................... 10-5复位的影响 .................................................................................................................................................... 10-5PSP 波形 ....................................................................................................................................................... 10-5设计技巧 ........................................................................................................................................................ 10-6相关应用笔记 ................................................................................................................................................. 10-7版本历史 ........................................................................................................................................................ 10-8 第11 章 TIMER0 11-1简介 ............................................................................................................................................................... 11-2控制寄存器 .................................................................................................................................................... 11-3操作 ............................................................................................................................................................... 11-4TMR0 中断 .................................................................................................................................................... 11-5Timer0 外部时钟的使用 ................................................................................................................................. 11-6TMR0 的预分频器 ......................................................................................................................................... 11-7设计技巧 ...................................................................................................................................................... 11-10相关应用笔记 ............................................................................................................................................... 11-11版本历史 ...................................................................................................................................................... 11-12第12 章 TIMER1 12-1简介 ............................................................................................................................................................... 12-2控制寄存器 .................................................................................................................................................... 12-3Timer1 工作在定时器模式 ..............................................................................................................................12-4Timer1 工作在同步计数器模式 ....................................................................................................................... 12-4Timer1 工作在异步计数器模式 ....................................................................................................................... 12-5Timer1 振荡器 ............................................................................................................................................... 12-7休眠操作 ........................................................................................................................................................ 12-9用CCP 触发器的输出将Timer1 复位 ............................................................................................................. 12-9Timer1 寄存器(TMR1H:TMR1L)的复位 .................................................................................................... 12-9Timer1 预分频器 ............................................................................................................................................ 12-9初始化 ......................................................................................................................................................... 12-10设计技巧 ...................................................................................................................................................... 12-12相关应用笔记 ............................................................................................................................................... 12-13版本历史 ...................................................................................................................................................... 12-14第13 章 Timer2 13-1简介 ............................................................................................................................................................... 13-2控制寄存器 .................................................................................................................................................... 13-3定时器时钟源 ................................................................................................................................................. 13-4定时器TMR2 和PR2 周期寄存器 .................................................................................................................. 13-4TMR2 匹配输出 ............................................................................................................................................. 13-4将Timer2 的预分频器和后分频器清零 ........................................................................................................... 13-4休眠操作 ........................................................................................................................................................ 13-4初始化 ........................................................................................................................................................... 13-5设计技巧 ........................................................................................................................................................ 13-6相关应用笔记 ................................................................................................................................................. 13-7版本历史 ........................................................................................................................................................ 13-8第14 章 比较/ 捕捉/ 脉宽调制(CCP) 14-1简介 ............................................................................................................................................................... 14-2控制寄存器 .................................................................................................................................................... 14-3捕捉模式 ........................................................................................................................................................ 14-4比较模式 ........................................................................................................................................................ 14-6PWM 模式 ..................................................................................................................................................... 14-8初始化 ......................................................................................................................................................... 14-12设计技巧 ...................................................................................................................................................... 14-15相关应用笔记 ............................................................................................................................................... 14-17版本历史 ...................................................................................................................................................... 14-18第15 章 同步串行口(SSP) 15-1简介 ............................................................................................................................................................... 15-2控制寄存器 .................................................................................................................................................... 15-3SPITM 模式 .................................................................................................................................................... 15-6SSP 模块的I2CTM 操作 ............................................................................................................................... 15-16初始化 ......................................................................................................................................................... 15-26设计技巧 ...................................................................................................................................................... 15-28相关应用笔记 ............................................................................................................................................... 15-29版本历史 ...................................................................................................................................................... 15-30第16 章 基本同步串行口(BSSP) 16-1简介 ............................................................................................................................................................... 16-2控制寄存器 .................................................................................................................................................... 16-3SPITM 模式 .................................................................................................................................................... 16-6SSP 模块 的I2CTM 操作 ............................................................................................................................... 16-15初始化 ......................................................................................................................................................... 16-23设计技巧 ...................................................................................................................................................... 16-24相关应用笔记 ............................................................................................................................................... 16-25版本历史 ...................................................................................................................................................... 16-26第17 章 主同步串行口(MSSP) 17-1简介 ............................................................................................................................................................... 17-2控制寄存器 .................................................................................................................................................... 17-4SPITM 模式 .................................................................................................................................................... 17-9SSP 模块的 I2C™ 操作 ............................................................................................................................... 17-18I2CTM 总线的连接注意事项 ........................................................................................................................... 17-56初始化 ......................................................................................................................................................... 17-57设计技巧 ...................................................................................................................................................... 17-58相关应用笔记 ............................................................................................................................................... 17-59版本历史 ...................................................................................................................................................... 17-60第18 章 USART 18-1简介 ............................................................................................................................................................... 18-2控制寄存器 .................................................................................................................................................... 18-3USART 波特率发生器(BRG) ..................................................................................................................... 18-5USART 异步工作模式 ................................................................................................................................... 18-8USART 同步主控模式 .................................................................................................................................. 18-15USART 同步从动模式 ................................................................................................................................. 18-19初始化 ......................................................................................................................................................... 18-21设计技巧 ...................................................................................................................................................... 18-22相关应用笔记 ............................................................................................................................................... 18-23版本历史 ...................................................................................................................................................... 18-24第19 章 参考电压模块 19-1简介 ............................................................................................................................................................... 19-2控制寄存器 .................................................................................................................................................... 19-3配置参考电压 ................................................................................................................................................. 19-4参考电压精度 ................................................................................................................................................. 19-5休眠模式下的操作 ......................................................................................................................................... 19-5复位的影响 .................................................................................................................................................... 19-5连接注意事项 ................................................................................................................................................. 19-6初始化 ........................................................................................................................................................... 19-7设计技巧 ........................................................................................................................................................ 19-8相关应用笔记 ................................................................................................................................................. 19-9版本历史 ...................................................................................................................................................... 19-10第20 章 比较器 20-1简介 ............................................................................................................................................................... 20-2控制寄存器 .................................................................................................................................................... 20-3设置比较器模式 ............................................................................................................................................. 20-4比较器工作原理 ............................................................................................................................................. 20-6比较器参考源 ................................................................................................................................................. 20-6比较器的响应时间 ......................................................................................................................................... 20-8比较器输出 .................................................................................................................................................... 20-8比较器中断 .................................................................................................................................................... 20-9休眠状态下比较器的操作 ............................................................................................................................... 20-9复位的影响 .................................................................................................................................................... 20-9模拟输入连接方式注意事项 .......................................................................................................................... 20-10初始化 ......................................................................................................................................................... 20-11设计技巧 ...................................................................................................................................................... 20-12相关应用笔记 ............................................................................................................................................... 20-13版本历史 ...................................................................................................................................................... 20-14第21 章 8 位A/D 转换器 21-1简介 ............................................................................................................................................................... 21-2控制寄存器 .................................................................................................................................................... 21-3操作 ............................................................................................................................................................... 21-5A/D 采集时间要求 .......................................................................................................................................... 21-6A/D 转换时钟的选择 ...................................................................................................................................... 21-8配置模拟输入端口 ......................................................................................................................................... 21-9A/D 转换 ...................................................................................................................................................... 21-10休眠期间的A/D 转换 ................................................................................................................................... 21-12A/D 精度/ 误差 ............................................................................................................................................ 21-13复位对A/D 转换的影响 ................................................................................................................................ 21-13CCP 触发器的使用 ...................................................................................................................................... 21-14连接注意事项 ............................................................................................................................................... 21-14传递函数 ...................................................................................................................................................... 21-14初始化 ......................................................................................................................................................... 21-15设计技巧 ...................................................................................................................................................... 21-16相关应用笔记 ............................................................................................................................................... 21-17版本历史 ...................................................................................................................................................... 21-18第22 章 基本型8 位A/D 转换器 22-1简介 ............................................................................................................................................................... 22-2控制寄存器 .................................................................................................................................................... 22-3A/D 采集时间要求 .......................................................................................................................................... 22-6A/D 转换时钟的选择 ...................................................................................................................................... 22-8配置模拟输入端口 ....................................................................................................................................... 22-10A/D 转换 ...................................................................................................................................................... 22-11休眠期间的A/D 转换 ................................................................................................................................... 22-14A/D 转换精度/ 误差 ..................................................................................................................................... 22-15复位对A/D 转换的影响 ................................................................................................................................ 22-16连接时的考虑事项 ....................................................................................................................................... 22-16传递函数 ...................................................................................................................................................... 22-16初始化 ......................................................................................................................................................... 22-17设计技巧 ...................................................................................................................................................... 22-18相关应用笔记 ............................................................................................................................................... 22-19版本历史 ...................................................................................................................................................... 22-20第23 章 10 位A/D 转换器 23-1简介 ............................................................................................................................................................... 23-2控制寄存器 .................................................................................................................................................... 23-3操作 ............................................................................................................................................................... 23-5A/D 采集时间要求 .......................................................................................................................................... 23-6A/D 转换时钟的选择 ...................................................................................................................................... 23-8模拟输入引脚的设置 ...................................................................................................................................... 23-9A/D 转换的编程举例 .................................................................................................................................... 23-10休眠期间的A/D 转换 ................................................................................................................................... 23-14复位对A/D 转换的影响 ................................................................................................................................ 23-14A/D 转换精度与误差 .................................................................................................................................... 23-15连接时的考虑事项 ....................................................................................................................................... 23-16传递函数 ...................................................................................................................................................... 23-16初始化 ......................................................................................................................................................... 23-17设计技巧 ...................................................................................................................................................... 23-18相关应用笔记 ............................................................................................................................................... 23-19版本历史 ...................................................................................................................................................... 23-20第24 章 积分型A/D 转换器 24-1简介 ............................................................................................................................................................... 24-2控制寄存器 .................................................................................................................................................... 24-3转换过程 ........................................................................................................................................................ 24-6其它模拟模块 ............................................................................................................................................... 24-12校准参数 ...................................................................................................................................................... 24-13设计技巧 ...................................................................................................................................................... 24-14相关应用笔记 ............................................................................................................................................... 24-15版本历史 ...................................................................................................................................................... 24-16第25 章 LCD 25-1简介 ............................................................................................................................................................... 25-2控制寄存器 .................................................................................................................................................... 25-3LCD 定时 ....................................................................................................................................................... 25-6LCD 中断 ..................................................................................................................................................... 25-12像素控制 ...................................................................................................................................................... 25-13电压发生器 .................................................................................................................................................. 25-15休眠模式下的操作 ....................................................................................................................................... 25-16复位的影响 .................................................................................................................................................. 25-17LCD 模块的设置 .......................................................................................................................................... 25-17判别比 ......................................................................................................................................................... 25-18LCD 电压发生器 .......................................................................................................................................... 25-20对比度 ......................................................................................................................................................... 25-22LCD 玻璃基板 .............................................................................................................................................. 25-22初始化 ......................................................................................................................................................... 25-23设计技巧 ...................................................................................................................................................... 25-24相关应用笔记 ............................................................................................................................................... 25-25版本历史 ...................................................................................................................................................... 25-26第26 章 看门狗定时器与休眠模式 26-1简介 ............................................................................................................................................................... 26-2控制寄存器 .................................................................................................................................................... 26-3看门狗定时器(WDT)的操作 ....................................................................................................................... 26-4休眠省电模式 ................................................................................................................................................. 26-7初始化 ........................................................................................................................................................... 26-9设计技巧 ...................................................................................................................................................... 26-10相关应用笔记 ............................................................................................................................................... 26-11版本历史 ...................................................................................................................................................... 26-12第27 章 器件配置位 27-1简介 ............................................................................................................................................................... 27-2配置字位 ........................................................................................................................................................ 27-4编程校验/ 代码保护 ....................................................................................................................................... 27-8识别码ID 的位置 ........................................................................................................................................... 27-9设计技巧 ...................................................................................................................................................... 27-10相关应用笔记 ............................................................................................................................................... 27-11版本历史 ...................................................................................................................................................... 27-12第28 章 在线串行编程 28-1简介 ............................................................................................................................................................... 28-2进入在线串行编程模式 .................................................................................................................................. 28-3应用电路 ........................................................................................................................................................ 28-4编程器 ........................................................................................................................................................... 28-6编程环境 ........................................................................................................................................................ 28-6其它优点 ........................................................................................................................................................ 28-7PICmicro® OTP 型单片机的现场编程 ............................................................................................................. 28-8FLASH 型 PICmicro® 单片机的现场编程 ...................................................................................................... 28-10设计技巧 ...................................................................................................................................................... 28-12相关应用笔记 ............................................................................................................................................... 28-13版本历史 ...................................................................................................................................................... 28-14第29 章 指令集 29-1简介 ............................................................................................................................................................... 29-2指令格式 ........................................................................................................................................................ 29-4作为源/ 目标寄存器的特殊功能寄存器 ........................................................................................................... 29-6Q 周期操作 .................................................................................................................................................... 29-7指令描述 ........................................................................................................................................................ 29-8设计技巧 ...................................................................................................................................................... 29-45相关应用笔记 ............................................................................................................................................... 29-47版本历史 ...................................................................................................................................................... 29-48第30 章 电气规范 30-1简介 ............................................................................................................................................................... 30-2绝对最大值 .................................................................................................................................................... 30-3器件选型表 .................................................................................................................................................... 30-4器件电压规范 ................................................................................................................................................. 30-5器件电流特性 ................................................................................................................................................. 30-6输入阈值电平 ................................................................................................................................................. 30-9I/O 电流特性 ................................................................................................................................................ 30-10输出驱动电压 ............................................................................................................................................... 30-11I/O 引脚的容性负载 ..................................................................................................................................... 30-12数据EEPROM / 闪存 .................................................................................................................................. 30-13LCD ............................................................................................................................................................. 30-14比较器和参考电压 ....................................................................................................................................... 30-15时序参数符号 ............................................................................................................................................... 30-16外部时钟时序波形图和时序要求示例 ............................................................................................................ 30-17上电和复位时序波形图及要求示例 ............................................................................................................... 30-19定时器Timer0 和Timer1 时序波形图及要求示例 ......................................................................................... 30-20CCP 的时序图及要求 ................................................................................................................................... 30-21并行从动端口 (PSP) 时序图及要求 .............................................................................................................. 30-22SSP 和 MSSP SPITM 模式时序波形图及要求示例 ....................................................................................... 30-23SSP I2CTM 模式时序波形图及要求示例 ........................................................................................................ 30-27MSSP I2CTM 模式时序波形图及要求示例 ..................................................................................................... 30-30USART/SCI 时序波形图及要求示例 ............................................................................................................. 30-328 位 A/D 时序波形图及要求示例 ................................................................................................................... 30-3410 位A/D 时序波形图及要求示例 ................................................................................................................. 30-36积分型A/D 时序波形图及要求示例 ............................................................................................................... 30-38LCD 时序波形图及要求示例 ......................................................................................................................... 30-40相关应用笔记 ............................................................................................................................................... 30-41版本历史 ...................................................................................................................................................... 30-42第31 章 器件特性 31-1简介 ............................................................................................................................................................... 31-2特性和电气规范 ............................................................................................................................................. 31-2DC 和AC 特性图表 ....................................................................................................................................... 31-2版本历史 ...................................................................................................................................................... 31-22第32 章 开发工具 32-1简介 ............................................................................................................................................................... 32-2集成开发环境(IDE) ................................................................................................................................... 32-3MPLAB® 软件语言支持 ................................................................................................................................. 32-6MPLAB® SIM 软件模拟器 ............................................................................................................................... 32-8MPLAB® 硬件仿真器支持 ............................................................................................................................... 32-9MPLAB® 编程器支持 ................................................................................................................................... 32-10辅助工具 ...................................................................................................................................................... 32-11开发板 ......................................................................................................................................................... 32-12针对其它Microchip 产品的开发工具 ............................................................................................................ 32-14相关应用笔记 ............................................................................................................................................... 32-15版本历史 ...................................................................................................................................................... 32-16第33 章 代码开发 33-1版本历史 ........................................................................................................................................................ 33-2第34 章 附录 34-1I2CTM 概述...................................................................................................................................................... 34-2LCD 玻璃基板生产商.................................................................................................................................... 34-11改进的器件特性............................................................................................................................................ 34-13版本历史....................................................................................................................................................... 34-19第35 章 术语表 35-1版本历史 ...................................................................................................................................................... 35-14目录
上传时间: 2013-11-15
上传用户:nanshan
ucos-ii 编译器ICCAVR CPU atmega8 8M 晶振 对原作者的ucos进行了简化,去掉了 hook,保留了基本功能 代码精简,编译后代码占 mage8 的 49% 时钟使用Timer2,中断时间为2 ms 任务1:刷新LED,检测按键,调整时间 任务2:计时,串口发送 9600 bps
标签: ucos-ii atmega8 ICCAVR ucos
上传时间: 2015-03-18
上传用户:Avoid98
RtosSerial.lib rtosSerial.h 使用说明,本库利用51的Timer2,9600bps适用于有片内外部存储器的51芯片占用32byte缓存,重写putchar,getchar函数,循环队列,后台操作。 可与rtx51很好集成。任何人可以自由分发,和应用。有疑问可以联系serialrtos@163.net
标签: RtosSerial rtosSerial lib 使用说明
上传时间: 2014-01-21
上传用户:lindor
UCOS/II for ICCAVR - The version of UCOS/II is 2.04 - the original port was done by Ole Saether for the IAR compiler. Jens E. Holtegaard ported one version using ICCAVR. Joerg Meyer did another port (using Jens port as a start?). This is basically Joerg s port plus a little bit of changes and documentation by me. - YOU MUST DOWNLOAD THE MAIN PART OF THE UCOS/II FROM THE UCOS/II WEBSITE http://www.ucos-ii.com . The supplied project file assumes the portable source is in the ..\source directory. - Joerg has written couple document showing the stack frames etc. but it is in German :-) They are included in this directory. - The Timer2 overflow interrupt is used for Timer Tick. If you want to change that, modify os_cpu_c.c and os_cpu_a.s - I have tested this using ATMega103 with and without external RAM using AVR Studio simulator. See test1.c test program. Both Code Compressed (PRO) and STD versions have been tested.
标签: UCOS original Saether version
上传时间: 2015-11-14
上传用户:ippler8
用於 德州仪器 TI 281x 系列DSP,事件管理器及定时器设置,使PWM 信号产生之原码,可用於控制单向PWM或三相PWM马达。 This program sets up the EV timers (TIMER1, Timer2, TIMER3 and TIMER4) to generate T1PWM, T2PWM, T3PWM, T4PWM and PWM1-12 waveforms.
上传时间: 2016-05-28
上传用户:zhuyibin
在本课中,我们要用一个按键来实现跑马灯的 10 级调速。这又会涉及到键的去抖的问 题。 本课的试验结果是,每按一次按键,跑马速度就降低一级,共 10 级。 这里我们又增加了一个变量 speedlever,来保存当前的速度档次。 在按键里的处理中,多了当前档次的延时值的设置。 请看程序: ―――――――――――――――― #define uchar unsigned char //定义一下方便使用 #define uint unsigned int #define ulong unsigned long #include <reg52.h> //包括一个 52 标准内核的头文件 sbit P10 = P1^0; //头文件中没有定义的 IO 就要自己来定义了 sbit P11 = P1^1; sbit P12 = P1^2; sbit P13 = P1^3; sbit K1= P3^2; bit ldelay=0; //长定时溢出标记,预置是 0 uchar speed=10; //设置一个变量保存默认的跑马灯的移动速度 uchar speedlever=0; //保存当前的速度档次 char code dx516[3] _at_ 0x003b;//这是为了仿真设置的 //一个按键控制的 10 级变速跑马灯试验 void main(void) // 主程序 { uchar code ledp[4]={0xfe,0xfd,0xfb,0xf7};//预定的写入 P1 的值 uchar ledi; //用来指示显示顺序 uint n; RCAP2H =0x10; //赋 T2 的预置值 0x1000,溢出 30 次就是 1 秒钟 RCAP2L =0x00; TR2=1; //启动定时器 ET2=1; //打开定时器 2 中断 EA=1; //打开总中断 while(1) //主程序循环 { if(ldelay) //发现有时间溢出标记,进入处理 { ldelay=0; //清除标记 P1=ledp[ledi]; //读出一个值送到 P1 口 ledi++; //指向下一个 if(ledi==4) { ledi=0; //到了最后一个灯就换到第一个 } } if(!K1) //如果读到 K1 为 0 { for(n=0;n<1000;n++); //等待按键稳定 while(!K1); //等待按键松开 for(n=0;n<1000;n++); //等待按键稳定松开 speedlever++; if(speedlever==10)speedlever=0; speed=speedlever*3; //档次和延时之间的预算法则,也可以用查表方法,做出 不规则的法则 } } } //定时器 2 中断 Timer2() interrupt 5 { static uchar t; TF2=0; t++; if((t==speed)||(t>30)) //比较一个变化的数值,以实现变化的时间溢出,同时限制了最慢速 度为 1 秒 { t=0; ldelay=1;//每次长时间的溢出,就置一个标记,以便主程序处理 } } ―――――――――――――――――――――― 请打开 lesson11 目录的工程,编译,运行,看结果: 按 K1,速度则降低一次,总共 10 个档次。
上传时间: 2017-11-06
上传用户:szcyclone
LED 一般是恒流操作的,如何改变 LED 的亮度呢?答案就是 PWM 控制。在一定的 频率的方波中,调整高电平和低电平的占空比,即可实现。比如我们用低电平点亮一个 LED 灯,我们假设把一个频率周期分为 10 个时间等份,如果方波中的高低电平占空比是 9:1, 这是就是一个比较暗的亮度,如果方波中高低电平占空比是 10:0,这时,全部是高电平, 灯是灭的。如果占空比是 5:5,就是一个中间亮度,如果高低比是 1:9,是一个比较亮的 亮度,如果高低是 0:10,这时全部是低电平,就是最亮的。 实际上应用中,电视屏幕墙中的几十百万 LED 象素都是这样控制的,而且每一个象素 都有红绿蓝 3 个 LED,每个 LED 可以变化的亮度是几百到几万或者更多的级别,以实现真 彩色的显示。还有在您的手机中,背光灯的亮度如果是可以变化的,也应该是这种工作方式。 目前的城市彩灯也有很多都使用了 LED,需要控制亮度是也是 PWM 控制。 下面来分析我们的例程,在这个例程中,我们将定时器 2 溢出定为 1/1200 秒。每 10 次脉冲输出一个 120HZ 频率。这每 10 次脉冲再用来控制高低电平的 10 个比值。这样,在 每个 1/120 秒的方波周期中,我们都可以改变方波的输出占空比,从而控制 LED 灯的 10 个 级别的亮度。 为什么输出方波的频率要 120HZ 这么高?因为如果频率太低,人眼就会看到闪烁感 觉。一般起码要在 60HZ 以上才感觉好点,120HZ 就基本上看不到闪烁,只能看到亮度的变 化了。 下面请看程序,程序中有比较多的注释: ――――――――――――――――――――――― #define uchar unsigned char //定义一下方便使用 #define uint unsigned int #define ulong unsigned long #include <reg52.h> //包括一个 52 标准内核的头文件 sbit P10 = P1^0; //要控制的 LED 灯 sbit K1= P3^2; //按键 K1 uchar scale;//用于保存占空比的输出 0 的时间份额,总共 10 份 char code dx516[3] _at_ 0x003b;//这是为了仿真设置的 //模拟 PWM 输出控制灯的 10 个亮度级别 void main(void) // 主程序 { uint n; RCAP2H =0xF3; //赋 T2 的预置值,溢出 1 次是 1/1200 秒钟 RCAP2L =0x98; TR2=1; //启动定时器 ET2=1; //打开定时器 2 中断 EA=1; //打开总中断 while(1) //程序循环 { ;//主程序在这里就不断自循环,实际应用中,这里是做主要工作 for(n=0;n<50000;n++); //每过一会儿就自动加一个档次的亮度 scale++; if(scale==10)scale=0; } } //1/1200 秒定时器 2 中断 Timer2() interrupt 5 { static uchar tt; //tt 用来保存当前时间在一秒中的比例位置 TF2=0; tt++; if(tt==10) //每 1/120 秒整开始输出低电平 { tt=0; if(scale!=0) //这里加这一句是为了消除灭灯状态产生的鬼影 P10=0; } if(scale==tt) //按照当前占空比切换输出高电平 P10=1; } ―――――――――――――――――― 在主程序中,每延时一段时间,就自动换一个占空比,以使亮度自动变化,方便观察。 编译,运行,看结果。 可以看到,LED 的亮度以每种亮度 1 秒左右不断变化,共有 10 个级别。
上传时间: 2017-11-06
上传用户:szcyclone
TM52 系列 F8368 是一个新的,快速的 8051 架构,与业界标准 8051 指令集完全兼容的 8 位单片机,并保持了 8051 外围的功能模块。通常情况下,TM52 执行指令,比传统的 8051 架构快六倍。TM52-F8368通过集成多种功能在芯片上,提供更高的性能,更低的成本,能快速进入市场,包括8K 字节的闪存(Flash)程序存储器, 512 字节 SRAM,低电压复位(LVR),低电压检测(LVD),双时钟省电工作模式,8051 标准 UART 和定时器 Timer0/Timer1/Timer2,实时计时器 Timer3,LCD/LED 驱动器,3 组16 位脉冲宽度调制器(PWM), 7 组 16 位脉冲宽度调制器(PWM),16 通道的 12 位模数转换器(ADC),I2C 接口和看门狗定时器(WDT)。它的高可靠性和低功耗的特性,可广泛适用于消费电子及家用电器产品。
标签: 51单片机
上传时间: 2022-04-18
上传用户:jason_vip1