Dmx512灯控制器程序
扫描二维码
随时随地手机看文章
/*==========================================*/
/*1.本程序采用keil编译系统.*/
/*2.本程序为水底灯简易Dmx控制器*/
/*3.采用AT89C52单片机,Fosc=16MHz*/
*/
/*==========================================*/
//程序修改SYSTEMMODE下使投光灯熄灭
#include
#include
/*=======================================*/
//序修改增加1。蓝色亮30秒后,白色亮10秒循环
//2。白色亮30秒后,蓝色亮10秒循环
/*系统模式设定;晶振频率=16MHz*/
#defineTIMER0_VALUE0x7fff//定时器0计时49ms
#defineTIMER1_VALUE300//定时器1计数值1.5ms
#defineTMOD_MODE_WORD0x11//GATE(门控信号)C/T(1-计数0-定时器1)M1M0(00-13位定时器01-16位定时器10-自装8位定时器
//GATE(门控信号)C/T(1-计数0-定时器0)M1M0(00-13位定时器01-16位定时器10-自装8位定时器
#defineTCON_MODE_WORD0x55//TF0(T0溢出中断请求)--TF1(T1溢出中断请求)--
//IE1(外部中1断请求)IT1(触发方式1-边沿)IE0(外部中0断请求)IT0(触发方式1-边沿)
#defineIE_MODE_WORD0x8e//EA(1-总中断开)?--ET2(定时器2中断)ES(串行中断)
//ET1(定时器1中断)EX1(外部中断1)ET0(定时器0中断)EX0(外部中断0)
#defineIP_MODE_WORD0x01//------PSPT1PX1PT0PX0
#definePCON_MODE_WORD0x00//SMOD------GF1GF0PDIDL;
#defineSCON_MODE_WORD0x90//SM0SM1SM2RENTB8RB8TIRIREN:接收容许
//00方式0同步移位寄存器Fosc/12
//01方式110位异步收发由定时器控制
sfrPMR=0XC4;//10方式211位异步收发Fosc/32Fosc/64
//11方式311位异步收发由定时器控制
#defineEEPROM_CONTROL_WORD0//93c66,bytemode
#defineDelay_Time1
#defineSystem_Mode_Menu10
#defineSingle_Color_Menu11
#defineRed0
#defineYellow1
#defineGreen2
#defineCyan3
#defineBlue4
#definePurple5
#defineWhite6
#defineBlack7
#defineOrange8
#definePINk9
#defineR0
#defineY1
#defineG2
#defineC3
#defineB4
#defineP5
#defineW6
#defineD7
#defineO8
#defineF9
#defineMenu1_Max14//2006-09-22更改由12更改为14
#defineMenu2_Max5
#defineAuto_Step1_Max46-1
#defineAuto_Step2_Max7-1
#defineBegin_Lamp1-1
#defineuncharunsignedchar
#defineunintunsignedint
#defineunlongunsignedlong
#defineDELAY_10S200//修改于2006-09-22
#defineDELAY_30S600//修改于2006-09-22
uintDelaywb;//修改于2006-09-22
ucharcodeMenu1_Tab[][16]=
{
"1)SystemMode",//0
"Set<>",
"2)SingleColor",//1
"Set<>",
"3)Flow1(FF)",//2
"Set<>",
"4)Flow2(Rew)",//3
"Set<>",
"5)Flow3(FF/Rew)",//4
"Set<>",
"6)M.ColorFlow1",//5
"Set<>",
"7)M.ColorFlow2",//6
"Set<>",
"8)ColorChase",//7
"Set<>",
"9)FadeChase",//8
"Set<>",
"10)FadeChange",//9
"Set<>",
"11)AutoRun1",//10
"<>",
//11
"12)AutoRun2",
"<>",
"13)CustomRun",//12
"",
"Clientmode1",//增加262006-09-22
"W30S-->B10S",//27
"Clientmode2",//增加282006-09-22
"B30S-->W10S",//29
"SRC-WASHER-100",//30
"Ver:2.3",//31
};
uncharcodeMenu2_Tab[][16]=
{
"Sort:",
"",
"Speed:",
"",
"FlashFreq:",
"",
"ixels/Step",
"",
"Save:",
"YesNo",
"LampAmount",
"",
"StartAddress",
"",
"WriteAddress",
"YesNo",
"Repeat:",
"",
"Save...",
"",
"Erase...",
"",
};
uncharcodeColor_Tab[][16]=
{
"1.R",
"2.G",
"3.Y",
"4.B",
"5.P",
"6.C",
"7.W",
"8.D",
"9.RG",
"10.RY",
"11.RB",
"12.RP",
"13.RC",
"14.RW",
"15.RD",
"16.GY",
"17.GB",
"18.GP",
"19.GC",
"20.GW",
"21.GD",
"22.YB",
"23.YP",
"24.YC",
"25.YW",
"26.YD",
"27.BP",
"28.BC",
"29.BW",
"30.BD",
"31.PC",
"32.PW",
"33.PD",
"34.CW",
"35.CD",
"36.WD",
"37.RYGC",
"38.BRCG",
"39.RCPY",
"40.GBCR",
"41.RCBP",
"42.YRGB",
"43.PCWG",
"44.CPYB",
"45.RGYBPCWD",
"46.ROYGCBPF",
"47.BRCPWYDF",
"48.WPCRGYBG",
"49.GRWPBYFW",
"50.RDGDBDPD",
};
uncharcodeColor_Table[][8]={
{R,R,R,R,R,R,R,R},//1
{G,G,G,G,G,G,G,G},//2
{Y,Y,Y,Y,Y,Y,Y,Y},//3
{B,B,B,B,B,B,B,B},//4
{P,P,P,P,P,P,P,P},//5
{C,C,C,C,C,C,C,C},//6
{W,W,W,W,W,W,W,W},//7
{D,W,W,W,W,W,W,W},//8
{R,G,R,G,R,G,R,G},//9
{R,Y,R,Y,R,Y,R,Y},//10
{R,B,R,B,R,B,R,B},//11
{R,P,R,P,R,P,R,P},//12
{R,C,R,C,R,C,R,C},//13
{R,W,R,W,R,W,R,W},//14
{R,D,R,D,R,D,R,D},//15
{G,Y,G,Y,G,Y,G,Y},//16
{G,B,G,B,G,B,G,B},//17
{G,P,G,P,G,P,G,P},//18
{G,C,G,C,G,C,G,C},//19
{G,W,G,W,G,W,G,W},//20
{G,D,G,D,G,D,G,D},//21
{Y,B,Y,B,Y,B,Y,B},//22
{Y,P,Y,P,Y,P,Y,P},//23
{Y,C,Y,C,Y,C,Y,C},//24
{Y,W,Y,W,Y,W,Y,W},//25
{Y,D,Y,D,Y,D,Y,D},//26
{B,P,B,P,B,P,B,P},//27
{B,C,B,C,B,C,B,C},//28
{B,W,B,W,B,W,B,W},//29
{B,D,B,D,B,D,B,D},//30
{P,C,P,C,P,C,P,C},//31
{P,W,P,W,P,W,P,W},//32
{P,D,P,D,P,D,P,D},//33
{C,W,C,W,C,W,C,W},//34
{C,D,C,D,C,D,C,D},//35
{W,D,W,D,W,D,W,D},//36
{R,Y,G,C,R,Y,G,C},//37
{B,R,C,G,B,R,C,G},//38
{R,C,P,Y,R,C,P,Y},//39
{G,B,C,R,G,B,C,R},//40
{R,C,B,P,R,C,B,P},//41
{Y,R,G,B,Y,R,G,B},//42
{P,C,W,G,P,C,W,G},//43
{C,P,Y,B,C,P,Y,B},//44
{R,G,Y,B,P,C,W,D},//45
{R,O,Y,G,C,B,P,F},//46
{B,R,C,P,W,Y,D,F},//47
{W,P,C,R,G,Y,B,G},//48
{G,R,W,P,B,Y,F,W},//49
{R,D,G,D,B,D,P,D}//50
};
uncharcodeAutorun_Table1[][5]={
{2,44,16,0,1},//2ff
{3,44,16,0,1},//3rew
{4,44,16,0,1},//4ff/rew
{5,9,14,0,4},//5M.Flow1
{5,10,14,0,4},//6M.Flow1
{5,12,14,0,4},//7M.Flow1
{5,13,14,0,4},//8M.Flow1
{5,14,14,0,4},//9M.Flow1
{5,16,14,0,4},//10M.Flow1
{5,17,14,0,4},//11M.Flow1
{5,16,14,0,4},//12M.Flow1
{5,20,14,0,4},//13M.Flow1
{5,21,14,0,4},//14M.Flow1
{5,22,14,0,4},//15M.Flow1
{5,23,14,0,4},//16M.Flow1
{5,25,14,0,4},//17M.Flow1
{5,30,14,0,4},//18M.Flow1
{5,45,14,0,1},//19M.Flow1
{6,9,14,0,4},//20M.Flow2
{6,10,14,0,4},//21M.Flow2
{6,12,14,0,4},//22M.Flow2
{6,13,14,0,4},//23M.Flow2
{6,14,14,0,4},//24M.Flow2
{6,16,14,0,4},//25M.Flow2
{6,17,14,0,4},//26M.Flow2
{6,16,14,0,4},//27M.Flow2
{6,20,14,0,4},//28M.Flow2
{6,21,14,0,4},//29M.Flow2
{6,22,14,0,4},//30M.Flow2
{6,23,14,0,4},//31M.Flow2
{6,25,14,0,4},//32M.Flow2
{6,30,14,0,4},//33M.Flow2
{6,45,14,0,1},//34M.Flow2
{7,10,11,0,4},//35M.Chase
{7,12,11,0,4},//36M.
{7,13,11,0,4},//37M.
{7,14,11,0,4},//38M.
{7,16,11,0,4},//39M.
{7,17,11,0,4},//40M.
{8,10,12,0,4},//41Color.Chase
{8,10,12,0,4},//42Color.Chase
{8,10,12,0,4},//43Color.Chase
{9,44,8,0,5},//44
{9,49,16,0,5},//4550.RDGDBDPDfade
{1,44,12,0,2},//46
{1,44,12,5,2},//47
};
uncharcodeAutorun_Table2[][5]={
{1,44,16,0,2},//145.RGYBPCWDsingle
{2,44,16,0,0},//3ff
{9,41,16,0,5},//4fade
{3,44,16,0,0},//5rew
{1,44,16,5,2},//245.RGYBPCWDsingle
{9,49,16,0,5},//650.RDGDBDPDfade
{4,44,16,0,0},//7ff/rew
};
unionUser_Data_Type
{
unintWord;
struct{uncharH;uncharL;}Bytes;
};
uncharPress_Time,Dmx_Timer;
uncharxdataWork_Data_Buff[512];
uncharxdataCustom_Run[30][5];
uncharmode,mode1,mode2;
unchardataSet_Num[5];
uncharMenu1,Menu2,Menu3,Bk_Menu1;
uncharFrequence,Frequence_Count,Speed;
uncharFade;
uncharRun_Speed;
unintRun_Time;
uncharCurrent_Lamp,Current_Lamp1,Color_Sort;
uncharidataMenu[15][5]={
{31,1,0,0,0},//1amountaddress
{1,0,0,3,0},//2
{8,0,0,3,0},//3
{9,0,0,3,0},//4
{10,0,0,3,0},//5
{11,0,0,3,0},//6
{12,0,0,3,0},//7
{13,3,0,3,0},//8
{10,0,0,3,0},//9
{47,12,0,3,0},//10
{16,0,0,3,0},//11auto
{17,0,0,3,0},//12
{18,0,0,3,0},//13
};
uncharTemp_Buff;
uncharAmount;
uncharColor_X,Color_X1,Color_X3;
uncharCurrent_Color,Current_Color1;
uncharPixels;
uncharidataColor_Table2[32];
uncharFade_Adj,Fade_Adj1,Fade_Time;
uncharEeprom_Control_Word_Rg;
uncharAuto_Step1,Auto_Step2,Auto_Reapeat,Circle,Repeat;
uncharAmount,Address;
uncharBk_Color_Sort,Bk_Pixels;
uncharR_data1,G_data1,B_data1;
uncharR_data2,G_data2,B_data2;
uncharPixels_Group;
uncharSave_Pc;
uncharPlay_Pc,Bk_Play_Pc;
uncharTemp_Color2,Temp_Color1;
sbitSw_Key1=P2^4;
sbitSw_Key2=P2^5;
sbitSw_Key3=P2^6;
sbitSw_Key4=P2^7;
sbitSw_Key5=P2^3;
sbitLCD_RS_Cs=P2^0;
sbitLcd_RW_Cs=P2^1;
sbitLcd_OE_Cs=P2^2;
//sbitLcd_Lamp=P1^0;
sbitEeprom_DI_Fg=P3^5;
sbitEeprom_DO_Fg=P3^5;
//sbitEeprom_CS_Fg=P3^4;
sbitEeprom_CS_Fg=P3^6;
sbitEeprom_CK_Fg=P3^7;
bitKey1_Flag;
bitKey2_Flag;
bitKey3_Flag;
bitKey4_Flag;
bitKey5_Flag;
bitKey6_Flag;
bitKey7_Flag;//此为增加2006-09-22
bitKey8_Flag;
bitFirst_Press_Flag;
bitDirection_Flag;
bitAdj_Direction_Flag,Adj_Direction_Flag1;
bitFlash_On;
bitSend_Data_Enable_Flag;
/*函数声明*/
voidWork_Buff_Clr(void);
voidDelay_10_uS(void);
voidDelay_N_mS(unintn_milisecond);/*nmSdelay*/
voidLcd_Initialize(void);
voidLcd_Menu1_DSP(uncharItem_Rg);
voidLcd_Menu2_Dsp(uncharItem_Rg);
voidLcd_Write_Data(uncharData_Rg);
voidLcd_Number_Dsp(void);
voidLcd_Color_Dsp(uncharItem_Rg);
voidHex_To_Ascii(unintData_Rg);
voidColor_Set(unintCh1,unintCh2,uncharColor);
uncharRead_Table(unchari,uncharj);
voidWrite_Table(unchari,uncharj,uncharadj);
bitEeprom_Check_Busy(void);
voidEE_Write_Start_Bit(void);
uncharEE_Read_Code_Bit(void);
voidEE_Write_Code_Bit(uncharCode_Rg,uncharBit_Count_Rg);
voidEeprom_Write_Enable(void);
uncharEeprom_Read_Data(unintAddress_Rg);
voidEeprom_Write_Data(unintAddress_Rg,unintValue_Rg);
voidAuto_Run(void);
voidFade_Color2Color(void);//uncharcolor1,color2);
voidHand_Time(void);
voidSend_Dmx_Data(void);
voidSend_blue(void);//增加于2006-09-22
voidSend_write(void);
/*==================================================================================*/
voidInt0(void)interrupt0using0
{
}
voidInt1(void)interrupt2using1
{
}
/*==================================================================================*/
//Timer0定时中断服务程序;49ms中断一次
voidTimer0(void)interrupt1using2
{
//uninti,j;
TH0=(unchar)((65536-TIMER0_VALUE)>>8);
TL0=(unchar)(65536-TIMER0_VALUE);
_nop_();
if(Flag.bit7)
{
Delaywb++;
}
if((Sw_Key1==0)&&(Sw_Key2!=0)&&(Sw_Key3!=0)&&(Sw_Key4!=0))
{
Press_Time++;
if(Press_Time==2)//>100ms
{
Key1_Flag=1;
}
if(Press_Time>4)//>2S
{
Key1_Flag=1;
Press_Time=4;
}
}
if((Sw_Key2==0)&&(Sw_Key1!=0)&&(Sw_Key3!=0)&&(Sw_Key4!=0))
{
Press_Time++;
if(Press_Time==2)//>100ms
{
Key2_Flag=1;
}
if(Press_Time>40)//>2S
{
Key2_Flag=1;
Press_Time=30;//every0.25s
}
}
if((Sw_Key3==0)&&(Sw_Key1!=0)&&(Sw_Key2!=0)&&(Sw_Key4!=0))
{
Press_Time++;
if(Press_Time==2)//>100ms
{
Key3_Flag=1;
}
if(Press_Time>80)//>2S
{
Key3_Flag=1;
Press_Time=78;//very0.25s
}
}
if((Sw_Key4==0)&&(Sw_Key1!=0)&&(Sw_Key2!=0)&&(Sw_Key3!=0))
{
Press_Time++;
if(Press_Time==2)//>100ms
{
Key4_Flag=1;
}
if(Press_Time>80)//>2S
{
Key4_Flag=1;
Press_Time=78;//every0.25s
}
}
if((Sw_Key3==0)&&(Sw_Key1==0))//doublekeysavekey
{
Press_Time++;
if(Press_Time==9)//>100ms
{
Key5_Flag=1;
}
}
if((Sw_Key4==0)&&(Sw_Key1==0))//doublekeyerasekey
{
Press_Time++;
if(Press_Time==6)//>100ms
{
Key6_Flag=1;
}
}
if((Sw_Key1!=0)&&(Sw_Key2!=0)&&(Sw_Key3!=0)&&(Sw_Key4!=0))
{
Press_Time=0;
}
if(((Key2_Flag)||(Key3_Flag)||(Key4_Flag))&&(First_Press_Flag))
{
First_Press_Flag=0;
Press_Time=2;
Key1_Flag=1;
Key2_Flag=Key3_Flag=Key4_Flag=Key5_Flag=Key6_Flag=0;
}
_nop_();
}
//Timer1定时中断服务程序;5ms中断一次
voidTimer1(void)interrupt3using1
{
Run_Time++;
Hand_Time();
//Auto_Run();
}
/*=================================================================================*/
voidSerial(void)interrupt4using3
{
}
/*==================================================================================*/
//主程序
voidmain(void)
{
unchari,j,l;
//unint*x;
PMR=0x41;//Use1kSRAM
TMOD=TMOD_MODE_WORD;
TCON=TCON_MODE_WORD;
TH0=(unchar)((65536-TIMER0_VALUE)>>8);
TL0=(unchar)(65536-TIMER0_VALUE);
TH1=TIMER1_VALUE;
TL1=TIMER1_VALUE;
PCON=PCON_MODE_WORD;
SCON=SCON_MODE_WORD;
IE=IE_MODE_WORD;
IP=IP_MODE_WORD;
EA=1;
EX0=1;
//变量初始化
Delay_10_uS();
Lcd_Initialize();
mode=0;
Dmx_Timer=0;
Frequence=0;
Work_Buff_Clr();
Flash_On=1;
Frequence_Count=0;
//Amount=30;
Direction_Flag=0;
Fade_Time=0;
Pixels_Group=0;
Current_Lamp1=0;
First_Press_Flag=1;
Bk_Color_Sort=0xff;
Bk_Pixels=0xff;
//Save_Pc=20;
Save_Pc=Read_Table(15,0);
Play_Pc=0;
Bk_Play_Pc=0;
Delay_N_mS(50);
Delay_N_mS(100);
Eeprom_Write_Enable();
Eeprom_Write_Enable();
Eeprom_Write_Enable();
//Eeprominitialization----------------------------------------
Write_Table(1,3,3);//singlecolorsetpixels4
Delay_N_mS(10);
Amount=Read_Table(0,0);//等数不能大于200
if(Amount>200)
{
Write_Table(0,0,1);
Amount=1;
}
for(i=1;i<10;i++)
{
j=Read_Table(i,0);
if(j>55)//sort
Write_Table(i,0,9);
}
for(i=1;i<10;i++)
{
j=Read_Table(i,1);
if(j>15)//speed
Write_Table(i,1,0);
}
for(i=1;i<10;i++)
{
j=Read_Table(i,2);
if(j>5)//frequence
Write_Table(i,2,0);
}
for(i=1;i<10;i++)
{
j=Read_Table(i,3);//pixel
if(j>3)
Write_Table(i,3,0);
}
for(i=10;i<12;i++)
{
j=Read_Table(i,0);
if(j>10)//autorunrepeat
Write_Table(i,0,0);
}
for(i=10;i<11;i++)
{
j=Read_Table(i,1);
if(j>15)//autorunspeed
Write_Table(i,1,0);
}
j=Read_Table(14,0);//menu1remmber
if(j>12)
Write_Table(14,0,1);
Menu1=Read_Table(14,0);
Lcd_Menu1_Dsp(15);//startPICture//修改:由13改为152006-09-22
//---------------------------------------------------
Menu2=0xff;
Run_Time=0;
Direction_Flag=0;
Fade_Adj1=0;
Fade_Adj=0;
Adj_Direction_Flag1=0;
Adj_Direction_Flag=0;
Current_Lamp=0;
Current_Lamp1=0;
Color_X=0;
Color_Sort=Read_Table(Menu1,0);
Current_Color=Color_Table[Color_Sort][Color_X];
/*====================================================================================*/
for(i=0;i<30;i++)
{
Custom_Run[0]=Read_Table(i+20,0);
Custom_Run[1]=Read_Table(i+20,1);
Custom_Run[2]=Read_Table(i+20,2);
Custom_Run[3]=Read_Table(i+20,3);
Custom_Run[4]=Read_Table(i+20,4);
}
_nop_();
while(1)
{
if(Key1_Flag)//modekey
{
Key1_Flag=0;
Lcd_Menu1_Dsp(Menu1);
Menu2=0xff;
First_Press_Flag=0;
}
//---------------------------------------------
if(Key2_Flag)//functionkey
{
Key2_Flag=0;
switch(Menu1)
{
case0://system
Menu2++;
//if(Menu2<5)
Menu2=5;
//if(Menu2>7)
//Menu2=4;
switch(Menu2)
{
case5://SetAmount
Amount=Read_Table(Menu1,0);
if(Amount>199)
Amount=0;
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Amount+1);
Lcd_Number_Dsp();
Write_Table(Menu1,0,Amount);
break;
case6://setaddress
Address=Read_Table(Menu1,1);
if(Address==0)
Address=1;
if(Address>200)
Address=1;
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Address);
Lcd_Number_Dsp();
Write_Table(Menu1,1,Address);
break;
case7://Writeaddress
Lcd_Menu2_Dsp(Menu2);
break;
default:
break;
}
break;
case1://Singlecolor
Menu2++;
if(Menu2>2)
Menu2=0;
switch(Menu2)
{
case0://ColorSort
Color_Sort=Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Lcd_Color_Dsp(Color_Sort);
break;
case1://Speed
Run_Speed=Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(16-Run_Speed);
Lcd_Number_Dsp();
break;
case2://Frequence
Frequence=Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
break;
default:
break;
}
break;
case2://Flow1顺
case3://Flow2反
case4://Flow3来回
case5://Multicolor顺
case6://Multicolor反
case7://twocolorchase
case8://twocolorfadechase
case9://Fadechange
Menu2++;
if(Menu2>3)
Menu2=0;
switch(Menu2)
{
case0://ColorSort
Color_Sort=Read_Table(Menu1,Menu2);
if((Menu1!=1)&&(Color_Sort<8))
Color_Sort=8;
if((Menu1==7)&&(Color_Sort>35))
Color_Sort=8;
if((Menu1==8)&&(Color_Sort>35))
Color_Sort=8;
Lcd_Menu2_Dsp(Menu2);
Lcd_Color_Dsp(Color_Sort);
break;
case1://Speed
Run_Speed=Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(16-Run_Speed);
Lcd_Number_Dsp();
break;
case2://Frequence
Frequence=Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
break;
case3://Pixel/Step
Pixels=Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Pixels+1);
Lcd_Number_Dsp();
break;
default:
break;
}
break;
case10://AutoRun1
case11://AutoRun2
if(Menu2<8)
Menu2=8;
if(Menu2==9)
Menu2=8;
else
Menu2=9;
switch(Menu2)
{
case8:
Repeat=Read_Table(Menu1,0);//autorunrepeat
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Repeat+1);
Lcd_Number_Dsp();
break;
case9:
Circle=Read_Table(Menu1,1);//Autorunspeed
Lcd_Menu2_Dsp(1);
Hex_To_Ascii(16-Circle);
Lcd_Number_Dsp();
break;
default:
break;
}
break;
//以下为增加的客户所需模式
case13://蓝色亮30秒后,红色亮10S
Key7_Flag=1;
break;
case14://红色亮30S后,蓝色亮10S
Key8_Flag=1;
break;
default:
break;
}
}
//-------------------------------------
if(Key3_Flag)//upkey
{
Key3_Flag=0;
switch(Menu2)
{
case0://colorsort
Color_Sort=Read_Table(Menu1,Menu2);
_nop_();
Color_Sort++;
if(Color_Sort>49)
{
Color_Sort=0;
}
if((Menu1!=1)&&(Color_Sort<8))
Color_Sort=8;
if((Menu1==7)&&(Color_Sort>35))
Color_Sort=8;
if((Menu1==8)&&(Color_Sort>35))
Color_Sort=8;
Lcd_Color_Dsp(Color_Sort);
Write_Table(Menu1,Menu2,Color_Sort);
break;
case1://speed
Run_Speed=Read_Table(Menu1,Menu2);
Run_Speed--;
if(Run_Speed==0xff)
{
Run_Speed=15;
}
Hex_To_Ascii(16-Run_Speed);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Run_Speed);
break;
case2://flashfrequence
Frequence=Read_Table(Menu1,Menu2);
Frequence++;
if(Frequence>5)
{
Frequence=0;
}
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Frequence);
break;
case3://Pixels/Step
Pixels=Read_Table(Menu1,Menu2);
Pixels++;
if(Pixels>3)
{
Pixels=0;
}
Hex_To_Ascii(Pixels+1);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Pixels);
break;
case5://LampAmount
Amount=Read_Table(Menu1,0);
Amount++;
if(Amount>199)
{
Amount=0;
}
Hex_To_Ascii(Amount+1);
Lcd_Number_Dsp();
Write_Table(Menu1,0,Amount);
break;
case6://StartAddress
Address=Read_Table(Menu1,1);
Address++;
if(Address>200)
{
Address=1;
}
Hex_To_Ascii(Address);
Lcd_Number_Dsp();
Write_Table(Menu1,1,Address);
break;
case7://写地址
EA=0;
TB8=0;
SBUF=0x0f;
while(!TI);
TI=0;
TB8=1;
SBUF=0x01;
while(!TI);
TI=0;
for(i=0;i<9;i++)
{
SBUF=0;
while(!TI);
TI=0;
}
SBUF=0x01;
while(!TI);
TI=0;
Delay_N_mS(100);
TB8=0;
SBUF=0x0f;
while(!TI);
TI=0;
TB8=1;
SBUF=0x02;
while(!TI);
TI=0;
SBUF=0x00;
while(!TI);
TI=0;
SBUF=Address;
while(!TI);
TI=0;
for(i=0;i<7;i++)
{
SBUF=0;
while(!TI);
TI=0;
}
SBUF=Address+0x02;
while(!TI);
TI=0;
Delay_N_mS(500);
EA=1;
break;
case8://autorunrepeat
Repeat=Read_Table(Menu1,0);
Repeat++;
if(Repeat>15)
{
Repeat=0;
}
Hex_To_Ascii(Repeat+1);
Lcd_Number_Dsp();
Write_Table(Menu1,0,Repeat);
break;
case9://autorunspeed
Circle=Read_Table(Menu1,1);
Circle--;
if(Circle==0xff)
{
Circle=15;
}
Hex_To_Ascii(16-Circle);
Lcd_Number_Dsp();
Write_Table(Menu1,1,Circle);
break;
case0xff:
Menu1++;
if(Menu1>Menu1_Max)
{
Menu1=0;
}
Write_Table(14,0,Menu1);//记忆当前模式
Lcd_Menu1_Dsp(Menu1);
default:
break;
Run_Time=0;
Direction_Flag=0;
Fade_Adj1=0;
Fade_Adj=0;
Adj_Direction_Flag1=0;
Adj_Direction_Flag=0;
Current_Lamp=0;
Current_Lamp1=0;
Color_X=0;
Color_Sort=Read_Table(Menu1,0);
Current_Color=Color_Table[Color_Sort][Color_X];
}
}
//-------------------------------------------------
if(Key4_Flag)//downkey
{
Key4_Flag=0;
switch(Menu2)
{
case0://colorsort
Color_Sort=Read_Table(Menu1,Menu2);
Color_Sort--;
if(Color_Sort==0xff)
{
Color_Sort=49;
}
if((Menu1!=1)&&(Color_Sort<8))
Color_Sort=49;
if((Menu1==7)&&(Color_Sort>35))
Color_Sort=35;
if((Menu1==8)&&(Color_Sort>35))
Color_Sort=35;
Lcd_Color_Dsp(Color_Sort);
Write_Table(Menu1,Menu2,Color_Sort);;
break;
case1://Speed
Run_Speed=Read_Table(Menu1,Menu2);
Run_Speed++;
if(Run_Speed>15)
{
Run_Speed=0;
}
Hex_To_Ascii(16-Run_Speed);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Run_Speed);
break;
case2://flashfrequence
Frequence=Read_Table(Menu1,Menu2);
Frequence--;
if(Frequence==0xff)
{
Frequence=5;
}
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Frequence);
break;
case3://Pixels/Step
Pixels=Read_Table(Menu1,Menu2);
Pixels--;
if(Pixels==0xff)
{
Pixels=3;
}
Hex_To_Ascii(Pixels+1);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Pixels);
break;
case5://LampAmount
Amount=Read_Table(Menu1,0);
Amount--;
if(Amount==0xff)
{
Amount=199;
}
Hex_To_Ascii(Amount+1);
Lcd_Number_Dsp();
Write_Table(Menu1,0,Amount);
break;
case6://StartAddress
Address=Read_Table(Menu1,1);
Address--;
if(Address==0)
{
Address=200;
}
Hex_To_Ascii(Address);
Lcd_Number_Dsp();
Write_Table(Menu1,1,Address);
break;
case8://autorunrepeat
Repeat=Read_Table(Menu1,0);
Repeat--;
if(Repeat==0xff)
{
Repeat=15;
}
Hex_To_Ascii(Repeat+1);
Lcd_Number_Dsp();
Write_Table(Menu1,0,Repeat);
break;
case9://autorunspeed
Circle=Read_Table(Menu1,1);
Circle++;
if(Circle>15)
{
Circle=0;
}
Hex_To_Ascii(16-Circle);
Lcd_Number_Dsp();
Write_Table(Menu1,1,Circle);
break;
case0xff:
Menu1--;
if(Menu1==0xff)
{
Menu1=Menu1_Max;
}
Write_Table(14,0,Menu1);//记忆当前模式
Lcd_Menu1_Dsp(Menu1);
break;
default:
break;
Run_Time=0;
Direction_Flag=0;
Fade_Adj1=0;
Fade_Adj=0;
Adj_Direction_Flag1=0;
Adj_Direction_Flag=0;
Current_Lamp=0;
Current_Lamp1=0;
Color_X=0;
Color_Sort=Read_Table(Menu1,0);
Current_Color=Color_Table[Color_Sort][Color_X];
}
}
if(Key5_Flag)//savekey
{
Key5_Flag=0;
if((Menu1<10)&&(Menu1!=0)&&(Menu2==0xff))
{
Lcd_Menu2_Dsp(9);
Save_Pc=Read_Table(15,0);
if(Save_Pc>=50)
Save_Pc=20;
Write_Table(Save_Pc,0,Menu1);
i=Read_Table(Menu1,0);
Write_Table(Save_Pc,1,i);
i=Read_Table(Menu1,1);
Write_Table(Save_Pc,2,i);
i=Read_Table(Menu1,2);
Write_Table(Save_Pc,3,i);
i=Read_Table(Menu1,3);
Write_Table(Save_Pc,4,i);
for(i=0;i<30;i++)
{
Custom_Run[0]=Read_Table(i+20,0);
Custom_Run[1]=Read_Table(i+20,1);
Custom_Run[2]=Read_Table(i+20,2);
Custom_Run[3]=Read_Table(i+20,3);
Custom_Run[4]=Read_Table(i+20,4);
}
Hex_To_Ascii(Save_Pc-19);
Lcd_Number_Dsp();
Save_Pc++;
if(Save_Pc>=50)
{
Save_Pc=20;
}
Write_Table(15,0,Save_Pc);
Play_Pc=0;
}
}
if(Key6_Flag)//erasekey
{
Key6_Flag=0;
if((Menu1<10)&&(Menu1!=0)&&(Menu2==0xff))
{
Lcd_Menu2_Dsp(10);
for(i=20;i<50;i++)
{
Write_Table(i,0,0xff);
Write_Table(i,1,0xff);
Write_Table(i,2,0xff);
Write_Table(i,3,0xff);
Write_Table(i,4,0xff);
}
Save_Pc=20;
Write_Table(15,0,Save_Pc);
for(i=0;i<30;i++)
{
Custom_Run[0]=Read_Table(i+20,0);
Custom_Run[1]=Read_Table(i+20,1);
Custom_Run[2]=Read_Table(i+20,2);
Custom_Run[3]=Read_Table(i+20,3);
Custom_Run[4]=Read_Table(i+20,4);
}
Play_Pc=0;
}
}
//----------------------------------------------------------------------------------------------------------
if((Color_Sort!=Bk_Color_Sort)||(Pixels!=Bk_Pixels))
{
Bk_Color_Sort=Color_Sort;
Bk_Pixels=Pixels;
i=0;
while(i<32)
{
for(j=0;j<8;j++)
{
for(l=0;l
Color_Table2=Color_Table[Color_Sort][j];
i++;
}
}
}
}
if(Menu1==0)
{
TB8=0;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
//SBUF=30;
//while(!TI);
//TI=0;
for(j=0;j<200;j++)//576
{
TB8=1;
SBUF=0;
while(!TI);
TI=0;
}
}
if((Menu1<10)&&(Menu1!=0))
{
Color_Sort=Read_Table(Menu1,0);
Run_Speed=Read_Table(Menu1,1);
Frequence=Read_Table(Menu1,2);
Pixels=Read_Table(Menu1,3);
if(Pixels>3)
Pixels=Read_Table(Menu1,3);
if(Pixels>3)
Pixels=0;
Bk_Menu1=Menu1;
Auto_Run();
}
if(Menu1==10)//autoran1
{
Repeat=Read_Table(Menu1,0);
Circle=Read_Table(Menu1,1);//speed
Bk_Menu1=Autorun_Table1[Auto_Step1][0];
Color_Sort=Autorun_Table1[Auto_Step1][1];
Run_Speed=16-Autorun_Table1[Auto_Step1][2];
Run_Speed=Run_Speed+Circle;
Frequence=Autorun_Table1[Auto_Step1][3];
Pixels=Autorun_Table1[Auto_Step1][4];
Auto_Run();
}
if(Menu1==11)
{
Repeat=Read_Table(Menu1,0);
Circle=Read_Table(Menu1,1);//speed
Bk_Menu1=Autorun_Table2[Auto_Step2][0];
Color_Sort=Autorun_Table2[Auto_Step2][1];
Run_Speed=16-Autorun_Table2[Auto_Step2][2];
Run_Speed=Run_Speed+Circle;
Frequence=Autorun_Table2[Auto_Step2][3];
Pixels=Autorun_Table2[Auto_Step2][4];
Auto_Run();
}
i=Custom_Run[Play_Pc][0];
if((Menu1==12)&&(i<10))
{
Repeat=0;
Circle=0;
Bk_Menu1=Custom_Run[Play_Pc][0];
Color_Sort=Custom_Run[Play_Pc][1];
Run_Speed=Custom_Run[Play_Pc][2];
Run_Speed=Run_Speed+Circle;
Frequence=Custom_Run[Play_Pc][3];
Pixels=Custom_Run[Play_Pc][4];
Auto_Run();
if(!First_Press_Flag)//开机时不显示
{
Bk_Play_Pc++;
if(Bk_Play_Pc>20)
{
Bk_Play_Pc=0;
Hex_To_Ascii(Play_Pc+1);
Lcd_Number_Dsp();
}
}
}
//蓝色亮10S,白色亮30S
if(Menu1==13)//增加于2006-09-22
{
Repeat=Read_Table(Menu1,0);
Circle=Read_Table(Menu1,1);
Flag.bit7=1;//开始计数
if(Flag.bit8)//亮白色
{
Send_blue();
if(Delaywb>DELAY_10)
{
Flag.bit8=0;
Delaywb=0;
}
}
else
{
Send_write();
if(Delaywb>DELAY_30)
{
Flag.bit8=1;
Delaywb=0;
}
}
}
//蓝色亮30S,白色亮10S
if(Menu1==14)//增加于2006-09-22
{
Repeat=Read_Table(Menu1,0);
Circle=Read_Table(Menu1,1);
Flag.bit7=1;//开始计数
if(Flag.bit8)//亮白色
{
Send_blue();
if(Delaywb>DELAY_30)
{
Flag.bit8=0;
Delaywb=0;
}
}
else
{
Send_write();
if(Delaywb>DELAY_10)
{
Flag.bit8=1;
Delaywb=0;
}
}
}
}
}
voidAuto_Run(void)
{
unchari,j,k;
i=Current_Lamp+Pixels;
if(i>Amount)
i=Amount;
switch(Bk_Menu1)
{
case1:
Pixels_Group=2;
Fade=0xff;//单色
Color_Set(0,31,Current_Color);
Dmx_Timer=8;
Send_Dmx_Data();
break;
case2://Flow1顺
Pixels_Group=0;
Fade=0xff;
Color_Set(Begin_Lamp+Current_Lamp,i+Begin_Lamp,Current_Color);
Dmx_Timer=8;
Send_Dmx_Data();
break;
case3://Flow2反
Pixels_Group=0;
Fade=0xff;
Color_Set(Amount-i+Begin_Lamp,Amount-Current_Lamp+Begin_Lamp,Current_Color);
Dmx_Timer=8;
Send_Dmx_Data();
break;
case4://Flow3来回
Pixels_Group=0;
Fade=0xff;
if(Direction_Flag)
Color_Set(Current_Lamp+Begin_Lamp,i+Begin_Lamp,Current_Color);
else
Color_Set(Amount-i+Begin_Lamp,Amount-Current_Lamp+Begin_Lamp,Current_Color);
Dmx_Timer=8;
Send_Dmx_Data();
break;
case5://Multicolor顺
Pixels_Group=1;
Fade=0xff;
EA=0;
for(i=0;i<32;i++)
{
j=(i+Current_Lamp1)%32;
Color_Set(i,i,Color_Table2[j]);
}
EA=1;
Dmx_Timer=8;
Send_Dmx_Data();
break;
case6://Multicolor反
Pixels_Group=1;
Fade=0xff;
EA=0;
for(i=0;i<32;i++)
{
j=(i+Current_Lamp1)%32;
Color_Set(31-i,31-i,Color_Table2[j]);
}
EA=1;
Dmx_Timer=8;
Send_Dmx_Data();
break;
case7://twocolorchase
Pixels_Group=1;
Fade=0xff;
i=0;
while(i<32)
{
j=Current_Lamp1%2;
for(k=0;k
Color_Set(i,i,Color_Table[Color_Sort][j]);
i++;
}
for(k=0;k
Color_Set(i,i,Color_Table[Color_Sort][1-j]);
i++;
}
}
_nop_();
Dmx_Timer=8;
Send_Dmx_Data();
break;
case8://twocolorFadechase
Pixels_Group=1;
Fade=0xff;
i=0;
while(i<32)
{
j=Current_Lamp1%2;
Fade=Fade_Adj*8;
for(k=0;k
Color_Set(i,i,Color_Table[Color_Sort][0]);
i++;
}
Fade=0xFF-Fade_Adj*8;
for(k=0;k
Color_Set(i,i,Color_Table[Color_Sort][1]);
i++;
}
}
_nop_();
Dmx_Timer=8;
Send_Dmx_Data();
break;
case9://fadechange
Pixels_Group=2;
Fade_Time++;
if(Fade_Time>Run_Speed)
{
Fade_Time=0;
if(R_data1>R_data2)
R_data1--;
if(R_data1
if(G_data1>G_data2)
G_data1--;
if(G_data1
if(B_data1>B_data2)
B_data1--;
if(B_data1
Work_Data_Buff[0]=R_data1;
Work_Data_Buff[1]=G_data1;
Work_Data_Buff[2]=B_data1;
Send_Dmx_Data();
}
if((R_data1==R_data2)&&(G_data1==G_data2)&&(B_data1==B_data2))
{
Color_X3++;
if(Color_X3>7)
{
Color_X3=0;
//自动运行参数-------------
Auto_Reapeat++;
if(Auto_Reapeat>Repeat)
{
Auto_Reapeat=0;
if(Menu1==10)//autoran1
{
Auto_Step1++;
if(Auto_Step1>Auto_Step1_Max)
Auto_Step1=0;
Bk_Menu1=Autorun_Table1[Auto_Step1][0];
Color_Sort=Autorun_Table1[Auto_Step1][1];
Run_Speed=Autorun_Table1[Auto_Step1][2];
Run_Speed=Run_Speed+Circle;
Frequence=Autorun_Table1[Auto_Step1][3];
Pixels=Autorun_Table1[Auto_Step1][4];
}
if(Menu1==11)
{
Auto_Step2++;
if(Auto_Step2>Auto_Step2_Max)
Auto_Step2=0;
Bk_Menu1=Autorun_Table2[Auto_Step2][0];
Color_Sort=Autorun_Table2[Auto_Step2][1];
Run_Speed=Autorun_Table2[Auto_Step2][2];
Run_Speed=Run_Speed+Circle;
Frequence=Autorun_Table2[Auto_Step2][3];
Pixels=Autorun_Table2[Auto_Step2][4];
}
i=Custom_Run[Play_Pc][0];
if((Menu1==12)&&(i<10))
{
Play_Pc++;
if(Play_Pc>29)
Play_Pc=0;
i=Custom_Run[Play_Pc][0];
if(i>10)
Play_Pc=0;
Bk_Menu1=Custom_Run[Play_Pc][0];
Color_Sort=Custom_Run[Play_Pc][1];
Run_Speed=Custom_Run[Play_Pc][2];
Run_Speed=Run_Speed+Circle;
Frequence=Custom_Run[Play_Pc][3];
Pixels=Custom_Run[Play_Pc][4];
}
Color_X=0;
Current_Color=Color_Table[Color_Sort][Color_X];
Current_Lamp=0;
Run_Time=0;
Color_Set(0,31,D);
_nop_();
}
//-----------------------
}
k=Color_X3+1;
if(k==8)
k=0;
Temp_Color2=Color_Table[Color_Sort][k];
Temp_Color1=Color_Table[Color_Sort][Color_X3];
Fade_Color2Color();//Temp_Color1,Temp_Color2);
}
break;
default:
break;
}
//Send_Dmx_Data();
_nop_();
}
voidHand_Time(void)
{
unchari;
_nop_();
if(Run_Time>Run_Speed)//
{
Run_Time=0;
Current_Lamp++;
Current_Lamp=Current_Lamp+Pixels;
if(!((Bk_Menu1==2)||(Bk_Menu1==3)||(Bk_Menu1==4)))//非流水时,循环不超过16盏灯
{
if(Current_Lamp>16)
Current_Lamp=Amount+1;
}
if(Current_Lamp>Amount)
{
Current_Lamp=0;
if(Direction_Flag)
Direction_Flag=0;
else
Direction_Flag=1;
Color_X++;
if(Color_X>7)
{
Color_X=0;
if(Bk_Menu1!=9)
{
Auto_Reapeat++;
if(Auto_Reapeat>Repeat)
{
Auto_Reapeat=0;
if(Menu1==10)//autoran1
{
Auto_Step1++;
if(Auto_Step1>Auto_Step1_Max)
Auto_Step1=0;
Bk_Menu1=Autorun_Table1[Auto_Step1][0];
Color_Sort=Autorun_Table1[Auto_Step1][1];
Run_Speed=Autorun_Table1[Auto_Step1][2];
Run_Speed=Run_Speed+Circle;
Frequence=Autorun_Table1[Auto_Step1][3];
Pixels=Autorun_Table1[Auto_Step1][4];
}
if(Menu1==11)
{
Auto_Step2++;
if(Auto_Step2>Auto_Step2_Max)
Auto_Step2=0;
Bk_Menu1=Autorun_Table2[Auto_Step2][0];
Color_Sort=Autorun_Table2[Auto_Step2][1];
Run_Speed=Autorun_Table2[Auto_Step2][2];
Run_Speed=Run_Speed+Circle;
Frequence=Autorun_Table2[Auto_Step2][3];
Pixels=Autorun_Table2[Auto_Step2][4];
}
i=Custom_Run[Play_Pc][0];
if((Menu1==12)&&(i<10))
{
Play_Pc++;
if(Play_Pc>29)
Play_Pc=0;
i=Custom_Run[Play_Pc][0];
if(i>10)
Play_Pc=0;
Bk_Menu1=Custom_Run[Play_Pc][0];
Color_Sort=Custom_Run[Play_Pc][1];
Run_Speed=Custom_Run[Play_Pc][2];
Run_Speed=Run_Speed+Circle;
Frequence=Custom_Run[Play_Pc][3];
Pixels=Custom_Run[Play_Pc][4];
}
Temp_Color2=Color_Table[Color_Sort][1];
Temp_Color1=Color_Table[Color_Sort][0];
Fade_Color2Color();//Temp_Color1,Temp_Color2);
Color_X3=0;
}
}
}
Current_Color=Color_Table[Color_Sort][Color_X];
}
Current_Lamp1++;
if(Current_Lamp1>31)
Current_Lamp1=0;
if(Adj_Direction_Flag)
{
Fade_Adj++;
if(Fade_Adj>31)
{
Adj_Direction_Flag=0;
Fade_Adj=31;
}
}
else
{
Fade_Adj--;
if(Fade_Adj==0xff)
{
Adj_Direction_Flag=1;
Fade_Adj=0;
}
}
if(Adj_Direction_Flag1)
{
Fade_Adj1++;
if(Fade_Adj1>255)
{
Adj_Direction_Flag1=0;
Fade_Adj1=255;
}
}
else
{
Fade_Adj1--;
if(Fade_Adj1==0xff)
{
Adj_Direction_Flag1=1;
Fade_Adj1=0;
}
}
}
}
voidFade_Color2Color(void)//uncharcolor1,color2)
{
switch(Temp_Color1)
{
caseRed:
R_data1=0xff;
G_data1=0x00;
B_data1=0x00;
break;
caseGreen:
R_data1=0x00;
G_data1=0xff;
B_data1=0x00;
break;
caseYellow:
R_data1=0xff;
G_data1=0xff;
B_data1=0x00;
break;
caseBlue:
R_data1=0x00;
G_data1=0x00;
B_data1=0xff;
break;
casePurple:
R_data1=0xff;
G_data1=0x00;
B_data1=0xff;
break;
caseCyan:
R_data1=0x00;
G_data1=0xff;
B_data1=0xff;
break;
caseWhite:
R_data1=0xff;
G_data1=0xff;
B_data1=0xff;
break;
caseBlack:
R_data1=0x00;
G_data1=0x00;
B_data1=0x00;
break;
caseOrange:
R_data1=0xff;
G_data1=125;
B_data1=0x00;
break;
casePink:
R_data1=0xff;
G_data1=0;
B_data1=125;
break;
default:
break;
}
switch(Temp_Color2)//color2)
{
caseRed:
R_data2=0xff;
G_data2=0x00;
B_data2=0x00;
break;
caseGreen:
R_data2=0x00;
G_data2=0xff;
B_data2=0x00;
break;
caseYellow:
R_data2=0xff;
G_data2=0xff;
B_data2=0x00;
break;
caseBlue:
R_data2=0x00;
G_data2=0x00;
B_data2=0xff;
break;
casePurple:
R_data2=0xff;
G_data2=0x00;
B_data2=0xff;
break;
caseCyan:
R_data2=0x00;
G_data2=0xff;
B_data2=0xff;
break;
caseWhite:
R_data2=0xff;
G_data2=0xff;
B_data2=0xff;
break;
caseBlack:
R_data2=0x00;
G_data2=0x00;
B_data2=0x00;
break;
caseOrange:
R_data2=0xff;
G_data2=125;
B_data2=0x00;
break;
casePink:
R_data2=0xff;
G_data2=0;
B_data2=125;
break;
default:
break;
}
}
voidSend_Dmx_Data(void)
{
uninti,j;
Send_Data_Enable_Flag=0;
Dmx_Timer++;
//if(Bk_Menu1==9)
//Dmx_Timer=9;
if(Dmx_Timer>2)
{
Dmx_Timer=0;//send672dataneed38mS
if(Flash_On)
{
Frequence_Count++;
if(Frequence_Count>(5-Frequence))
{
Frequence_Count=0;
Flash_On=0;
}
if(!Frequence)
{
Flash_On=1;
}
switch(Pixels_Group)
{
case0:
TB8=0;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
//SBUF=30;
//while(!TI);
//TI=0;
for(j=0;j<600;j++)//576
{
SBUF=Work_Data_Buff[j];
while(!TI);
TI=0;
}
break;
case1:
TB8=0;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
//SBUF=30;
//while(!TI);
//TI=0;
for(i=0;i<7;i++)//6
{
for(j=0;j<96;j++)
{
SBUF=Work_Data_Buff[j];
while(!TI);
TI=0;
}
}
break;
case2:
TB8=0;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
for(i=0;i<200;i++)
{
for(j=0;j<3;j++)
{
SBUF=Work_Data_Buff[j];
while(!TI);
TI=0;
}
}
/*
_nop_();
for(j=0;j<1;j++)
{
i=0;
TB8=0;
TB8=0;
TB8=0;
TB8=0;
TB8=0;
SBUF=0x0f;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x06;
i=i+0x06;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x02;
i=i+0x02;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=0x08;
i=i+0x08;
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=Work_Data_Buff[0];
i=i+Work_Data_Buff[0];
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=Work_Data_Buff[1];
i=i+Work_Data_Buff[1];
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=Work_Data_Buff[2];
i=i+Work_Data_Buff[2];
while(!TI);
TI=0;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
TB8=1;
SBUF=i;
while(!TI);
TI=0;
Delay_N_mS(1);
}
_nop_();*/
break;
default:
break;
}
}
else
{
Frequence_Count++;
if(Frequence_Count>(5-Frequence))
{
Frequence_Count=0;
Flash_On=1;
}
TB8=0;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
//SBUF=30;
//while(!TI);
//TI=0;
for(j=0;j<576;j++)
{
SBUF=00;
while(!TI);
TI=0;
}
}
Delay_N_mS(4);
}
}
/*====================================================================================*/
uncharRead_Table(unchari,uncharj)
{
unchartemp2;
uninttemp1;
EA=0;
temp1=i*5+j;
temp2=Eeprom_Read_Data(temp1);
EA=1;
//temp2=Menu[j];
returntemp2;
}
voidWrite_Table(unchari,uncharj,uncharadj)
{
//Menu[j]=adj;
uninttemp1;
unchartemp2;
EA=0;
temp1=i*5+j;
temp2=adj;
Eeprom_Write_Data(temp1,temp2);
EA=1;
}
voidWork_Buff_Clr(void)
{
uninti;
for(i=0;i<512;i++)
{
Work_Data_Buff=0x00;
}
}
voidColor_Set(unintCh1,unintCh2,uncharColor)//参数:起始通道,结束通道,颜色
{
uncharR_data,G_data,B_data;
uninti;
switch(Color)
{
caseRed:
R_data=Fade;
G_data=0x00;
B_data=0x00;
break;
caseGreen:
R_data=0x00;
G_data=Fade;
B_data=0x00;
break;
caseYellow:
R_data=Fade;
G_data=Fade;
B_data=0x00;
break;
caseBlue:
R_data=0x00;
G_data=0x00;
B_data=Fade;
break;
casePurple:
R_data=Fade;
G_data=0x00;
B_data=Fade;
break;
caseCyan:
R_data=0x00;
G_data=Fade;
B_data=Fade;
break;
caseWhite:
R_data=Fade;
G_data=Fade;
B_data=Fade;
break;
caseBlack:
R_data=0x00;
G_data=0x00;
B_data=0x00;
break;
caseOrange:
R_data=0xff;
G_data=125;
B_data=0x00;
break;
casePink:
R_data=0xff;
G_data=0;
B_data=125;
break;
default:
break;
}
_nop_();
for(i=Ch1*3;i<=Ch2*3;i++)
{
Work_Data_Buff=R_data;
i++;
Work_Data_Buff=G_data;
i++;
Work_Data_Buff=B_data;
}
_nop_();
}
/*----------------------------------------------------------------------------------*/
voidDelay_10_uS(void)
{
chari=30;
while(i--);
}
voidDelay_N_mS(unintn_milisecond)/*nmSdelay*/
{
unchari;
while(n_milisecond--)
{
//i=165;//nomaldealy
i=165*3;//forw77e58
while(i--);
}
}
/*==================================================================================*/
voidLcd_Initialize(void)
{
//RS=0,写命令码操作
Lcd_RS_Cs=0;
//RW=0,写操作
Lcd_RW_Cs=0;
//功能设定命令码(FunctionSet)
//D/L(bit4)=1:8bit资料接口
//N(bit3)=1:2行显示
//F(bit2)=0:5x7dots
Lcd_Write_Data(0x38);
Delay_N_mS(1);
//功能设定命令码(FunctionSet)
//D/L(bit4)=1:8bit资料接口
//N(bit3)=1:2行显示
//F(bit2)=0:5x7dots
Lcd_Write_Data(0x38);
Delay_N_mS(1);
//功能设定命令码(FunctionSet)
//D/L(bit4)=1:8bit资料接口
//N(bit3)=1:2行显示
//F(bit2)=0:5x7dots
Lcd_Write_Data(0x38);
Delay_N_mS(1);
//显示开关命令码(DisplayOn/OffControl)
//D(bit2)=0:字符显示关闭
//C(bit1)=0:光标显示关闭
//B(bit0)=0:光标闪烁关闭
Lcd_Write_Data(0x08);
Delay_N_mS(1);
//清除所有显示,将光标返回到起始位址
Lcd_Write_Data(0x01);
Delay_N_mS(1);
}
/*==================================================================================*/
//LCDmenu1显示
voidLcd_Menu1_Dsp(uncharItem_Rg)
{
unchari;
Lcd_RS_Cs=0;
Lcd_RW_Cs=0;
Lcd_Write_Data(0x0C);
Delay_N_mS(1);
//设置DDRAM的位址,位址码为0
Lcd_Write_Data(0x80);
Delay_N_mS(1);
Lcd_RS_Cs=1;
Lcd_RW_Cs=0;
for(i=0;i<16;i++)
{
Lcd_Write_Data(Menu1_Tab[Item_Rg*2]);
Delay_N_mS(1);
//Delay_10_uS();
//Delay_10_uS();
}
Lcd_RS_Cs=0;
Lcd_RW_Cs=0;
//设置DDRAM的位址
Lcd_Write_Data(0xC0);
Delay_N_mS(1);
Lcd_RS_Cs=1;
Lcd_RW_Cs=0;
for(i=0;i<16;i++)
{
Lcd_Write_Data(Menu1_Tab[Item_Rg*2+1]);
Delay_N_mS(1);
//Delay_10_uS();
}
}
//Delay_10_uS();
/*==================================================================================*/
//LCDmenu2显示
voidLcd_Menu2_Dsp(uncharItem_Rg)
{
unchari;
Lcd_RS_Cs=0;
Lcd_RW_Cs=0;
Lcd_Write_Data(0x0C);
Delay_N_mS(1);
//设置DDRAM的位址,位址码为0
Lcd_Write_Data(0x80);
Delay_N_mS(1);
Lcd_RS_Cs=1;
Lcd_RW_Cs=0;
for(i=0;i<16;i++)
{
Lcd_Write_Data(Menu2_Tab[Item_Rg*2]);
Delay_N_mS(1);
}
Lcd_RS_Cs=0;
Lcd_RW_Cs=0;
//设置DDRAM的位址
Lcd_Write_Data(0xC0);
Delay_N_mS(1);
Lcd_RS_Cs=1;
Lcd_RW_Cs=0;
for(i=0;i<16;i++)
{
Lcd_Write_Data(Menu2_Tab[Item_Rg*2+1]);
Delay_N_mS(1);
}
}
voidLcd_Color_Dsp(uncharItem_Rg)
{
unchari;
Lcd_RS_Cs=0;
Lcd_RW_Cs=0;
Lcd_Write_Data(0x0C);
Delay_N_mS(1);
//设置DDRAM的位址,位址码为0
Lcd_Write_Data(0xc0);
Delay_N_mS(1);
Lcd_RS_Cs=1;
Lcd_RW_Cs=0;
for(i=0;i<16;i++)
{
Lcd_Write_Data(Color_Tab[Item_Rg]);
Delay_N_mS(1);
}
}
//=====================================================================================
//LCD写操作动作
voidLcd_Write_Data(uncharData_Rg)
{
Lcd_OE_Cs=1;
_nop_();
_nop_();
_nop_();
_nop_();
P0=Data_Rg;
_nop_();
_nop_();
_nop_();
_nop_();
Lcd_OE_Cs=0;
}
/*=======================================================================================*/
voidLcd_Number_Dsp(void)
{
unchari;
Lcd_RS_Cs=0;
Lcd_RW_Cs=0;
Lcd_Write_Data(0x0C);
Delay_N_mS(1);
//设置DDRAM的位址,位址码为
Lcd_Write_Data(0xc6);
Delay_N_mS(1);
Lcd_RS_Cs=1;
Lcd_RW_Cs=0;
for(i=0;i<5;i++)
{
Lcd_Write_Data(Set_Num);
Delay_N_mS(1);
}
}
//=========================================================================================
voidHex_To_Ascii(unintData_Rg)
{
unchari;
uncharHex4Bcd_Buf[5];
//HexToBCD
for(i=5;i>0;i--)
{
Hex4Bcd_Buf[i-1]=Data_Rg%10;
Data_Rg/=10;
}
/*--------------------------------------*/
for(i=0;i<5;i++)
{
Set_Num[i]=0x20;
}
//BCDToASCII
if(Hex4Bcd_Buf[0]==0)
{
Set_Num[0]=0x20;
if(Hex4Bcd_Buf[1]==0)
{
Set_Num[1]=0x20;
if(Hex4Bcd_Buf[2]==0)
{
Set_Num[2]=0x20;
if(Hex4Bcd_Buf[3]==0)
{
Set_Num[3]=0x20;
Set_Num[4]=Hex4Bcd_Buf[4]+0x30;
}
else
{
Set_Num[3]=Hex4Bcd_Buf[3]+0x30;
Set_Num[4]=Hex4Bcd_Buf[4]+0x30;
}
}
else
{
for(i=2;i<5;i++)
{
Set_Num[i]=Hex4Bcd_Buf+0x30;
}
}
}
else
{
for(i=1;i<5;i++)
{
Set_Num[i]=Hex4Bcd_Buf+0x30;
}
}
}
else
{
for(i=0;i<5;i++)
{
Set_Num[i]=Hex4Bcd_Buf+0x30;
}
}
}
/*==================================================================================*/
//功能:写资料到EEPROM指定地址.
//传入参数:1.资料码.
//2.地址码.
voidEeprom_Write_Data(unintAddress_Rg,unintValue_Rg)
{
EE_Write_Start_Bit();
EE_Write_Code_Bit(0x40,2);//写操作码"01"
//写地址A8(93C66)
EE_Write_Code_Bit((unchar)(Address_Rg>>1),1);
//写地址A7--A0(93C66)
EE_Write_Code_Bit((unchar)Address_Rg,8);
//写1个Byte资料
EE_Write_Code_Bit((unchar)Value_Rg,8);
//检测"忙"
Eeprom_Check_Busy();
Eeprom_CS_Fg=0;
}
/*==================================================================================*/
//功能:从EEPROM指定地址读取资料.
//传入参数:地址码.
//传回参数:资料码.
uncharEeprom_Read_Data(unintAddress_Rg)
{
uncharRead_Data_Buf;
EE_Write_Start_Bit();
//写操作码"10"
EE_Write_Code_Bit(0x80,2);
/*-------------------------------------*/
//写地址A8(93C66)
EE_Write_Code_Bit((unchar)(Address_Rg>>1),1);
//写地址A7--A0(93C66)
EE_Write_Code_Bit((unchar)Address_Rg,8);
//读1个Byte资料
Read_Data_Buf=EE_Read_Code_Bit();
Eeprom_CS_Fg=0;
returnRead_Data_Buf;
}
/*==================================================================================*/
//功能:EEPROM抹除及写致能命令.
voidEeprom_Write_Enable(void)
{
unchari;
EE_Write_Start_Bit();
EE_Write_Code_Bit(0x30,4);
EE_Write_Code_Bit(0x00,7);
Eeprom_CS_Fg=0;
Eeprom_CK_Fg=0;
Eeprom_DI_Fg=0;
for(i=0;i
}
/*==================================================================================*/
voidEE_Write_Code_Bit(uncharCode_Rg,uncharBit_Count_Rg)
{
unchari;
while(Bit_Count_Rg--)
{
Eeprom_DI_Fg=(Code_Rg&0x80)?1:0;
for(i=0;i
Eeprom_CK_Fg=1;
for(i=0;i
Eeprom_CK_Fg=0;
for(i=0;i
Code_Rg<<=1;
}
}
/*==================================================================================*/
//功能:从EEPROM内部读取1Byte的资料.
//传回参数:资料码.
uncharEE_Read_Code_Bit(void)
{
unchari;
uncharm;
uncharData_Rg;
Eeprom_DO_Fg=1;
Data_Rg=0;
for(i=0;i<8;i++)
{
Data_Rg<<=1;
Eeprom_CK_Fg=1;
for(m=0;m
Eeprom_CK_Fg=0;
for(m=0;m
if(Eeprom_DO_Fg)
{
Data_Rg|=0x01;
}
}
returnData_Rg;
}
/*==================================================================================*/
//功能:写起始位元到EEPROM
voidEE_Write_Start_Bit(void)
{
unchari;
Eeprom_CS_Fg=1;
Eeprom_CK_Fg=0;
for(i=0;i
Eeprom_DI_Fg=0;
for(i=0;i
Eeprom_CK_Fg=1;
for(i=0;i
Eeprom_CK_Fg=0;
for(i=0;i
Eeprom_DI_Fg=1;
for(i=0;i
Eeprom_CK_Fg=1;
for(i=0;i
Eeprom_CK_Fg=0;
for(i=0;i
}
/*==================================================================================*/
//功能:检测EEPROM"忙".
bitEeprom_Check_Busy(void)
{
uninti;
Eeprom_DO_Fg=1;
Eeprom_CS_Fg=0;
for(i=0;i<6;i++)
;
Eeprom_CS_Fg=1;
for(i=0;i<2000;i++)
{
//Eeprom_CK_Fg=1;
_nop_();
_nop_();
_nop_();
_nop_();
//Eeprom_CK_Fg=0;
_nop_();
_nop_();
_nop_();
_nop_();
if(Eeprom_DO_Fg)
{
break;
}
}
returni?0:1;
}
/*==================================================================================*/
voidSend_write(void)
{
ucharwrite;
TB8=0;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
for(write=0;write<600;write++)
{
SBUF=0xFF;
while(!TI);
TI=0;
}
}
/*********************************************************/
voidSend_blue(void)
{
ucharblue0,blue1;
TB8=0;
SBUF=0x00;
while(!TI);
TI=0;
TB8=1;
SBUF=0x00;
while(!TI);
TI=0;
for(blue1=0;blue1<200;blue1++
{
for(blue0=0;blue0<3;;blue0++)
{
if(blue==2)
{
SBUF=0xFF;
while(!TI);
TI=0;
}
else
{
SBUF=0xFF;
while(!TI);
TI=0;
}
}
}
}