PSOC的最大好处就在于,它已经集成了很多的资源,最重要的是它的底层配置已经写好啦,我们直接应用就可以了!不需要在像STM32,C51,AVR, MP430哪样,还得配置引脚,还有各种的设置。我们在原理图中配置好之后,在main中,只需要配置RGB的显示顺序就可以啦。程序如下:
/*****************************************************************************
* LED_Red - P1[6]
* LED_Green - P0[2]
* LED_Blue - P0[3]
******************************************************************************/
#include <device.h>
#define RED 0u
#define GREEN 1u
#define BLUE 2u
#define NUM_OF_COLORS 7u
CYCODE const uint8 colorMap[][3] = {{0x99,0x00,0x99}, /* Violet */
{0x4B,0x00,0x82}, /* Indigo */
{0x00,0x00,0xFF}, /* Blue */
{0x00,0xFF,0x00}, /* Green */
{0xFF,0xD3,0x00}, /* Yellow */
{0xFF,0x45,0x00}, /* Orange */
{0xFF,0x00,0x00}}; /* Red */
void main()
{
uint8 colorIndex = 0u;
PWM_Red_Start();
PWM_Green_Start();
PWM_Blue_Start();
Clock_PWM_Start();
for(;;)
{
for(colorIndex = 0; colorIndex < NUM_OF_COLORS; colorIndex++)
{
PWM_Red_WriteCompare(colorMap[colorIndex][RED]);
PWM_Green_WriteCompare(colorMap[colorIndex][GREEN]);
PWM_Blue_WriteCompare(colorMap[colorIndex][BLUE]);
CyDelay(1000);
}
}
}
|