/*==========================================*/
/* 1. 本程序采用 keil 编译系统. */
/* 2. 本程序为水底灯简易Dmx控制器 */
/* 3. 采用
AT89C52 单片机 , Fosc = 16MHz */
*/
/*==========================================*/
//程序修改 SYSTEM MODE下使投光灯熄灭
#include <reg51.h>
#include <intrins.h>
/*=======================================*/
//序修改 增加1。蓝色亮30秒后,白色亮10秒循环
// 2。白色亮30秒后,蓝色亮10秒循环
/* 系统模式设定; 晶振频率 = 16MHz */
# define TIMER0_VALUE 0x7fff // 定时器 0 计时 49ms
# define TIMER1_VALUE 300 // 定时器 1 计数值1.5ms
# define TMOD_MODE_WORD 0x11 // 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位定时器
# define TCON_MODE_WORD 0x55 // TF0(T0溢出中断请求) -- TF1(T1溢出中断请求) --
// IE1(外部中1断请求) IT1(触发方式 1-边沿) IE0(外部中0断请求) IT0(触发方式 1-边沿)
# define IE_MODE_WORD 0x8e // EA(1-总中断开)? -- ET2(定时器2中断) ES(串行中断)
// ET1(定时器1中断) EX1(外部中断1) ET0(定时器0中断) EX0(外部中断0)
# define IP_MODE_WORD 0x01 // -- -- -- PS PT1 PX1 PT0 PX0
# define PCON_MODE_WORD 0x00 // SMOD -- -- -- GF1 GF0 PD IDL;
# define SCON_MODE_WORD 0x90 // SM0 SM1 SM2 REN TB8 RB8 TI RI REN:接收容许
// 0 0 方式0 同步移位寄存器 Fosc/12
// 0 1 方式1 10位异步收发 由定时器控制
sfr PMR=0XC4; // 1 0 方式2 11位异步收发 Fosc/32 Fosc/64
// 1 1 方式3 11位异步收发 由定时器控制
# define EEPROM_CONTROL_WORD 0 // 93c66,byte mode
# define Delay_Time 1
# define System_Mode_Menu1 0
# define Single_Color_Menu1 1
# define Red 0
# define Yellow 1
# define Green 2
# define Cyan 3
# define Blue 4
# define Purple 5
# define White 6
# define Black 7
# define Orange 8
# define PINk 9
# define R 0
# define Y 1
# define G 2
# define C 3
# define B 4
# define P 5
# define W 6
# define D 7
# define O 8
# define F 9
# define Menu1_Max 14 //2006-09-22更改 由12更改为14
# define Menu2_Max 5
# define Auto_Step1_Max 46-1
# define Auto_Step2_Max 7-1
# define Begin_Lamp 1-1
#define unchar unsigned char
#define unint unsigned int
#define unlong unsigned long
#define DELAY_10S 200 //修改于2006-09-22
#define DELAY_30S 600 //修改于2006-09-22
uint Delaywb ; //修改于2006-09-22
uchar code Menu1_Tab[ ][16] =
{
"1)System Mode ", //0
" Set < >",
"2)Single Color ", //1
" Set < >",
"3)Flow1(FF) ", //2
" Set < >",
"4)Flow2(Rew) ", //3
" Set < >",
"5)Flow3(FF/Rew) ", //4
" Set < >",
"6)M.Color Flow1 ", //5
" Set < >",
"7)M.Color Flow2 ", //6
" Set < >",
"8)Color Chase ", //7
" Set < >",
"9)Fade Chase ", //8
" Set < >",
"10)Fade Change", //9
" Set < >",
"11)Auto Run1 ", //10
" < >",
//11
"12)Auto Run2 ",
" < >",
"13)Custom Run ", //12
" ",
" Client mode1 ", //增加 26 2006-09-22
" W 30S-->B 10S ", // 27
" Client mode2 ", //增加 28 2006-09-22
" B 30S-->W 10S ", // 29
" SRC-WASHER-100 ", // 30
" Ver:2.3 ", // 31
};
unchar code Menu2_Tab[ ][16] =
{
"Sort: ",
" ",
"Speed: ",
" ",
"Flash Freq: ",
" ",
"ixels/Step ",
" ",
"Save: ",
" Yes No",
" Lamp Amount ",
" ",
" Start Address ",
" ",
" Write Address ",
" Yes No",
"Repeat: ",
" ",
" Save... ",
" ",
" Erase... ",
" ",
};
unchar code Color_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 ",
};
unchar code Color_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
};
unchar code Autorun_Table1[ ][5] = {
{ 2,44,16, 0, 1}, //2 ff
{ 3,44,16, 0, 1}, //3 rew
{ 4,44,16, 0, 1}, //4 ff/rew
{ 5, 9,14, 0, 4}, //5 M.Flow1
{ 5,10,14, 0, 4}, //6 M.Flow1
{ 5,12,14, 0, 4}, //7 M.Flow1
{ 5,13,14, 0, 4}, //8 M.Flow1
{ 5,14,14, 0, 4}, //9 M.Flow1
{ 5,16,14, 0, 4}, //10 M.Flow1
{ 5,17,14, 0, 4}, //11 M.Flow1
{ 5,16,14, 0, 4}, //12 M.Flow1
{ 5,20,14, 0, 4}, //13 M.Flow1
{ 5,21,14, 0, 4}, //14 M.Flow1
{ 5,22,14, 0, 4}, //15 M.Flow1
{ 5,23,14, 0, 4}, //16 M.Flow1
{ 5,25,14, 0, 4}, //17 M.Flow1
{ 5,30,14, 0, 4}, //18 M.Flow1
{ 5,45,14, 0, 1}, //19 M.Flow1
{ 6, 9,14, 0, 4}, //20 M.Flow2
{ 6,10,14, 0, 4}, //21 M.Flow2
{ 6,12,14, 0, 4}, //22 M.Flow2
{ 6,13,14, 0, 4}, //23 M.Flow2
{ 6,14,14, 0, 4}, //24 M.Flow2
{ 6,16,14, 0, 4}, //25 M.Flow2
{ 6,17,14, 0, 4}, //26 M.Flow2
{ 6,16,14, 0, 4}, //27 M.Flow2
{ 6,20,14, 0, 4}, //28 M.Flow2
{ 6,21,14, 0, 4}, //29 M.Flow2
{ 6,22,14, 0, 4}, //30 M.Flow2
{ 6,23,14, 0, 4}, //31 M.Flow2
{ 6,25,14, 0, 4}, //32 M.Flow2
{ 6,30,14, 0, 4}, //33 M.Flow2
{ 6,45,14, 0, 1}, //34 M.Flow2
{ 7,10,11, 0, 4}, //35 M.Chase
{ 7,12,11 , 0, 4}, //36 M.
{ 7,13,11, 0, 4}, //37 M.
{ 7,14,11, 0, 4}, //38 M.
{ 7,16,11, 0, 4}, //39 M.
{ 7,17,11, 0, 4}, //40 M.
{ 8,10,12, 0, 4}, //41 Color.Chase
{ 8,10,12, 0, 4}, //42 Color.Chase
{ 8,10,12, 0, 4}, //43 Color.Chase
{ 9,44, 8, 0, 5}, //44
{ 9,49, 16, 0, 5}, //45 50.RDGDBDPD fade
{ 1,44,12, 0, 2}, //46
{ 1,44,12, 5, 2}, //47
};
unchar code Autorun_Table2[ ][5] = {
{ 1, 44,16, 0, 2}, //1 45.RGYBPCWD single
{ 2, 44,16, 0, 0}, //3 ff
{ 9, 41,16, 0, 5}, //4 fade
{ 3, 44,16, 0, 0}, //5 rew
{ 1, 44,16, 5, 2}, //2 45.RGYBPCWD single
{ 9, 49,16, 0, 5}, //6 50.RDGDBDPD fade
{ 4, 44,16, 0, 0}, //7 ff/rew
};
union User_Data_Type
{
unint Word;
struct{unchar H; unchar L;}Bytes;
};
unchar Press_Time,Dmx_Timer;
unchar xdata Work_Data_Buff[512];
unchar xdata Custom_Run[30][5];
unchar mode,mode1,mode2;
unchar data Set_Num[5];
unchar Menu1,Menu2,Menu3,Bk_Menu1;
unchar Frequence,Frequence_Count,Speed;
unchar Fade;
unchar Run_Speed;
unint Run_Time;
unchar Current_Lamp,Current_Lamp1,Color_Sort;
unchar idata Menu[15][5]={
{31, 1, 0, 0, 0}, //1 amount address
{ 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}, //11 auto
{17, 0, 0, 3, 0}, //12
{18, 0, 0, 3, 0}, //13
};
unchar Temp_Buff;
unchar Amount;
unchar Color_X,Color_X1,Color_X3;
unchar Current_Color,Current_Color1;
unchar Pixels;
unchar idata Color_Table2[32];
unchar Fade_Adj,Fade_Adj1,Fade_Time;
unchar Eeprom_Control_Word_Rg;
unchar Auto_Step1,Auto_Step2,Auto_Reapeat,Circle,Repeat;
unchar Amount,Address;
unchar Bk_Color_Sort,Bk_Pixels;
unchar R_data1,G_data1,B_data1;
unchar R_data2,G_data2,B_data2;
unchar Pixels_Group;
unchar Save_Pc;
unchar Play_Pc,Bk_Play_Pc;
unchar Temp_Color2,Temp_Color1;
sbit Sw_Key1 = P2^4;
sbit Sw_Key2 = P2^5;
sbit Sw_Key3 = P2^6;
sbit Sw_Key4 = P2^7;
sbit Sw_Key5 = P2^3;
sbit LCD_RS_Cs = P2^0;
sbit Lcd_RW_Cs = P2^1;
sbit Lcd_OE_Cs = P2^2;
//sbit Lcd_Lamp = P1^0;
sbit Eeprom_DI_Fg = P3^5;
sbit Eeprom_DO_Fg = P3^5;
//sbit Eeprom_CS_Fg = P3^4;
sbit Eeprom_CS_Fg = P3^6;
sbit Eeprom_CK_Fg = P3^7;
bit Key1_Flag;
bit Key2_Flag;
bit Key3_Flag;
bit Key4_Flag;
bit Key5_Flag;
bit Key6_Flag;
bit Key7_Flag; //此为增加 2006-09-22
bit Key8_Flag;
bit First_Press_Flag;
bit Direction_Flag;
bit Adj_Direction_Flag,Adj_Direction_Flag1;
bit Flash_On;
bit Send_Data_Enable_Flag;
/* 函数声明 */
void Work_Buff_Clr ( void );
void Delay_10_uS(void);
void Delay_N_mS( unint n_milisecond); /* n mS delay */
void Lcd_Initialize( void );
void Lcd_Menu1_DSP( unchar Item_Rg );
void Lcd_Menu2_Dsp( unchar Item_Rg );
void Lcd_Write_Data( unchar Data_Rg );
void Lcd_Number_Dsp( void );
void Lcd_Color_Dsp( unchar Item_Rg );
void Hex_To_Ascii( unint Data_Rg );
void Color_Set(unint Ch1,unint Ch2,unchar Color);
unchar Read_Table(unchar i,unchar j);
void Write_Table(unchar i,unchar j,unchar adj);
bit Eeprom_Check_Busy( void );
void EE_Write_Start_Bit( void);
unchar EE_Read_Code_Bit( void );
void EE_Write_Code_Bit( unchar Code_Rg, unchar Bit_Count_Rg );
void Eeprom_Write_Enable( void );
unchar Eeprom_Read_Data( unint Address_Rg );
void Eeprom_Write_Data( unint Address_Rg, unint Value_Rg );
void Auto_Run(void);
void Fade_Color2Color(void); //unchar color1,color2);
void Hand_Time(void);
void Send_Dmx_Data(void);
void Send_blue (void); //增加于2006-09-22
void Send_write(void);
/*==================================================================================*/
void Int0 (void) interrupt 0 using 0
{
}
void Int1(void) interrupt 2 using 1
{
}
/*==================================================================================*/
// Timer0 定时中断服务程序; 49ms 中断一次
void Timer0(void) interrupt 1 using 2
{
// unint i,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; // every 0.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; // very 0.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; // every 0.25s
}
}
if((Sw_Key3 == 0)&&( Sw_Key1 == 0)) // double key save key
{
Press_Time++;
if ( Press_Time==9) // >100ms
{
Key5_Flag =1;
}
}
if((Sw_Key4 == 0)&&( Sw_Key1 == 0)) // double key erase key
{
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 中断一次
void Timer1(void) interrupt 3 using 1
{
Run_Time ++;
Hand_Time();
// Auto_Run();
}
/*=================================================================================*/
void Serial(void) interrupt 4 using 3
{
}
/*==================================================================================*/
// 主程序
void main( void )
{
unchar i,j,l;
// unint * x;
PMR = 0x41; // Use 1k SRAM
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();
// Eeprom initialization----------------------------------------
Write_Table(1,3,3); //single color set pixels 4
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) //auto run repeat
Write_Table(i,0,0);
}
for ( i=10;i<11;i++ )
{
j = Read_Table(i,1);
if(j>15) //auto run speed
Write_Table(i,1,0);
}
j = Read_Table(14,0); // menu1 remmber
if(j>12)
Write_Table(14,0,1);
Menu1=Read_Table(14,0);
Lcd_Menu1_Dsp(15); //start PICture // 修改:由13改为15 2006-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) //mode key
{
Key1_Flag =0;
Lcd_Menu1_Dsp(Menu1);
Menu2 = 0xff;
First_Press_Flag = 0;
}
//---------------------------------------------
if (Key2_Flag) //function key
{
Key2_Flag =0;
switch ( Menu1)
{
case 0: // system
Menu2++;
// if(Menu2 < 5)
Menu2 = 5;
// if(Menu2>7)
// Menu2 = 4;
switch ( Menu2 )
{
case 5 : //Set Amount
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;
case 6 : // set address
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;
case 7 : // Write address
Lcd_Menu2_Dsp(Menu2);
break;
default:
break;
}
break;
case 1: // Single color
Menu2++;
if ( Menu2 > 2)
Menu2 = 0;
switch ( Menu2 )
{
case 0 : //Color Sort
Color_Sort = Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Lcd_Color_Dsp(Color_Sort);
break;
case 1 : //Speed
Run_Speed = Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(16-Run_Speed);
Lcd_Number_Dsp();
break;
case 2 : //Frequence
Frequence = Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
break;
default:
break;
}
break;
case 2 : //Flow1 顺
case 3 : //Flow2 反
case 4 : //Flow3 来回
case 5 : //Multicolor 顺
case 6 : //Multicolor 反
case 7 : //two color chase
case 8 : //two color fade chase
case 9 : //Fade change
Menu2++;
if ( Menu2 > 3)
Menu2 = 0;
switch ( Menu2 )
{
case 0 : //Color Sort
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;
case 1 : //Speed
Run_Speed = Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(16-Run_Speed);
Lcd_Number_Dsp();
break;
case 2 : //Frequence
Frequence = Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
break;
case 3 : //Pixel/Step
Pixels = Read_Table(Menu1,Menu2);
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Pixels+1);
Lcd_Number_Dsp();
break;
default:
break;
}
break;
case 10 : //Auto Run1
case 11 : //Auto Run2
if(Menu2 < 8)
Menu2 = 8;
if(Menu2 == 9)
Menu2 = 8;
else
Menu2 =9;
switch ( Menu2 )
{
case 8 :
Repeat = Read_Table(Menu1,0); //auto run repeat
Lcd_Menu2_Dsp(Menu2);
Hex_To_Ascii(Repeat + 1);
Lcd_Number_Dsp();
break;
case 9 :
Circle = Read_Table(Menu1,1); //Auto run speed
Lcd_Menu2_Dsp(1);
Hex_To_Ascii(16-Circle);
Lcd_Number_Dsp();
break;
default:
break;
}
break;
//以下为增加的客户所需模式
case 13: //蓝色亮30秒后,红色亮10S
Key7_Flag=1;
break;
case 14: //红色亮30S后,蓝色亮10S
Key8_Flag=1;
break;
default:
break;
}
}
//-------------------------------------
if ( Key3_Flag) //up key
{
Key3_Flag =0;
switch( Menu2 )
{
case 0 : //color sort
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;
case 1 : //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;
case 2 : //flash frequence
Frequence = Read_Table(Menu1,Menu2);
Frequence++;
if ( Frequence >5)
{
Frequence =0;
}
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Frequence);
break;
case 3 : //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;
case 5 : //Lamp Amount
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;
case 6 : //Start Address
Address = Read_Table(Menu1,1);
Address++;
if ( Address >200)
{
Address = 1;
}
Hex_To_Ascii(Address);
Lcd_Number_Dsp();
Write_Table(Menu1,1,Address);
break;
case 7 : //写地址
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;
case 8 : //auto run repeat
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;
case 9 : //auto run speed
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;
case 0xff:
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) //down key
{
Key4_Flag =0;
switch( Menu2 )
{
case 0 : //color sort
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;
case 1 : //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;
case 2 : //flash frequence
Frequence = Read_Table(Menu1,Menu2);
Frequence--;
if ( Frequence == 0xff)
{
Frequence = 5;
}
Hex_To_Ascii(Frequence);
Lcd_Number_Dsp();
Write_Table(Menu1,Menu2,Frequence);
break;
case 3 : //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;
case 5 : //Lamp Amount
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;
case 6 : //Start Address
Address = Read_Table(Menu1,1);
Address--;
if ( Address == 0)
{
Address = 200;
}
Hex_To_Ascii(Address);
Lcd_Number_Dsp();
Write_Table(Menu1,1,Address);
break;
case 8 : //auto run repeat
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;
case 9 : //auto run speed
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;
case 0xff:
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) //save key
{
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) //erase key
{
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<ixels+1;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 ) //auto ran1
{
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;
}
}
}
}
}
void Auto_Run(void)
{
unchar i,j,k;
i = Current_Lamp + Pixels;
if( i > Amount )
i = Amount;
switch ( Bk_Menu1)
{
case 1 :
Pixels_Group = 2;
Fade = 0xff; //单色
Color_Set(0,31,Current_Color);
Dmx_Timer = 8;
Send_Dmx_Data();
break;
case 2 : //Flow1 顺
Pixels_Group = 0;
Fade = 0xff;
Color_Set(Begin_Lamp + Current_Lamp,i + Begin_Lamp,Current_Color);
Dmx_Timer = 8;
Send_Dmx_Data();
break;
case 3 : //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;
case 4 : //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;
case 5 : //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;
case 6 : //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;
case 7 : // two color chase
Pixels_Group = 1;
Fade = 0xff;
i=0;
while(i<32)
{
j = Current_Lamp1%2;
for(k=0;k<ixels+1;k++)
{
Color_Set(i,i,Color_Table[Color_Sort][j]);
i++;
}
for(k=0;k<ixels+1;k++)
{
Color_Set(i,i,Color_Table[Color_Sort][1-j]);
i++;
}
}
_nop_();
Dmx_Timer = 8;
Send_Dmx_Data();
break;
case 8 : // two color Fade chase
Pixels_Group = 1;
Fade = 0xff;
i=0;
while(i<32)
{
j = Current_Lamp1%2;
Fade=Fade_Adj*8;
for(k=0;k<ixels+1;k++)
{
Color_Set(i,i,Color_Table[Color_Sort][0]);
i++;
}
Fade=0xFF-Fade_Adj*8;
for(k=0;k<ixels+1;k++)
{
Color_Set(i,i,Color_Table[Color_Sort][1]);
i++;
}
}
_nop_();
Dmx_Timer = 8;
Send_Dmx_Data();
break;
case 9 : //fade change
Pixels_Group = 2;
Fade_Time++;
if(Fade_Time > Run_Speed)
{
Fade_Time = 0;
if(R_data1 > R_data2)
R_data1--;
if(R_data1 < R_data2)
R_data1++;
if(G_data1 > G_data2)
G_data1--;
if(G_data1 < G_data2)
G_data1++;
if(B_data1 > B_data2)
B_data1--;
if(B_data1 < B_data2)
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 ) //auto ran1
{
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_();
}
void Hand_Time(void)
{
unchar i;
_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 ) //auto ran1
{
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;
}
}
}
}
void Fade_Color2Color(void) //unchar color1,color2)
{
switch ( Temp_Color1)
{
case Red :
R_data1 = 0xff;
G_data1 = 0x00;
B_data1 = 0x00;
break;
case Green :
R_data1 = 0x00;
G_data1 = 0xff;
B_data1 = 0x00;
break;
case Yellow :
R_data1 = 0xff;
G_data1 = 0xff;
B_data1 = 0x00;
break;
case Blue :
R_data1 = 0x00;
G_data1 = 0x00;
B_data1 = 0xff;
break;
case Purple :
R_data1 = 0xff;
G_data1 = 0x00;
B_data1 = 0xff;
break;
case Cyan :
R_data1 = 0x00;
G_data1 = 0xff;
B_data1 = 0xff;
break;
case White :
R_data1 = 0xff;
G_data1 = 0xff;
B_data1 = 0xff;
break;
case Black :
R_data1 = 0x00;
G_data1 = 0x00;
B_data1 = 0x00;
break;
case Orange :
R_data1 = 0xff;
G_data1 = 125;
B_data1 = 0x00;
break;
case Pink :
R_data1 = 0xff;
G_data1 = 0;
B_data1 = 125;
break;
default:
break;
}
switch ( Temp_Color2) //color2)
{
case Red :
R_data2 = 0xff;
G_data2 = 0x00;
B_data2 = 0x00;
break;
case Green :
R_data2 = 0x00;
G_data2 = 0xff;
B_data2 = 0x00;
break;
case Yellow :
R_data2 = 0xff;
G_data2 = 0xff;
B_data2 = 0x00;
break;
case Blue :
R_data2 = 0x00;
G_data2 = 0x00;
B_data2 = 0xff;
break;
case Purple :
R_data2 = 0xff;
G_data2 = 0x00;
B_data2 = 0xff;
break;
case Cyan :
R_data2 = 0x00;
G_data2 = 0xff;
B_data2 = 0xff;
break;
case White :
R_data2 = 0xff;
G_data2 = 0xff;
B_data2 = 0xff;
break;
case Black :
R_data2 = 0x00;
G_data2 = 0x00;
B_data2 = 0x00;
break;
case Orange :
R_data2 = 0xff;
G_data2 = 125;
B_data2 = 0x00;
break;
case Pink :
R_data2 = 0xff;
G_data2 = 0;
B_data2 = 125;
break;
default:
break;
}
}
void Send_Dmx_Data(void)
{
unint i,j;
Send_Data_Enable_Flag = 0;
Dmx_Timer ++;
// if( Bk_Menu1 == 9)
// Dmx_Timer = 9;
if ( Dmx_Timer > 2)
{
Dmx_Timer = 0; //send 672 data need 38 mS
if( Flash_On )
{
Frequence_Count ++;
if(Frequence_Count > (5 - Frequence))
{
Frequence_Count = 0;
Flash_On = 0;
}
if(!Frequence)
{
Flash_On = 1;
}
switch (Pixels_Group)
{
case 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<600 ;j++) //576
{
SBUF = Work_Data_Buff[j];
while( ! TI );
TI = 0;
}
break;
case 1 :
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;
case 2 :
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);
}
}
/*====================================================================================*/
unchar Read_Table(unchar i,unchar j)
{
unchar temp2;
unint temp1;
EA =0;
temp1 = i*5+j;
temp2 = Eeprom_Read_Data( temp1 );
EA = 1;
// temp2 = Menu[j];
return temp2;
}
void Write_Table(unchar i,unchar j,unchar adj)
{
//Menu[j] = adj;
unint temp1;
unchar temp2;
EA=0;
temp1 = i*5+j;
temp2 = adj;
Eeprom_Write_Data( temp1, temp2 );
EA=1;
}
void Work_Buff_Clr ( void )
{
unint i;
for ( i=0;i<512;i++)
{
Work_Data_Buff = 0x00;
}
}
void Color_Set(unint Ch1,unint Ch2,unchar Color) //参数: 起始通道,结束通道,颜色
{
unchar R_data,G_data,B_data;
unint i;
switch ( Color)
{
case Red :
R_data = Fade;
G_data = 0x00;
B_data = 0x00;
break;
case Green :
R_data = 0x00;
G_data = Fade;
B_data = 0x00;
break;
case Yellow :
R_data = Fade;
G_data = Fade;
B_data = 0x00;
break;
case Blue :
R_data = 0x00;
G_data = 0x00;
B_data = Fade;
break;
case Purple :
R_data = Fade;
G_data = 0x00;
B_data = Fade;
break;
case Cyan :
R_data = 0x00;
G_data = Fade;
B_data = Fade;
break;
case White :
R_data = Fade;
G_data = Fade;
B_data = Fade;
break;
case Black :
R_data = 0x00;
G_data = 0x00;
B_data = 0x00;
break;
case Orange :
R_data = 0xff;
G_data = 125;
B_data = 0x00;
break;
case Pink :
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_();
}
/*----------------------------------------------------------------------------------*/
void Delay_10_uS(void)
{
char i=30;
while(i--);
}
void Delay_N_mS( unint n_milisecond) /* n mS delay */
{
unchar i;
while(n_milisecond--)
{
// i=165; // nomal dealy
i=165*3; //for w77e58
while(i--);
}
}
/*==================================================================================*/
void Lcd_Initialize( void )
{
// RS = 0, 写命令码操作
Lcd_RS_Cs = 0;
// RW = 0, 写操作
Lcd_RW_Cs = 0;
// 功能设定命令码( Function Set )
// D/L(bit4) = 1: 8bit 资料接口
// N(bit3) = 1: 2 行显示
// F(bit2) = 0: 5 x 7 dots
Lcd_Write_Data( 0x38 );
Delay_N_mS(1);
// 功能设定命令码( Function Set )
// D/L(bit4) = 1: 8bit 资料接口
// N(bit3) = 1: 2 行显示
// F(bit2) = 0: 5 x 7 dots
Lcd_Write_Data( 0x38 );
Delay_N_mS(1);
// 功能设定命令码( Function Set )
// D/L(bit4) = 1: 8bit 资料接口
// N(bit3) = 1: 2 行显示
// F(bit2) = 0: 5 x 7 dots
Lcd_Write_Data( 0x38 );
Delay_N_mS(1);
// 显示开关命令码( Display On/Off Control )
// 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);
}
/*==================================================================================*/
// LCD menu1显示
void Lcd_Menu1_Dsp( unchar Item_Rg )
{
unchar i;
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();
/*==================================================================================*/
// LCD menu2显示
void Lcd_Menu2_Dsp( unchar Item_Rg )
{
unchar i;
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);
}
}
void Lcd_Color_Dsp( unchar Item_Rg )
{
unchar i;
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 写操作动作
void Lcd_Write_Data( unchar Data_Rg )
{
Lcd_OE_Cs = 1;
_nop_();
_nop_();
_nop_();
_nop_();
P0 = Data_Rg;
_nop_();
_nop_();
_nop_();
_nop_();
Lcd_OE_Cs = 0;
}
/*=======================================================================================*/
void Lcd_Number_Dsp( void )
{
unchar i;
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);
}
}
//=========================================================================================
void Hex_To_Ascii( unint Data_Rg )
{
unchar i;
unchar Hex4Bcd_Buf[5];
// Hex To BCD
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;
}
// BCD To ASCII
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. 地址码.
void Eeprom_Write_Data( unint Address_Rg, unint Value_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 指定地址读取资料.
// 传入参数: 地址码.
// 传回参数: 资料码.
unchar Eeprom_Read_Data( unint Address_Rg )
{
unchar Read_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;
return Read_Data_Buf;
}
/*==================================================================================*/
// 功 能: EEPROM 抹除及写致能命令.
void Eeprom_Write_Enable( void )
{
unchar i;
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 < Delay_Time; i ++ )
;
}
/*==================================================================================*/
void EE_Write_Code_Bit( unchar Code_Rg, unchar Bit_Count_Rg )
{
unchar i;
while( Bit_Count_Rg -- )
{
Eeprom_DI_Fg = ( Code_Rg & 0x80 ) ? 1 : 0;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_CK_Fg = 1;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_CK_Fg = 0;
for( i = 0; i < Delay_Time; i ++ )
;
Code_Rg <<= 1;
}
}
/*==================================================================================*/
// 功 能: 从 EEPROM 内部读取 1 Byte 的资料.
// 传回参数: 资料码.
unchar EE_Read_Code_Bit( void )
{
unchar i;
unchar m;
unchar Data_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 < Delay_Time; m ++ )
;
Eeprom_CK_Fg = 0;
for( m = 0; m < Delay_Time; m ++ )
;
if( Eeprom_DO_Fg )
{
Data_Rg |= 0x01;
}
}
return Data_Rg;
}
/*==================================================================================*/
// 功 能: 写起始位元到 EEPROM
void EE_Write_Start_Bit( void )
{
unchar i;
Eeprom_CS_Fg = 1;
Eeprom_CK_Fg = 0;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_DI_Fg = 0;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_CK_Fg = 1;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_CK_Fg = 0;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_DI_Fg = 1;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_CK_Fg = 1;
for( i = 0; i < Delay_Time; i ++ )
;
Eeprom_CK_Fg = 0;
for( i = 0; i < Delay_Time; i ++ )
;
}
/*==================================================================================*/
// 功 能: 检测 EEPROM "忙".
bit Eeprom_Check_Busy( void )
{
unint i;
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;
}
}
return i ? 0 : 1;
}
/*==================================================================================*/
void Send_write (void)
{
uchar temp_write;
TB8 = 0;
SBUF = 0x00;
while( ! TI );
TI = 0;
TB8= 1;
SBUF = 0x00;
while( ! TI );
TI = 0;
for(temp_write=0; temp_write<600 ;temp_write++)
{
SBUF = 0xFF;
while( ! TI );
TI = 0;
}
}
/*********************************************************/
void Send_blue (void)
{
uchar temp_blue0, temp_blue1;
TB8 = 0;
SBUF = 0x00;
while( ! TI );
TI = 0;
TB8= 1;
SBUF = 0x00;
while( ! TI );
TI = 0;
for(temp_blue1=0; temp_blue1<200; temp_blue1++
{
for(temp_blue0=0; temp_blue0<3; ;temp_blue0++)
{
if(temp_blue==2)
{
SBUF = 0xFF;
while( ! TI );
TI = 0;
}
else
{
SBUF = 0xFF;
while( ! TI );
TI = 0;
}
}
}
}