我用CY3261A-RGB板子上的led16做了个小程序,用rgb实现颜色的变更,采用for循环嵌套,程序代码如下:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" #define uchar unsigned char #define uint unsigned int // PSoC API definitions for all User Modules
void delay(uint x) { uint i,j; for(i=0;i<=x;i++) { for(j=0;j<=50;j++); } }
void main() { uchar r1=0,g1=0,b1=0,i=3;
PRT2DR&=~0x80;
SSDM_1_Start(); SSDM_2_Start(); SSDM_3_Start();
M8C_EnableGInt;
while(i--) { SSDM_1_WriteSignalDensity(0xff); SSDM_2_WriteSignalDensity(0x80); SSDM_3_WriteSignalDensity(0x00); delay(2000); SSDM_1_WriteSignalDensity(0x00); SSDM_2_WriteSignalDensity(0x80); SSDM_3_WriteSignalDensity(0xff); delay(2000); SSDM_1_WriteSignalDensity(0x80); SSDM_2_WriteSignalDensity(0x00); SSDM_3_WriteSignalDensity(0xff); delay(2000); } for(r1=0;r1<=250;r1+=5) { for(g1=0;g1<=250;g1+=5) { for(b1=250;b1>=0;b1-=25) { delay(1000); SSDM_1_WriteSignalDensity(r1); SSDM_2_WriteSignalDensity(g1); SSDM_3_WriteSignalDensity(b1); } } } } }
程序执行后,第一个while循环可以正常执行,但是后面的for嵌套却不行,每次都只是蓝灯渐暗,另外两个始终点不亮,很奇怪。后来我把for嵌套程序修改如下后,正常执行了。感到莫名其妙,不知道是哪里的问题。 for(r1=0;r1<=250;r1+=5) { for(g1=0;g1<=250;g1+=5) { b1=250; while(b1-=5) { delay(1000); SSDM_1_WriteSignalDensity(r1); SSDM_2_WriteSignalDensity(g1); SSDM_3_WriteSignalDensity(b1); } } } } 不知道这是不是designer的bug? |