📄 dzkzqv10.c
字号:
//(***************************
// Version V1.0
// 地砖控制器
// 2004-09-23 mcu:w77e58 ,172800bps at RS485 11.0592MHz
#include <reg52.h>
//#include <w77c32.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define byte unsigned char
#define word unsigned
#define bool bit
#define true 1
#define false 0
#define SPEED 20
#define SPEEDCOL 10 //七彩过渡速度
#define SPEEDCOLS 500 //七彩停留时间
#define SPEEDBY 40 //百叶速度
//*************************************
sfr CHPCON= 0xbf;
sfr CHPENR=0xf6;
sfr PMR= 0xC4;
sfr SBUF1=0xc1;
sfr SCON1=0xc0;
sbit led=P3^5;
//**********************
uchar idata dis_red[40];
uchar idata dis_grn[40];
uchar idata dis_blu[40];
uchar XX,X1;
uchar code x64cr[]=
{
//红色数据:
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
0,0,0,0,0,0,0,0,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
/*
0x0B,0x0B,0x0A,0x0A,0x09,0x09,0x08,0x07,0x07,0x06,0x06,0x05,0x05,0x05,0x04,0x04,
0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,
0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0E,0x0E,0x0D,0x0D,0x0D,0x0C,0x0C,0x0B,0x00,
0x0B,0x0B,0x0A,0x0A,0x09,0x09,0x08,0x07,0x07,0x06,0x06,0x05,0x05,0x05,0x04,0x04,
0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,
0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0E,0x0E,0x0D,0x0D,0x0D,0x0C,0x0C,0x0B,0x00,
0x0B,0x0B,0x0A,0x0A,0x09,0x09,0x08,0x07,0x07,0x06,0x06,0x05,0x05,0x05,0x04,0x04,
0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,
0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0E,0x0E,0x0D,0x0D,0x0D,0x0C,0x0C,0x0B,0x00,
0x0B,0x0B,0x0A,0x0A,0x09,0x09,0x08,0x07,0x07,0x06,0x06,0x05,0x05,0x05,0x04,0x04,
0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,
0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0E,0x0E,0x0D,0x0D,0x0D,0x0C,0x0C,0x0B,0x00,
*/
};
uchar code x64cg[]=
{
//绿色数据:
0,0,0,0,0,0,0,0,
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
0,0,0,0,0,0,0,0,
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/*
0x0F,0x0E,0x0E,0x0E,0x0D,0x0D,0x0C,0x0C,0x0C,0x0B,0x0B,0x0B,0x0A,0x0A,0x0A,0x0A,
0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x09,0x09,0x09,0x08,0x08,0x07,0x07,
0x06,0x06,0x06,0x05,0x05,0x04,0x04,0x04,0x04,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x00,
0x0F,0x0E,0x0E,0x0E,0x0D,0x0D,0x0C,0x0C,0x0C,0x0B,0x0B,0x0B,0x0A,0x0A,0x0A,0x0A,
0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x09,0x09,0x09,0x08,0x08,0x07,0x07,
0x06,0x06,0x06,0x05,0x05,0x04,0x04,0x04,0x04,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x00,
0x0F,0x0E,0x0E,0x0E,0x0D,0x0D,0x0C,0x0C,0x0C,0x0B,0x0B,0x0B,0x0A,0x0A,0x0A,0x0A,
0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x09,0x09,0x09,0x08,0x08,0x07,0x07,
0x06,0x06,0x06,0x05,0x05,0x04,0x04,0x04,0x04,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x00,
0x0F,0x0E,0x0E,0x0E,0x0D,0x0D,0x0C,0x0C,0x0C,0x0B,0x0B,0x0B,0x0A,0x0A,0x0A,0x0A,
0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x09,0x09,0x09,0x08,0x08,0x07,0x07,
0x06,0x06,0x06,0x05,0x05,0x04,0x04,0x04,0x04,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05,0x06,0x06,0x06,0x07,0x07,0x00,
*/
};
uchar code x64cb[]=
{
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
15,13,11,9,7,5,3,1,
0,0,0,0,0,0,0,0,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
31,31,31,31,31,31,31,31,
31,31,31,31,31,31,31,31,
31,31,31,31,31,31,31,31,
31,31,31,31,31,31,31,31,
31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
/*
0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x06,
0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0E,0x0D,0x0B,0x0A,0x08,0x07,0x06,0x05,0x04,0x03,
0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x06,
0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0E,0x0D,0x0B,0x0A,0x08,0x07,0x06,0x05,0x04,0x03,
0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x06,
0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0E,0x0D,0x0B,0x0A,0x08,0x07,0x06,0x05,0x04,0x03,
0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x06,
0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0E,0x0D,0x0B,0x0A,0x08,0x07,0x06,0x05,0x04,0x03,
*/
};
//**************************
void clear(void);
void sendall(void);//发送全部
void televise(void);//广播发送
void send_del(uchar j);
void delay(uint j);
void delay1s(uint j);
void qcld(uchar speed);
void duun(uchar speed);
void lrmun(uchar speed);
void mlrun(uchar speed);
void mlrco(uchar speed);
void lrmco(uchar speed);
void col7(void);
void mlrmov(uchar speed);
void ybyzk(uchar speed);
void ybybm(uchar speed);
void zbyzk(uchar speed);
void zbybm(uchar speed);
//********************************************
void main()
{
SM0=1;
SM1=1;
SM2=0;
T2CON=0X30;
ES=0;
RCAP2H=0XFF;
TH2=0XFF;
RCAP2L=0Xdc;
TL2=0Xdc; //bps=38400bps 256-(22.1184*10^6/32/38400)
TR2=1;
TMOD=0x25; //timer 1 dps timer sync
SCON1=0xd0; //serial prot 1
TH1=0xfd;
TL1=0xfd; //256-(22.1184*10~6/32/12/3/38400*2)
TL0=0xff; //timer 0 is ac sync
TH0=0xff;
TR0=1;
ET0=1;
TR1=1;
ET1=0;
ES=1;
EA=1;
//SCON=0xb0; //bps
//CHPENR=0X87;
//CHPENR=0X59;
//CHPCON=0X10;
PMR=PMR|0x01; //enable on-chip RAM
XX=30;
X1=16;
//*******************
while(1)
{
col7();
zbyzk(SPEEDBY);
zbybm(SPEEDBY);
ybyzk(SPEEDBY);
ybybm(SPEEDBY);
zbyzk(SPEEDBY);
zbybm(SPEEDBY);
ybyzk(SPEEDBY);
ybybm(SPEEDBY);
qcld(120/XX);
duun(120/XX);
clear();
lrmun(120/XX);
lrmco(120/XX);
mlrun(120/XX);
mlrco(120/XX);
mlrmov(120/XX);
mlrun(120/XX);
}
}
//**************************
//七种颜色渐变
//*****************************
void col7(uchar speed)
{
uchar n,i;
clear();
for(i=0;i<16;i++)
{for(n=0;n<4;n++)dis_red[n]=i;
televise();
delay1s(SPEEDCOL);
}
delay1s(SPEEDCOLS);
//----------------------------
for(i=0;i<16;i++)
{for(n=0;n<4;n++)dis_grn[n]=i;
televise();
delay1s(SPEEDCOL);
}
delay1s(SPEEDCOLS);
//----------------------------
for(i=15;i<254;i--)
{for(n=0;n<4;n++)dis_red[n]=i;
televise();
delay1s(SPEEDCOL);
}
delay1s(SPEEDCOLS);
//----------------------------
for(i=0;i<16;i++)
{for(n=0;n<4;n++)dis_blu[n]=i;
televise();
delay1s(SPEEDCOL);
}
delay1s(SPEEDCOLS);
//----------------------------
for(i=15;i<254;i--)
{for(n=0;n<4;n++)dis_grn[n]=i;
televise();
delay1s(SPEEDCOL);
}
delay1s(SPEEDCOLS);
//----------------------------
for(i=0;i<16;i++)
{for(n=0;n<4;n++)dis_red[n]=i;
televise();
delay1s(SPEEDCOL);
}
delay1s(SPEEDCOLS);
//---------------------------
for(i=0;i<16;i++)
{for(n=0;n<4;n++)dis_grn[n]=i;
televise();
delay1s(SPEEDCOL);
}
delay1s(SPEEDCOLS);
}
//**************************
//将数据广播发送
//*****************************
void televise(void)
{
TB8=1;
SBUF=0;while(!TI);TI=0;
TB8=0;
send_del(20);
SBUF=dis_red[0];
while(!TI);TI=0;
send_del(20);
SBUF=dis_grn[0];
while(!TI);TI=0;
send_del(20);
SBUF=dis_blu[0];
while(!TI);TI=0;
send_del(20);
led=!led;
}
//**************************
//加清除显示内存
//*****************************
void clear(void)
{
uchar i;
for(i=0;i<XX;i++)
{
dis_red[i]=0;
dis_grn[i]=0;
dis_blu[i]=0;
}
}
//*******************************
//左展开
//********************************
void duun(uchar speed)
{
uchar x;
for(x=0;x<XX;x++)
{
dis_red[x]=x64cr[x];
dis_grn[x]=x64cg[x];
dis_blu[x]=x64cb[x];
sendall();
}
delay1s(speed);
}
//*******************************
//左百叶展开
//********************************
void zbyzk(uchar speed)
{
uchar x,i;
for(i=0;i<4;i++)
{for(x=0;x<XX/4;x++)
{
dis_red[x*4+i]=x64cr[x];
dis_grn[x*4+i]=x64cg[x];
dis_blu[x*4+i]=x64cb[x];
}
sendall();
delay1s(speed);
}
}
//*******************************
//左百叶闭幕
//********************************
void zbybm(uchar speed)
{
uchar x,i;
for(i=0;i<4;i++)
{for(x=0;x<XX/4;x++)
{
dis_red[x*4+i]=0;
dis_grn[x*4+i]=0;
dis_blu[x*4+i]=0;
}
sendall();
delay1s(speed);
}
}
//*******************************
//右百叶展开
//********************************
void ybyzk(uchar speed)
{
uchar x,i;
for(i=3;i<254;i--)
{for(x=0;x<XX/4;x++)
{
dis_red[x*4+i]=x64cr[x];
dis_grn[x*4+i]=x64cg[x];
dis_blu[x*4+i]=x64cb[x];
}
sendall();
delay1s(speed);
}
}
//*******************************
//右百叶闭幕
//********************************
void ybybm(uchar speed)
{
uchar x,i;
for(i=3;i<254;i--)
{for(x=0;x<XX/4;x++)
{
dis_red[x*4+i]=0;
dis_grn[x*4+i]=0;
dis_blu[x*4+i]=0;
}
sendall();
delay1s(speed);
}
}
//*******************************
//从中间向两边展开
//*******************************
void mlrun(uchar speed)
{
uchar x;
for(x=0;x<X1;x++)
{
dis_red[x+X1]=x64cr[x+X1];dis_red[X1-x]=x64cr[X1-x];
dis_grn[x+X1]=x64cg[x+X1];dis_grn[X1-x]=x64cg[X1-x];
dis_blu[x+X1]=x64cb[x+X1];dis_blu[X1-x]=x64cb[X1-x];
sendall();
}
delay1s(speed);
}
//*******************************
//从中间向两边闭幕
//**********************************
void mlrco(uchar speed)
{
uchar x;
for(x=X1;x<XX;x++)
{
dis_red[x]=0;dis_red[XX-1-x]=0;
dis_grn[x]=0;dis_grn[XX-1-x]=0;
dis_blu[x]=0;dis_blu[XX-1-x]=0;
sendall();
}
delay1s(speed);
}
//*******************************
//两边向中间展开
//**********************************
void lrmun(uchar speed)
{
uchar x;
for(x=XX-1;x>X1;x--)
{
dis_red[x]=x64cr[x];dis_red[XX-1-x]=x64cr[XX-1-x];
dis_grn[x]=x64cg[x];dis_grn[XX-1-x]=x64cg[XX-1-x];
dis_blu[x]=x64cb[x];dis_blu[XX-1-x]=x64cb[XX-1-x];
sendall();
}
delay1s(speed);
}
//*******************************
//两边向中间闭幕
//**********************************
void lrmco(uchar speed)
{
uchar x;
for(x=0;x<X1;x++)
{
dis_red[x]=0;dis_red[XX-1-x]=0;
dis_grn[x]=0;dis_grn[XX-1-x]=0;
dis_blu[x]=0;dis_blu[XX-1-x]=0;
sendall();
}
delay1s(speed);
}
//*******************************
//中间向两边移出
//**********************************
void mlrmov(uchar speed)
{
uint i,x;
uchar code *ROMP;
ROMP=0x2000;
for(x=0;x<XX;x++)
{
dis_red[x]=0;//清屏
dis_grn[x]=0;//清屏
dis_blu[x]=0;//清屏
}
for(i=0;i<XX/2;i++)
{
for(x=XX-1;x>X1;x--)
{
dis_red[x]=dis_red[x-1];
dis_grn[x]=dis_grn[x-1];
dis_blu[x]=dis_blu[x-1];
}
dis_red[X1]=*ROMP;ROMP++;
dis_grn[X1]=*ROMP;ROMP++;
dis_blu[X1]=*ROMP;ROMP++;
for(x=0;x<X1-1;x++)
{
dis_red[x]=dis_red[x+1];
dis_grn[x]=dis_grn[x+1];
dis_blu[x]=dis_blu[x+1];
}
dis_red[X1-1]=*ROMP;ROMP++;
dis_grn[X1-1]=*ROMP;ROMP++;
dis_blu[X1-1]=*ROMP;ROMP++;
sendall();
}
delay1s(speed);
}
//***********************************
//多彩流动
//***************************************
void qcld(uchar speed)
{
uint j,x;
uchar rs,gs,bs;
for(j=0;j<XX;j++)
{for(x=XX-1;x>0;x--)
{
dis_red[x]=dis_red[x-1];
dis_grn[x]=dis_grn[x-1];
dis_blu[x]=dis_blu[x-1];
}
dis_red[0]=x64cr[j];
dis_grn[0]=x64cg[j];
dis_blu[0]=x64cb[j];
sendall();
delay(speed);
}
delay1s(speed);
for(j=0;j<XX*2;j++)
{
rs=dis_red[XX-1];
gs=dis_grn[XX-1];
bs=dis_blu[XX-1];
for(x=XX-1;x>0;x--)
{
dis_red[x]=dis_red[x-1];
dis_grn[x]=dis_grn[x-1];
dis_blu[x]=dis_blu[x-1];
}
dis_red[0]=rs;
dis_grn[0]=gs;
dis_blu[0]=bs;
sendall();
delay(speed);
}
//*******************************************
for(j=0;j<XX;j++)
{for(x=XX-1;x>0;x--)
{
dis_red[x]=dis_red[x-1];
dis_grn[x]=dis_grn[x-1];
dis_blu[x]=dis_blu[x-1];
}
dis_red[0]=0;
dis_grn[0]=0;
dis_blu[0]=0;
sendall();
delay(speed);
}
}
//******************************
//发送显示内存数据到各灯管
//*******************************
void sendall(void)
{
uchar j;
for(j=0;j<XX-1;j++)
{TB8=1;
SBUF=j+1;while(!TI);TI=0;
TB8=0;
send_del(20);
//send red
SBUF=dis_red[j];
while(!TI);TI=0;
send_del(20);
//send greed
SBUF=dis_grn[j];
while(!TI);TI=0;
send_del(20);
//***********bluer
SBUF=dis_blu[j];
while(!TI);TI=0;
send_del(20);
}
led=!led;
}
//**********************************
//延时
//*******************************
void delay1s(uint j)
{
int i;
while(j!=0)
{
for(i=0;i<65535;i++);
j--;
}
}
//*******************************
void delay(uint j)
{
int i;
while(j!=0)
{
for(i=0;i<ssp*256;i++);
j--;
}
ssp=1;
}
//*******************************
void send_del(uchar j)
{
while(j!=0)
{
j--;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -