#include "DrvConfig.h"
#include "SM39R08A3.h"//"SM39R08A5.h"
#include "global.h"
#include "math.h"
u16 n_10ms=0,sinVal=0;
bit b_10ms=0;
void GPIO_Init()
{
P0M0 = 0x00;
 0M1 = 0xff;
 1M0 = 0x00;
 1M1 = 0x02; //P1.1 短路调电流
}
void Clock_Int()
{
CKCON = 0x00;
 FCON=0x01; //定时器时钟频率 Fosc
TMOD = 0x01;
TH0 = 0x0A9;
TL0 = 0x9A;
ET0 = 1;
TF0=0;
TR0 = 1;
}
void WDT_LVC_Int()
{
TAKEY=0x55;
TAKEY=0xaa;
TAKEY=0x5a;
WDTC=0xf7;
LVC|=0x81;
IELVI=1;
}
main()
{
GPIO_Init();
EA = 0;
Clock_Int();
WDT_LVC_Int();
EA =1;
PWMC = 0xa1;
while(1)
{
}
}
void Int_Time0(void) interrupt 1
{
u16 x=0;
TH0 = 0x0A9;
TL0 = 0x9A;
b_10ms=1;
if(b_10ms==1)
{
b_10ms=0;
n_10ms++;
if(n_10ms==10)
{
for(x=0;x<360;x++)
{
sinVal=255*(1+sin(x*(6.28/360)))/2;
PWMD0H = (sinVal>>8)|(0<<7);
PWMD0L = (sinVal);
PWMMDH = 1023>>8;
PWMMDL = (1023);
}
n_10ms=0;
}
}
}
请勿各位大神,这程序应该怎么改,才能输出50HZ的正弦波,谢谢
|