DMX512 C程序
扫描二维码
随时随地手机看文章
#include"reg51.h"
sfrT2CON=0XC8;
sfrT2MOD=0XC9;
sfrRCAPL2=0XCA;
sfrRCAPH2=0XCB;
sfrTH2=0XCC;
sfrTL2=0XCD;
sbitGREEN=P1^0;
sbitBLUK=P1^1;
sbitYELLOW=P1^2;
sbitRED=P1^3;
sbitLED=P1^5;
bitrevfg;
unsignedcharstart,ribit;
unsignedcharcdata[6];
voidinitUART(void)
{
T2CON=0X34;
TH2=0XFF;
TL2=0XFE;
RCAPH2=0XFF;
RCAPL2=0XFE;
SCON=0XD0;
}
voidbps(void)interrupt4using1
{
if(RI)
{
RI=0;
if((RB8==0)&&(SBUF==0)){start=1;revfg=0;}
elseif((start==1)&&(revfg==0)){revfg=1;ribit=0;}
if(revfg==1)
{
cdata[ribit]=SBUF;
ribit++;
if(ribit>=5){ribit=0;revfg=0;start=0;}
}
}
elseif(TI==1)TI=0;
}
voidmain(void)
{
initUart();
EA=1;
ES=1;
RED=1;
GREEN=1;
BLUK=1;
YELLOW=1;
while(1)
{
if(cdata[0]==0)LED=1;
if(cdata[1]<50)
{
RED=0;
GREEN=0;
BLUK=0;
YELLOW=0;
}
if((cdata[1]>=50)&&(cdata[1]<100))
{
RED=1;
GREEN=0;
BLUK=0;
YELLOW=0;
}
if((cdata[1]>=100)&&(cdata[1]<200))
{
RED=0;
GREEN=1;
BLUK=0;
YELLOW=0;
}
if(cdata[1]>=200)
{
RED=1;
GREEN=1;
BLUK=1;
YELLOW=1;
}
}
}