代码工程:
SPWM数据:
中颖单片机源码如下:
- /*****************************
- 说明:
- SH88F516集成了3个8位PWM模块,可以分别通过各自的PWMCON寄存器控制PWM模块的时钟,PWMP寄存器控制PWM输出波形的周期,PWMD寄存器控制PWM输出波形的
- 占空比,从而产生周期和占空比分别可调整的脉宽调制波形.在PWM输出允许期间可以修改这三个寄存器,但在下一个PWM周期修改才会起作用. PWM定时器提
- 供3个中断源,在每个PWM周期都会产生中断.他们有不同的标志位,共享一个中断向量地址.
- 本程序通过PWM0中断和查表的方式输出50Hz正弦波,示波器测量时,J9右端测量,左端接地,
- 要求;打开J13的1脚
- ****************************/
- #include <sh88f516.h>
- /*unsigned char code SPWM[200]={50,52,53,55,56,58,59,61,62,64,65,67,68,70,71,73,74,
- 75,77,78,79,81,82,83,84,85,86,88,89,90,90,91,92,93,
- 94,95,95,96,96,97,98,98,98,99,99,99,100,100,100,100,
- 100,100,100,100,100,99,99,99,98,98,98,97,96,96,95,95,
- 94,93,92,91,90,90,89,88,86,85,84,83,82,81,79,78,77,
- 75,74,73,71,70,68,67,65,64,62,61,59,58,56,55,53,52,
- 50,48,47,45,44,42,41,39,38,36,35,33,32,30,29,27,26,
- 25,23,22,21,19,18,17,16,15,14,12,11,10,10,9,8,7,6,5,
- 5,4,4,3,2,2,2,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,2,2,2,3,
- 4,4,5,5,6,7,8,9,10,10,11,12,14,15,16,17,18,19,21,22,
- 23,25,26,27,29,30,32,33,35,36,38,39,41,42,44,45,47,48};
- */
- unsigned char SpwmCount;
- void init();
- main()
- {
- int i,j;
- P1 = 0xff;
- init();
- while(1)
- {
- for (i=500; i>0; i--)
- {
- P1 |= 0x0f;
- }
- for (j=500; j>0; j--)
- {
- P1 &= 0x00;
- }
- }
- }
- void init()
- {
- CLKCON = 0x00; //系统时钟=晶振频率
- PWM0P = 2; //PWM0输出周期 = PWM0P[7-0]*PWM0时钟
- PWM0D = 1; //PWM0输出占空比 = PWM0D[7-0]*PWM0时钟 50%
- PWM0CON = 0x81; //PWM0控制寄存器; 1011 0001---打开PWM0定时器,并从PWM0管脚输出 占空比极性为高,时钟为系统时钟的1/16
- IEN1 = 0x20; //开启PWM中断 EPWM=1 但是这边不能使用位操作,不具备位寻址功能
- EA = 1; //开启总中断
- SpwmCount = 0;
- }
- void PWM_INT() interrupt 12 using 3 //PWM 0/1/2的中断号共享为12.
- {
- /* if(PWM0CON & 0x02) //判断是否为PWM1中断?
- {
- SpwmCount++;
- if(SpwmCount>=200)
- SpwmCount=0;
- PWM0D = 1; //SPWM[SpwmCount]; //查表得到相应的正弦值
- }
- */
- // PWM0CON &= 0xFD; //清除中断标志位 PWMIF=0但是这边不能使用位操作,不具备位寻址功能
- …………
- …………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
[color=rgb(51, 102, 153) !important]复制代码
压缩包里面包含有中颖单片机sh88f516常用功能的源码,中文注释都很详细
下载地址:http://www.51hei.com/bbs/dpj-98300-1.html
|
|