为了大家观看方便我把程序再发一次
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define nop() _nop_()
#define Red 1
#define Green 2
#define Blue 3
#define White 4
#define High 1
#define Low 0
sbit DIO=P3^4;
bdata uchar a;
sbit a7=a^7;
sbit LED=P3^5;
uchar show[3],color=1,temp=0xff;
void delay_ms(int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write(uchar date)
{
uchar i;
for(i=0;i<8;i++)
{
if(date&0x80)
{
DIO=1;
nop(); nop(); nop(); nop();
nop(); nop(); nop(); nop();
nop(); nop(); nop();
DIO=0;
}
else
{
DIO=1;
nop();nop();nop();nop();
nop();
DIO=0;
}
date<<=1;
}
}
void display()
{
uchar i,j;
for(j=0;j<1;j++)
for(i=0;i<3;i++)
write(show[i]);
}
void load()
{
uchar i;
for(i=0;i<1;i++)
{
if(color==Red)
{
show[i*3+0]=temp;
show[i*3+1]=0x00;
show[i*3+2]=0x00;
}
if(color==Green)
{
show[i*3+0]=0x00;
show[i*3+1]=temp;
show[i*3+2]=0x00;
}
if(color==Blue)
{
show[i*3+0]=0x00;
show[i*3+1]=0x00;
show[i*3+2]=temp;
}
if(color==White)
{
show[i*3+0]=temp;
show[i*3+1]=temp;
show[i*3+2]=temp;
}
}
}
void show_3()
{
for(color=1;color<5;color++)
{
for(temp=0;temp<255;temp++)
{
load();
display();
delay_ms(50);
}
for(temp=255;temp>0;temp--)
{
load();
display();
delay_ms(50);
}
}
}
void show_1()
{
uchar i;
for(i=0;i<2;i++)
{
write(0xff);
write(0x00);
write(0xaa);
write(0xff);
write(0x00);
write(0xaa);
write(0xff);
write(0x00);
write(0xaa);
write(0xff);
write(0xff);
write(0xff);
}
}
void main()
{
uchar i,j;
for(j=0;j<4;j++)
for(i=0;i<3;i++)
write(0xff);
delay_ms(50);
while(1)
{
show_1();
LED=!LED;
}
}
|