/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Website: http://www.nuvoton.com
// E-Mail : MicroC-8bit@nuvoton.com
// Date : Jan/21/2019
//***********************************************************************************************************
//***********************************************************************************************************
// File Function: ML51 GPIO toggle demo code
//***********************************************************************************************************
#include "ML51.H"
#include "math.h"
//----------------------------------------------------------------------------------------------//
void main (void)
{
int i=0;
unsigned int j=0;
unsigned char tab[]={0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,2 ,2 ,3 ,3 ,3 ,4 ,4 ,4 ,5 ,5 ,6 ,6 ,7 ,7 ,8 ,8 ,9 ,9 ,10 ,11 ,11 ,12 ,13 ,13 ,14 ,15 ,16 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 ,31 ,33 ,34 ,35 ,36 ,37 ,39 ,40 ,41 ,43 ,44 ,46 ,47 ,49 ,50 ,52 ,53 ,55 ,56 ,58 ,60 ,61 ,63 ,65 ,66 ,68 ,70 ,72 ,74 ,75 ,77 ,79 ,81 ,83 ,85 ,87 ,89 ,91 ,94 ,96 ,98 ,100 };
//PWM时钟源为系统时钟FSYS
PWM0_ClockSource(PWM_FSYS,128);
MFP_P03_PWM0_CH2;
P03_PUSHPULL_MODE;
PWM0_ConfigOutputChannel(2,Independent,EdgeAligned,0x6FF,20);
PWM0_RUN();
while(1)
{
for(i=0;i<=100;i++)
{
Timer3_Delay(24000000,4,1,10000);
//P03 ^=1;
j=(unsigned int)(pow(i,2.2)/251.1886);
//允许载入新的占空比
set_PWM0CON0_LOAD;
PWM0_ConfigOutputChannel(2,Independent,EdgeAligned,0x6FF,j);
}
for(i=100;i>=0;i--)
{
Timer3_Delay(24000000,4,1,10000);
//P03 ^=1;
j=(unsigned int)(pow(i,2.2)/251.1886);
//允许载入新的占空比
set_PWM0CON0_LOAD;
PWM0_ConfigOutputChannel(2,Independent,EdgeAligned,0x6FF,j);
}
}
}