DMX512 C程序
点击数:7322 次 录入时间:03-04 11:35:11 整理:http://www.55dianzi.com 51单片机
#include "reg51.h"
sfr T2CON =0XC8;
sfr T2MOD =0XC9;
sfr RCAPL2=0XCA;
sfr RCAPH2=0XCB;
sfr TH2 =0XCC;
sfr TL2 =0XCD;
sbit GREEN = P1^0;
sbit BLUK = P1^1;
sbit YELLOW= P1^2;
sbit RED = P1^3;
sbit LED = P1^5;
bit revfg;
unsigned char start,ribit;
unsigned char cdata[6];
void initUART(void)
{
T2CON=0X34;
TH2=0XFF;
TL2=0XFE;
RCAPH2=0XFF;
RCAPL2=0XFE;
SCON=0XD0;
}
void bps(void) interrupt 4 using 1
{
if(RI)
{
RI=0;
if((RB8==0)&&(SBUF==0)){start=1;revfg=0;}
else if((start==1)&&(revfg==0)){revfg=1;ribit=0;}
if(revfg==1)
{
cdata[ribit]=SBUF;
ribit++;
if(ribit>=5){ribit=0;revfg=0;start=0;}
}
}
else if(TI==1)TI=0;
}
void main(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;
}
}
}
本文关键字:程序 51单片机,单片机-工控设备 - 51单片机