控制所有PWM輸出的代碼
/**************************************************************************//**
* @file main.c
* @version V1.00
* $Revision: 2 $
* $Date: 14/12/25 10:24a $
* @brief Change duty cycle and period of output waveform by BPWM Double Buffer function.
* @note
* Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "M0518.h"
/*---------------------------------------------------------------------------------------------------------*/
/* Macro, type and constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define PLLCON_SETTING CLK_PLLCON_50MHz_HXT
#define PLL_CLOCK 50000000
/*---------------------------------------------------------------------------------------------------------*/
/* Global variables */
/*---------------------------------------------------------------------------------------------------------*/
/**
* @brief BPWM0 IRQ Handler
*
* @param None
*
* @return None
*
* @Details ISR to handle BPWM0 interrupt event
*/
void BPWM0_IRQHandler(void)
{
static int toggle = 0;
// Update BPWM0 channel 0 period and duty
if(toggle == 0)
{
BPWM_SET_CNR(BPWM0, 0, 99);
BPWM_SET_CMR(BPWM0, 0, 39);
}
else
{
BPWM_SET_CNR(BPWM0, 0, 399);
BPWM_SET_CMR(BPWM0, 0, 199);
}
toggle ^= 1;
// Clear channel 0 period interrupt flag
BPWM_ClearPeriodIntFlag(BPWM0, 0);
}
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Enable Internal RC clock */
CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
/* Waiting for IRC22M clock ready */
CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
/* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
/* Enable external 12MHz XTAL, internal 22.1184MHz */
CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk | CLK_PWRCON_OSC22M_EN_Msk);
/* Enable PLL and Set PLL frequency */
CLK_SetCoreClock(PLL_CLOCK);
/* Waiting for clock ready */
CLK_WaitClockReady(CLK_CLKSTATUS_PLL_STB_Msk | CLK_CLKSTATUS_XTL12M_STB_Msk | CLK_CLKSTATUS_OSC22M_STB_Msk);
/* Switch HCLK clock source to PLL, STCLK to HCLK/2 */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(2));
/* Enable UART module clock */
CLK_EnableModuleClock(UART0_MODULE);
/* Select UART module clock source */
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));
/* Enable BPWM0 clock source */
CLK_EnableModuleClock(PWM0_MODULE);
CLK_EnableModuleClock(PWM1_MODULE);
CLK_EnableModuleClock(BPWM0_MODULE);
CLK_EnableModuleClock(BPWM1_MODULE);
/* Select BPWM module clock source */
CLK_SetModuleClock(PWM0_MODULE, CLK_CLKSEL3_PWM0_S_PLL, 0);
CLK_SetModuleClock(PWM1_MODULE, CLK_CLKSEL3_PWM1_S_PLL, 0);
CLK_SetModuleClock(BPWM0_MODULE, CLK_CLKSEL3_BPWM0_S_PLL, 0);
CLK_SetModuleClock(BPWM1_MODULE, CLK_CLKSEL3_BPWM1_S_PLL, 0);
/* Reset BPWM0 */
SYS_ResetModule(PWM0_RST);
SYS_ResetModule(PWM1_RST);
SYS_ResetModule(BPWM0_RST);
SYS_ResetModule(BPWM1_RST);
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
//SystemCoreClockUpdate();
PllClock = PLL_CLOCK; // PLL
SystemCoreClock = PLL_CLOCK / 1; // HCLK
CyclesPerUs = PLL_CLOCK / 1000000; // For SYS_SysTickDelay()
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set GPB multi-function pins for UART0 RXD and TXD */
SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB0_Msk | SYS_GPB_MFP_PB1_Msk);
SYS->GPB_MFP |= (SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD);
#if 1
/* Set GPA.12/13/14/15/0/1 multi-function pins for PWM0 Channel 0 ~ channel 5 */
SYS->GPA_MFP &= ~(SYS_GPA_MFP_PA12_Msk | SYS_GPA_MFP_PA13_Msk | SYS_GPA_MFP_PA14_Msk | SYS_GPA_MFP_PA15_Msk);
SYS->GPA_MFP |= (SYS_GPA_MFP_PA12_PWM0_CH0 | SYS_GPA_MFP_PA13_PWM0_CH1 | SYS_GPA_MFP_PA14_PWM0_CH2 | SYS_GPA_MFP_PA15_PWM0_CH3);
//SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PA0_Msk | SYS_ALT_MFP3_PA1_Msk);
SYS->ALT_MFP4 &= ~(SYS_ALT_MFP4_PA12_Msk | SYS_ALT_MFP4_PA13_Msk );
/* Set GPA.2/3 multi-function pins for PWM1 Channel 0 ~ channel 1 */
SYS->GPA_MFP &= ~(SYS_GPA_MFP_PA2_Msk | SYS_GPA_MFP_PA3_Msk);
SYS->GPA_MFP |= (SYS_GPA_MFP_PA2_PWM1_CH0 | SYS_GPA_MFP_PA3_PWM1_CH1);
SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PA2_Msk | SYS_ALT_MFP3_PA3_Msk);
SYS->ALT_MFP3 |= (SYS_ALT_MFP3_PA2_PWM1_CH0 | SYS_ALT_MFP3_PA3_PWM1_CH1);
SYS->ALT_MFP4 &= ~(SYS_ALT_MFP4_PA2_Msk | SYS_ALT_MFP4_PA3_Msk);
/* Set GPA.11 multi-function pins for PWM1 Channel 3 */
SYS->GPA_MFP &= ~(SYS_GPA_MFP_PA11_Msk|SYS_GPA_MFP_PA10_Msk);
SYS->GPA_MFP |= SYS_GPA_MFP_PA11_PWM1_CH3|SYS_GPA_MFP_PA10_PWM1_CH2;
SYS->ALT_MFP3 &= ~SYS_ALT_MFP3_PA11_Msk|SYS_ALT_MFP3_PA10_Msk;
SYS->ALT_MFP3 |= SYS_ALT_MFP3_PA11_PWM1_CH3|SYS_ALT_MFP3_PA10_PWM1_CH2;
/* Set GPF.4 multi-function pins for PWM1 Channel 4 to output IrDA code*/
SYS->GPF_MFP &= ~(SYS_GPF_MFP_PF4_Msk);
SYS->GPF_MFP |= (SYS_GPF_MFP_PF4_PWM1_CH4);
SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PF4_Msk);
SYS->ALT_MFP3 |= (SYS_ALT_MFP3_PF4_PWM1_CH4);
/* Set GPF.5 multi-function pins for PWM1 Channel 5 to drive Head LED*/
SYS->GPF_MFP &= ~(SYS_GPF_MFP_PF5_Msk);
SYS->GPF_MFP |= (SYS_GPF_MFP_PF5_PWM1_CH5);
SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PF5_Msk);
SYS->ALT_MFP3 |= (SYS_ALT_MFP3_PF5_PWM1_CH5);
SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB11_Msk);
SYS->GPB_MFP |= (SYS_GPB_MFP_PB11_PWM0_CH4);
SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PB11_Msk);
SYS->ALT_MFP3 |= (SYS_ALT_MFP3_PB11_PWM0_CH4);
SYS->GPE_MFP &= ~(SYS_GPE_MFP_PE5_Msk);
SYS->GPE_MFP |= (SYS_GPE_MFP_PE5_PWM0_CH5);
SYS->ALT_MFP &= ~(SYS_ALT_MFP_PE5_Msk);
SYS->ALT_MFP |= (SYS_ALT_MFP_PE5_PWM0_CH5);
/* Set GPC.0/1/2/3 and GPD.15/14 multi-function pins for BPWM0 Channel 0 ~ channel 5 */
SYS->GPC_MFP &= ~(SYS_GPC_MFP_PC0_Msk | SYS_GPC_MFP_PC1_Msk | SYS_GPC_MFP_PC2_Msk | SYS_GPC_MFP_PC3_Msk);
SYS->GPC_MFP |= (SYS_GPC_MFP_PC0_BPWM0_CH0 | SYS_GPC_MFP_PC1_BPWM0_CH1 | SYS_GPC_MFP_PC2_BPWM0_CH2 | SYS_GPC_MFP_PC3_BPWM0_CH3);
SYS->GPD_MFP &= ~(SYS_GPD_MFP_PD15_Msk | SYS_GPD_MFP_PD14_Msk);
SYS->GPD_MFP |= (SYS_GPD_MFP_PD15_BPWM0_CH4 | SYS_GPD_MFP_PD14_BPWM0_CH5);
SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PC0_Msk | SYS_ALT_MFP3_PC1_Msk | SYS_ALT_MFP3_PC2_Msk | SYS_ALT_MFP3_PC3_Msk | SYS_ALT_MFP3_PD15_Msk | SYS_ALT_MFP3_PD14_Msk);
SYS->ALT_MFP3 |= (SYS_ALT_MFP3_PC0_BPWM0_CH0 | SYS_ALT_MFP3_PC1_BPWM0_CH1 | SYS_ALT_MFP3_PC2_BPWM0_CH2 | SYS_ALT_MFP3_PC3_BPWM0_CH3 | SYS_ALT_MFP3_PD15_BPWM0_CH4 | SYS_ALT_MFP3_PD14_BPWM0_CH5);
/* Set GPB.8/12, GPD.7/6 and GPF.0/1 multi-function pins for BPWM1 Channel 0 ~ channel 5 */
SYS->GPD_MFP &= ~(SYS_GPD_MFP_PD7_Msk | SYS_GPD_MFP_PD6_Msk);
SYS->GPD_MFP |= (SYS_GPD_MFP_PD7_BPWM1_CH0 | SYS_GPD_MFP_PD6_BPWM1_CH1);
SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB8_Msk | SYS_GPB_MFP_PB12_Msk|SYS_GPB_MFP_PB15_Msk);
SYS->GPB_MFP |= (SYS_GPB_MFP_PB8_BPWM1_CH2 | SYS_GPB_MFP_PB12_BPWM1_CH3|SYS_GPB_MFP_PB15_BPWM1_CH5);
SYS->ALT_MFP2 |=SYS_ALT_MFP2_PB15_BPWM1_CH5;
SYS->GPF_MFP &= ~(SYS_GPF_MFP_PF8_Msk );
SYS->GPF_MFP |= (SYS_GPF_MFP_PF8_BPWM1_CH4 );
SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PD7_Msk | SYS_ALT_MFP3_PD6_Msk | SYS_ALT_MFP3_PB8_Msk | SYS_ALT_MFP3_PB12_Msk | SYS_ALT_MFP3_PF8_Msk | SYS_ALT_MFP3_PB15_Msk);
SYS->ALT_MFP3 |= (SYS_ALT_MFP3_PD7_BPWM1_CH0 | SYS_ALT_MFP3_PD6_BPWM1_CH1 | SYS_ALT_MFP3_PB8_BPWM1_CH2 | SYS_ALT_MFP3_PB12_BPWM1_CH3 | SYS_ALT_MFP3_PF8_BPWM1_CH4|SYS_ALT_MFP3_PB15_BPWM1_CH5);
#endif
}
void UART0_Init()
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init UART */
/*---------------------------------------------------------------------------------------------------------*/
/* Reset IP */
SYS_ResetModule(UART0_RST);
/* Configure UART0 and set UART0 Baudrate */
UART_Open(UART0, 115200);
}
void PWM01_Init(void)
{
/* Set PWM0/1 channel 0/2/4 as independent mode and down count type */
PWM0->CTL1 = 0x0111;
PWM1->CTL1 = 0x0111;
/* Set BPWM0/1 all 6 channels as down count type */
BPWM0->CTL1 = 0x01;
BPWM1->CTL1 = 0x01;
/* Enable all PWM0/1 channels output */
PWM_EnableOutput(PWM0, 0x3F);
PWM_EnableOutput(PWM1, 0x3F);
/* Enable all BPWM0/1 channels output */
BPWM_EnableOutput(BPWM0, 0x3F);
BPWM_EnableOutput(BPWM1, 0x3F);
}
unsigned int i,j,cnt;
void TMR0_IRQHandler(void)
{
if(TIMER_GetIntFlag(TIMER0) == 1)
{
/* Clear Timer0 time-out interrupt flag */
TIMER_ClearIntFlag(TIMER0);
i=i+2;
j=j-2;
}
}
void TMR1_IRQHandler(void)
{
if(TIMER_GetIntFlag(TIMER1) == 1)
{
/* Clear Timer0 time-out interrupt flag */
TIMER_ClearIntFlag(TIMER1);
i=i+1;
cnt=cnt+1;
if(cnt==8)
cnt=0;
// j=j-2;
}
}
void TMR2_IRQHandler(void)
{
if(TIMER_GetIntFlag(TIMER2) == 1)
{
/* Clear Timer0 time-out interrupt flag */
TIMER_ClearIntFlag(TIMER2);
i=i+1;
// j=j-2;
}
}
int updatedmode;
#define BLUE 0X1
#define RED 0x2
#define GREEN 0x3
#define YELLOW 0x04//green + red
#define PINK 0X05 //red + blue
#define CYAN 0x06 //green + blue
#define WHITE 0X07 //red+green_blue
#define NONE 0X00
int color_array_init[8][3]={//blue, red, green
{ 0, 0, 0}, //none
{100, 0, 0}, //BLUE
{ 0, 100, 0}, //RED
{ 0, 0, 100}, //GREEN
{ 0, 100, 100}, //YELLOW=red + green
{100, 100, 0}, //PINK
{100, 0, 100}, //CYAN
{100, 100, 100} //WHITE
};
int color_array[8][3];
int r,g,b;
void color_table_adj(unsigned int color,int duty)
{
if (color==BLUE)
{
color_array[BLUE][0]=duty;
color_array[BLUE][1]=0;
color_array[BLUE][2]=0;
}
if (color==RED)
{
color_array[RED][0]=0;
color_array[RED][1]=duty;
color_array[RED][2]=0;
}
if (color==GREEN)
{
color_array[GREEN][0]=0;
color_array[GREEN][1]=0;
color_array[GREEN][2]=duty;
}
if (color==YELLOW)
{
color_array[YELLOW][0]=0;
color_array[YELLOW][1]=duty;
color_array[YELLOW][2]=duty;
}
if (color==PINK)
{
color_array[PINK][0]=duty;
color_array[PINK][1]=duty;
color_array[PINK][2]=0;
}
if (color==CYAN)
{
color_array[CYAN][0]=duty;
color_array[CYAN][1]=0;
color_array[CYAN][2]=duty;
}
if (color==WHITE)
{
color_array[WHITE][0]=duty;
color_array[WHITE][1]=duty;
color_array[WHITE][2]=duty;
}
}
void LED1(unsigned int color)
{
PWM_ConfigOutputChannel(PWM0, 0, 10000, color_array[color][0]);//B COLOR
PWM_ConfigOutputChannel(PWM0, 1, 10000, color_array[color][1]);//R COLOR
PWM_ConfigOutputChannel(PWM0, 2, 10000, color_array[color][2]);//g COLOR
}
void LED8(unsigned int color)
{
PWM_ConfigOutputChannel(PWM0, 3, 10000, color_array[color][0]);//B COLOR
PWM_ConfigOutputChannel(PWM0, 4, 10000, color_array[color][1]);//R COLOR
PWM_ConfigOutputChannel(PWM0, 5, 10000, color_array[color][2]);//g COLOR
}
void LED7(unsigned int color)
{
BPWM_ConfigOutputChannel(BPWM0, 0, 10000, color_array[color][0]);//B COLOR
BPWM_ConfigOutputChannel(BPWM0, 1, 10000, color_array[color][1]);//R COLOR
BPWM_ConfigOutputChannel(BPWM0, 2, 10000, color_array[color][2]);//g COLOR
}
void LED6(unsigned int color)
{
BPWM_ConfigOutputChannel(BPWM0, 3, 10000, color_array[color][0]);//B COLOR
BPWM_ConfigOutputChannel(BPWM0, 4, 10000, color_array[color][1]);//R COLOR
BPWM_ConfigOutputChannel(BPWM0, 5, 10000, color_array[color][2]);//g COLOR
}
void LED5(unsigned int color)
{
BPWM_ConfigOutputChannel(BPWM1, 0, 10000, color_array[color][0]);//B COLOR
BPWM_ConfigOutputChannel(BPWM1, 1, 10000, color_array[color][1]);//R COLOR
BPWM_ConfigOutputChannel(BPWM1, 2, 10000, color_array[color][2]);//g COLOR
}
void LED3(unsigned int color)
{
BPWM_ConfigOutputChannel(BPWM1, 3, 10000, color_array[color][0]);//B COLOR
BPWM_ConfigOutputChannel(BPWM1, 4, 10000, color_array[color][1]);//R COLOR
BPWM_ConfigOutputChannel(BPWM1, 5, 10000, color_array[color][2]);//g COLOR
}
void LED2(unsigned int color)
{
PWM_ConfigOutputChannel(PWM1, 0, 10000, color_array[color][0]);//B COLOR
PWM_ConfigOutputChannel(PWM1, 1, 10000, color_array[color][1]);//R COLOR
PWM_ConfigOutputChannel(PWM1, 2, 10000, color_array[color][2]);//g COLOR
}
void LED4(unsigned int color)
{
PWM_ConfigOutputChannel(PWM1, 3, 10000, color_array[color][0]);//B COLOR
PWM_ConfigOutputChannel(PWM1, 4, 10000, color_array[color][1]);//R COLOR
PWM_ConfigOutputChannel(PWM1, 5, 10000, color_array[color][2]);//g COLOR
}
void(*p_function[8])(unsigned int color) ;
unsigned int temp;
/*---------------------------------------------------------------------------------------------------------*/
/* Main Function */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, IP clock and multi-function I/O */
SYS_Init();
/* Lock protected registers */
//SYS_LockReg();
/* Init UART to 115200-8n1 for print message */
UART0_Init();
// PA->PMD=0x55555555;
// PB->PMD=0x55555555;
// PC->PMD=0x55555555;
// PD->PMD=0x55555555;
// PE->PMD=0x55555555;
// PF->PMD=0x55555555;
//GPIO_SetMode(PA,BIT12,GPIO_PMD_OUTPUT);
//GPIO_SetMode(PA,BIT13,GPIO_PMD_OUTPUT);
//GPIO_SetMode(PA,BIT14,GPIO_PMD_OUTPUT);
// PA12=0;
// PA13=0;
// PA14=0;
#if 1
PWM01_Init();
// PWM0 channel 0 frequency is 100Hz, duty 30%,
PWM_ConfigOutputChannel(PWM0, 0, 10000, 0);//B COLOR
PWM_ConfigOutputChannel(PWM0, 1, 10000, 0);//R COLOR
PWM_ConfigOutputChannel(PWM0, 2, 10000, 0);//g COLOR
PWM_ConfigOutputChannel(PWM0, 3, 256000, 0);
PWM_ConfigOutputChannel(PWM0, 4, 256000, 0);
PWM_ConfigOutputChannel(PWM0, 5, 256000, 0);
PWM_ConfigOutputChannel(PWM1, 0, 256000, 0);
PWM_ConfigOutputChannel(PWM1, 1, 256000, 0);
PWM_ConfigOutputChannel(PWM1, 2, 256000, 0);
PWM_ConfigOutputChannel(PWM1, 3, 256000, 0);
PWM_ConfigOutputChannel(PWM1, 4, 256000, 0);
PWM_ConfigOutputChannel(PWM1, 5, 256000, 0);
BPWM_ConfigOutputChannel(BPWM0, 0, 256000, 0);
BPWM_ConfigOutputChannel(BPWM0, 1, 256000, 0);
BPWM_ConfigOutputChannel(BPWM0, 2, 256000, 0);
BPWM_ConfigOutputChannel(BPWM0, 3, 256000, 0);
BPWM_ConfigOutputChannel(BPWM0, 4, 256000, 0);
BPWM_ConfigOutputChannel(BPWM0, 5, 256000, 0);
BPWM_ConfigOutputChannel(BPWM1, 0, 256000, 0);
BPWM_ConfigOutputChannel(BPWM1, 1, 256000, 0);
BPWM_ConfigOutputChannel(BPWM1, 2, 256000, 0);
BPWM_ConfigOutputChannel(BPWM1, 3, 256000,0);
BPWM_ConfigOutputChannel(BPWM1, 4, 256000, 0);
BPWM_ConfigOutputChannel(BPWM1, 5, 256000, 0);
/* Start all PWM0/1 counters */
PWM_Start(PWM0, 0x3f);
PWM_Start(PWM1, 0x3f);
/* Start all BPWM0/1 counters */
BPWM_Start(BPWM0, 0x1);
BPWM_Start(BPWM1, 0x1);
#endif
p_function[0]= LED1;
p_function[1]= LED2;
p_function[2]= LED3;
p_function[3]= LED4;
p_function[4]= LED5;
p_function[5]= LED6;
p_function[6]= LED7;
p_function[7]= LED8;
(*p_function[0]) (BLUE);
(*p_function[1]) (RED);
(*p_function[2]) (GREEN);
(*p_function[3]) (WHITE);
(*p_function[4]) (PINK);
(*p_function[5]) (YELLOW);
(*p_function[6]) (CYAN);
(*p_function[7]) (BLUE);
CLK_EnableModuleClock(TMR0_MODULE);
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HXT, 0);
TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 16);
TIMER_EnableInt(TIMER0);
NVIC_EnableIRQ(TMR0_IRQn);
TIMER_Start(TIMER0);
CLK_EnableModuleClock(TMR1_MODULE);
CLK_SetModuleClock(TMR1_MODULE, CLK_CLKSEL1_TMR1_S_HXT, 0);
TIMER_Open(TIMER1, TIMER_PERIODIC_MODE,1);
TIMER_EnableInt(TIMER1);
NVIC_EnableIRQ(TMR1_IRQn);
TIMER_Start(TIMER1);
cnt=0;
i=0;
temp=0;
while(1){
if(i>80)
{
i=1;
if (updatedmode==1)
updatedmode=0;
else
{
updatedmode=1;
j=80;
}
}
if(updatedmode==0)
{
color_table_adj(BLUE,i);
(*p_function[0]) (BLUE);
(*p_function[1]) (BLUE);
(*p_function[2]) (BLUE);
(*p_function[3]) (BLUE);
(*p_function[4]) (BLUE);
(*p_function[5]) (BLUE);
(*p_function[6]) (BLUE);
(*p_function[7]) (BLUE);
(*p_function[cnt]) (PINK);
}
else
{
color_table_adj(BLUE,j);
color_table_adj(PINK,100);
(*p_function[0]) (BLUE);
(*p_function[1]) (BLUE);
(*p_function[2]) (BLUE);
(*p_function[3]) (BLUE);
(*p_function[4]) (BLUE);
(*p_function[5]) (BLUE);
(*p_function[6]) (BLUE);
(*p_function[7]) (BLUE);
(*p_function[cnt]) (PINK);
}
}
#if 0
CLK_EnableModuleClock(TMR2_MODULE);
CLK_SetModuleClock(TMR2_MODULE, CLK_CLKSEL1_TMR1_S_HXT, 0);
TIMER_Open(TIMER2, TIMER_PERIODIC_MODE,2);
TIMER_EnableInt(TIMER2);
NVIC_EnableIRQ(TMR2_IRQn);
TIMER_Start(TIMER2);
i=0;
temp=0;
while(1){
if(i!=temp)
{
temp=i;
if(i==8)
i=0;
(*p_function[0]) (GREEN);
(*p_function[1]) (GREEN);
(*p_function[2]) (GREEN);
(*p_function[3]) (GREEN);
(*p_function[4]) (GREEN);
(*p_function[5]) (GREEN);
(*p_function[6]) (GREEN);
(*p_function[7]) (GREEN);
(*p_function) (BLUE);
}
}
#endif
#if 0
CLK_EnableModuleClock(TMR1_MODULE);
CLK_SetModuleClock(TMR1_MODULE, CLK_CLKSEL1_TMR1_S_HXT, 0);
TIMER_Open(TIMER1, TIMER_PERIODIC_MODE,100);
TIMER_EnableInt(TIMER1);
NVIC_EnableIRQ(TMR1_IRQn);
TIMER_Start(TIMER1);
i=0;
temp=0;
while(1){
if(i!=temp)
{
temp=i;
if(i==8)
i=0;
(*p_function[0]) (NONE);
(*p_function[1]) (NONE);
(*p_function[2]) (NONE);
(*p_function[3]) (NONE);
(*p_function[4]) (NONE);
(*p_function[5]) (NONE);
(*p_function[6]) (NONE);
(*p_function[7]) (NONE);
(*p_function) (BLUE);
}
}
#endif
#if 0
CLK_EnableModuleClock(TMR0_MODULE);
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HXT, 0);
TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 16);
TIMER_EnableInt(TIMER0);
NVIC_EnableIRQ(TMR0_IRQn);
TIMER_Start(TIMER0);
i=0;
while(1){
if(i>80)
{
i=1;
if (updatedmode==1)
updatedmode=0;
else
{
updatedmode=1;
j=80;
}
}
if(updatedmode==0)
{
PWM_ConfigOutputChannel(PWM0, 0, 16000,i);//B COLOR
PWM_ConfigOutputChannel(PWM0, 3, 16000,i);//B COLOR
PWM_ConfigOutputChannel(PWM1, 0, 16000,i);//B COLOR
PWM_ConfigOutputChannel(PWM1, 3, 16000,i);//B COLOR
BPWM_ConfigOutputChannel(BPWM0, 0, 16000, i);
BPWM_ConfigOutputChannel(BPWM0, 3, 16000, i);
BPWM_ConfigOutputChannel(BPWM1, 0, 16000, i);
BPWM_ConfigOutputChannel(BPWM1, 3, 16000, i);
}
else
{
PWM_ConfigOutputChannel(PWM0, 0, 16000,j);//B COLOR
PWM_ConfigOutputChannel(PWM0, 3, 16000,j);//B COLOR
PWM_ConfigOutputChannel(PWM1, 0, 16000,j);//B COLOR
PWM_ConfigOutputChannel(PWM1, 3, 16000,j);//B COLOR
BPWM_ConfigOutputChannel(BPWM0, 0, 16000,j);
BPWM_ConfigOutputChannel(BPWM0, 3, 16000, j);
BPWM_ConfigOutputChannel(BPWM1, 0, 16000, j);
BPWM_ConfigOutputChannel(BPWM1, 3, 16000, j);
}
}
#endif
} |
学习了