可是我第一次写一个程序就把我给难住了,程序很简单,用的是PIC16F505芯片,她有1K字的大小,可我写的程序编译达到500多字节就说放不下,我的主程序只是调用同一个子程序,只是形参不同而已,多调用一次就不够,少一次就可以,我用的PICC8.05编译器,望前辈们能在百忙之中看一下,非常感谢! c程序如下: #include<pic.h> //#include<pic16505.h> #define uchar unsigned char #define Classes 100
/************************************************ Start 一种颜色的起始色级 Over 一种颜色的结束色级 Delay20ms 一个色级保持时间的20ms数 Color11 第一种基色的PORTB数据 color21 第一种基色的PORTC数据 Color12 第二种基色的PORTB数据 Color22 第二种基色的PORTC数据 *************************************************/
/* void Change(static uchar Start,static uchar Over,static uchar Delay20ms, static uchar Color11,static uchar Color21,static uchar Color12,static uchar Color22); */
void Change(uchar Start,uchar Over,uchar Delay20ms, uchar Color11,uchar Color21,uchar Color12,uchar Color22) { uchar m,Color_nb; for(Color_nb=Start;Color_nb<Over;Color_nb++) { TMR0=0; while(TMR0<Delay20ms) /*在Delay20ms内俩种基色交替亮*/ { asm("clrWDT"); for(m=0;m<(Classes-Color_nb);m++) /*第一种基色亮的时间*/ { PORTB=Color11; PORTC=Color21; } for(m=0;m<Color_nb;m++) /*第二种基色亮的时间*/ { PORTB=Color12; PORTC=Color22; } } } } void main() { uchar n; OPTION=0X20; TRISB=0X00; TRISC=0X20; PORTB&=0X00; PORTC&=0X20; while(1) { // Change(0,1,50,0x24,0x01,0x24,0x01); /*红保持2秒*/ // Change(0,1,50,0x02,0x12,0x02,0x12); /*绿保持2秒*/ Change(0,1,50,0x01,0x0c,0x01,0x0c); /*兰保持2秒*/ Change(30,31,50,0x24,0x01,0x02,0x12); /*橙保持2秒*/ Change(70,71,50,0x24,0x01,0x02,0x12); /*黄保持2秒*/ Change(50,51,50,0x02,0x12,0x01,0x0c); /*青保持2秒*/ Change(50,51,50,0x01,0x0c,0x24,0x01); /*紫保持2秒*/ Change(0,1,50,0x27,0x1f,0x27,0x1f); /*白保持2秒*/ Change(0,100,1,0x27,0x1f,0x24,0x01); /*红固定,绿蓝递减*/ Change(0,100,1,0x24,0x01,0x25,0x0d); /*红固定,蓝递增*/ Change(0,100,1,0x25,0x0d,0x01,0x0c); /*蓝固定,红递减*/ Change(0,100,1,0x01,0x0c,0x03,0x1e); /*蓝固定,绿递增*/ Change(0,100,1,0x03,0x1e,0x02,0x12); /*绿固定,蓝递减*/ Change(0,100,1,0x02,0x12,0x26,0x13); /*绿固定,红递增*/ Change(0,100,1,0x26,0x13,0x24,0x01); /*红固定,绿递减*/ Change(0,100,1,0x24,0x01,0x27,0x1f); /*红固定,绿蓝递增*/ for(n=0;n<10;n++) { Change(0,1,10,0x21,0x02,0x21,0x02); /*三段R-G-B保持0.2秒*/ Change(0,1,10,0x04,0x14,0x04,0x14); /*三段G-B-R保持0.2秒*/ Change(0,1,10,0x02,0x09,0x02,0x09); /*三段B-R-G保持0.2秒*/ } for(n=0;n<10;n++) /*红绿蓝交替亮*/ { /*每次0.2秒*/ Change(0,1,10,0x24,0x01,0x24,0x01); /*共10次 */ Change(0,1,10,0x02,0x12,0x02,0x12); Change(0,1,10,0x01,0x0c,0x01,0x0c); } Change(0,1,25,0x27,0x1f,0x27,0x1f); /*白保持1秒*/ Change(0,1,25,0x27,0x07,0x27,0x07); /*红白白保持1秒*/ Change(0,1,25,0x27,0x01,0x27,0x01); /*红红白保持1秒*/ Change(0,1,25,0x24,0x01,0x24,0x01); /*红红红保持1秒*/ Change(0,1,25,0x27,0x1f,0x27,0x1f); /*白保持1秒*/ Change(0,1,25,0x04,0x11,0x04,0x11); /*绿红红保持1秒*/ Change(0,1,25,0x04,0x12,0x04,0x12); /*绿绿红保持1秒*/ Change(0,1,25,0x02,0x12,0x02,0x12); /*绿绿绿保持1秒*/ //Change(0,60,2,0x24,0x01,0x02,0x12); /*红平滑到橙 2.4秒 */ //Change(60,130,2,0x24,0x01,0x02,0x12); /*橙平滑到黄 2.8秒 */ //Change(130,200,2,0x24,0x01,0x02,0x12); /*黄平滑到绿 2.8秒 */ //Change(0,100,1,0x02,0x12,0x01,0x0c); /*绿平滑到青 2秒*/ //Change(100,200,1,0x02,0x12,0x01,0x0c); /*青平滑到兰 2秒*/ //Change(0,100,1,0x01,0x0c,0x24,0x01); /*兰平滑到紫 2秒*/ //Change(100,200,1,0x01,0x0c,0x24,0x01); /*紫平滑到红 2秒*/ //Change(0,200,1,0x24,0x01,0x02,0x12); /*红平滑到绿 历时4秒 */ //Change(0,200,1,0x02,0x12,0x01,0x0c); /*绿平滑到蓝 历时4秒 */ //Change(0,200,1,0x01,0x0c,0x24,0x01); /*蓝平滑到红 历时4秒 */ } } |
|