📄 pwmdac_test.c
字号:
#define LPCEB2000_I
/*********************************************************************************************
* File: pwmdac_test.c
* Author: Embest w.h.xie
* Desc: test pwmdac
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "target.h"
/*********************************************************************************************
* name: time_dly
* func: display code
* para: dly --in, delay value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void time_dly(uint32 dly)
{
uint32 i;
for(; dly>0; dly--)
for(i=0; i<500; i++);
}
/*********************************************************************************************
* name: sys_init
* func: init the sys
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void sys_init()
{
// allow PLL
PLLCON = 1;
VPBDIV = PLL_VPBDIV;
PLLCFG = PLL_CFG;
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
// set MAM 2 CCLK
MAMCR = 0;
MAMTIM = MAM_TIM;
MAMCR = 2;
// init all interrupt
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
}
/*********************************************************************************************
* name: pwm_Init
* func: init the pwm
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void pwm_init(void)
{
PWM_PR = 100; // 100 PR
PWM_MCR = 0x02; // PWM2 match
PWM_MR0 = 100; // set PWM0 register
PWM_MR5 = 50; // set PWM5 register
PWM_LER = 0x21; // PWM0 and PWM5 read-in
PWM_PCR = 0x2000; // set PWMENA5 bit
PWM_TCR = 0x09; // start PWM
}
/*********************************************************************************************
* name: Main
* func: main fun
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int main(void)
{
uint8 i ,j;
// init GPIO
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000400;
sys_init();
pwm_init();
do{
for (i=0; i<200 ; i++) {
j = i;
if (i>100) j = 200 - i;
PWM_MR0 = 100;
PWM_MR5 = j; // set PWM5 register
PWM_LER = 0x21; // PWM0 and PWM5 read-in
time_dly(20);
}
} while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -