#include<intrins.h> //移位函数 #define nop _nop_(); #define uchar unsigned char //宏替换,方便书写 #define uint unsigned int //宏替换,方便书写 sbit DIO=P3^3; //数据输出引脚声明 uchar bdata LED_DAT; //可位操作的数据发送暂存变量声明 sbit bit0=LED_DAT^0; //被发送的数据各位定义 sbit bit1=LED_DAT^1; sbit bit2=LED_DAT^2; sbit bit3=LED_DAT^3; sbit bit4=LED_DAT^4; sbit bit5=LED_DAT^5; sbit bit6=LED_DAT^6; sbit bit7=LED_DAT^7; uint j; //时间控制全局变量声明 uchar RR,GG,BB; //RGB灰度值全局变量声明 void h_dat0(); //数码BIT0 void h_dat1(); //数码BIT1 void fs_rgbdat(); //发送RGB灰度数据 void red_jl(); //红色渐亮 void red_jm(); //红色渐灭 void green_jl(); //绿色渐亮 void green_jm(); //绿色渐灭 void blue_jl(); //蓝色渐亮 void blue_jm(); //蓝色渐灭 void white_jl(); //白色渐亮 void white_jm(); //白色渐灭 void delay_1ms(uint z); //延时函数声明 //*****************************主程序开始*****************************// void main() { while(1) { RR=0; GG=0; BB=0; fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(50); //延时100毫秒等待所有MCU复位 red_jl(); //红色渐亮 red_jm(); //红色渐灭 green_jl(); //绿色渐亮 green_jm(); //绿色渐灭 blue_jl(); //蓝色渐亮 blue_jm(); //蓝色渐灭 white_jl(); //白色渐亮 white_jm(); //白色渐灭 } } //*****************************主程序结束*****************************// //*****************************子程序开始*****************************// //=======================红色渐亮=======================// void red_jl() { uint i; RR=0; GG=0; BB=0; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); RR++; } RR=255; GG=0; BB=0; } //=======================红色渐灭=======================// void red_jm() { uint i; RR=255; GG=0; BB=0; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); RR--; } RR=0; GG=0; BB=0; } //=======================绿色渐亮=======================// void green_jl() { uint i; RR=0; GG=0; BB=0; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); GG++; } RR=0; GG=255; BB=0; } //=======================绿色渐灭=======================// void green_jm() { uint i; RR=0; GG=255; BB=0; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); GG--; } RR=0; GG=0; BB=0; } //=======================蓝色渐亮=======================// void blue_jl() { uint i; RR=0; GG=0; BB=0; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); BB++; } RR=0; GG=0; BB=255; } //=======================蓝色渐灭=======================// void blue_jm() { uint i; RR=0; GG=0; BB=255; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); BB--; } RR=0; GG=0; BB=0; } //=======================白色渐亮=======================// void white_jl() { uint i; RR=0; GG=0; BB=0; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); RR++; GG++; BB++; } RR=255; GG=255; BB=255; } //=======================白色渐灭=======================// void white_jm() { uint i; RR=255; GG=255; BB=255; for(i=0; i<256; i++) //白色渐灭 { fs_rgbdat(); //发送RGB灰度数据 DIO=0; //数据IO口置0 delay_1ms(5); RR--; GG--; BB--; } RR=0; GG=0; BB=0; } //=============低速模式数码BIT0(高电平时间:600ns 低电平时间:1940ns 周期T=2.54US)=============// void h_dat0() { DIO=1; nop; nop; nop; nop; nop; nop; nop; nop; DIO=0; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; } //=============低速模式数码BIT1(高电平时间:1840ns 低电平时间:700ns 周期T=2.54US)=============// void h_dat1() { DIO=1; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; DIO=0; } //===================发送RGB灰度数据===================// void fs_rgbdat() //发送RGB灰度数据 { uint k; for(k=0; k<1024; k++) //发送1024个像素点的数据 (灯的封装与PCB封装不一致,须按RBG的顺序发送数据!!!) { LED_DAT=RR; //红灯数据赋值给LED_DAT if(bit7==1) h_dat1(); else h_dat0(); if(bit6==1) h_dat1(); else h_dat0(); if(bit5==1) h_dat1(); else h_dat0(); if(bit4==1) h_dat1(); else h_dat0(); if(bit3==1) h_dat1(); else h_dat0(); if(bit2==1) h_dat1(); else h_dat0(); if(bit1==1) h_dat1(); else h_dat0(); if(bit0==1) h_dat1(); else h_dat0(); LED_DAT=BB; //蓝灯数据赋值给LED_DAT if(bit7==1) h_dat1(); else h_dat0(); if(bit6==1) h_dat1(); else h_dat0(); if(bit5==1) h_dat1(); else h_dat0(); if(bit4==1) h_dat1(); else h_dat0(); if(bit3==1) h_dat1(); else h_dat0(); if(bit2==1) h_dat1(); else h_dat0(); if(bit1==1) h_dat1(); else h_dat0(); if(bit0==1) h_dat1(); else h_dat0(); LED_DAT=GG; //绿灯数据赋值给LED_DAT if(bit7==1) h_dat1(); else h_dat0(); if(bit6==1) h_dat1(); else h_dat0(); if(bit5==1) h_dat1(); else h_dat0(); if(bit4==1) h_dat1(); else h_dat0(); if(bit3==1) h_dat1(); else h_dat0(); if(bit2==1) h_dat1(); else h_dat0(); if(bit1==1) h_dat1(); else h_dat0(); if(bit0==1) h_dat1(); else h_dat0(); } } //========================延时1MS======================// void delay_1ms(uint z) { uint x,y; for(x=z; x>0; x--) for(y=2800; y>0; y--); } //*****************************程序结束*****************************//
收藏0 举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
等级类勋章
发帖类勋章
时间类勋章
人才类勋章
42
1546
2
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号