#include "reg52.h"
#include "pio.h"
#include "vfd.h"
/*************************************************************************/
void Delay(BYTE time)
{
BYTE i;
for(i=0;i<time;i++);
}
/*************************************************************************/
void Write_VFD_Data(BYTE AData)
{
BYTE i;
for(i = 0;i <8; i++)
{
PT6311_CLK=0;
PT6311_DATA=AData&0x01;
AData=AData>>1;
PT6311_CLK=1;
}
PT6311_DATA=1;
}
/*************************************************************************/
WORD VFD_Read_Key(void)
{
unsigned char j;
unsigned char i;
BYTE keybuf[2];
BYTE Bit1;
keybuf[0]=0x00;
keybuf[1]=0x00;
PT6311_STB=0;
Delay(1);
PT6311_DATA=1;
PT6311_CLK=1;
Write_VFD_Data(vfd_read_cmd);
// Delay(1); /*release data line */
for(j=0;j<2;j++)
{
for (i=0;i< 8;i++)
{
PT6311_CLK=0;
Delay(1);
PT6311_CLK=1;
if(PT6311_DATA==1)
keybuf[j] |= (0x01<<i);
Delay(1);
}
}
PT6311_STB=1;
PT6311_DATA=1;
PT6311_CLK=1;
Bit1=0;
if((keybuf[0]==0)&&(keybuf[1]==0))
{
if(KeyDown)
{
KeyDown=0;
return(Key_Value);
}
else
return(0);
}
for(j=0;j<2;j++)
{
for (i=0;i< 8;i++)
{
if(keybuf[j]&(0x01<<i)) Bit1++;
}
}
if(Bit1>1) return(0);
Key_Value=(keybuf[1]<<8)+keybuf[0];
KeyDown=1;
return(0);
}
/*************************************************************************/
void VFD_Display()
{
unsigned char i;
PT6311_STB=0;
Delay(1);
PT6311_DATA=1;
PT6311_CLK=1;
Write_VFD_Data(vfd_dismod_cmd);
PT6311_STB=1;
Delay(1);
PT6311_STB=0;
Delay(1);
Write_VFD_Data(vfd_writedata_cmd);
PT6311_STB=1;
Delay(1);
PT6311_STB=0;
Delay(1);
Write_VFD_Data(vfd_first_address);
if(power_onoff==1)
{
for(i=0;i<16;i++)
{
Write_VFD_Data(vfdbuf[i*2]);
Write_VFD_Data(vfdbuf[i*2+1]);
Write_VFD_Data(0x00);
}
}
else
{
for(i=0;i<16;i++)
{
Write_VFD_Data(0x00);
Write_VFD_Data(0x00);
Write_VFD_Data(0x00);
}
}
PT6311_STB=1;
Delay(1);
PT6311_STB=0;
Delay(1);
Write_VFD_Data(vfd_control_cmd);
//Write_VFD_Data(vfd_control_off);
PT6311_STB=1;
Delay(1);
PT6311_DATA=1;
PT6311_CLK=1;
}
/*************************************************************************/
void DisplayUpdate()
{
BYTE i;
if(power_onoff==0) return;
if(Music_Mode)
{
MusicModeUpDate();
return;
}
FlashDidplsy();
if(Display_Update_Delay>0) return;
FlashBitNumber=0;
FlashSegNumber=0;
Flash_Display=0;
memo_off;
Memo_Save=0;
eq_mode_flag=0;
// Display_Mode=7;
for(i=0;i<16;i++)
{
switch(Display_Mode)
{
case 1:
for(i=0;i<15;i++)
{
vfdbuf[i*2]=LEVEL_Mod0[EQLevel[i]][1];
vfdbuf[i*2+1]=LEVEL_Mod0[EQLevel[i]][0];
}
break;
case 2:
for(i=0;i<15;i++)
{
vfdbuf[i*2]=LEVEL_Mod1[EQLevel[i]][1];
vfdbuf[i*2+1]=LEVEL_Mod1[EQLevel[i]][0];
}
break;
case 3:
for(i=0;i<15;i++)
{
vfdbuf[i*2]=LEVEL_Mod2[EQLevel[i]][1];
vfdbuf[i*2+1]=LEVEL_Mod2[EQLevel[i]][0];
}
break;
case 4:
for(i=0;i<15;i++)
{
vfdbuf[i*2]=LEVEL_Mod3[EQLevel[i]][1];
vfdbuf[i*2+1]=LEVEL_Mod3[EQLevel[i]][0];
}
break;
case 5:
for(i=0;i<15;i++)
{
vfdbuf[i*2]=LEVEL_Mod0[EQLevel[i]][1]|LEVEL_Mod1[EQLevel_Bak[i]][1];
vfdbuf[i*2+1]=LEVEL_Mod0[EQLevel[i]][0]|LEVEL_Mod1[EQLevel_Bak[i]][0];
//vfdbuf[i*2]=LEVEL_Mod1[EQLevel_Bak[i]][1];
//vfdbuf[i*2+1]=LEVEL_Mod1[EQLevel_Bak[i]][0];
if(Display_Down_Delay==0)
{
if(EQLevel_Bak[i]>EQLevel[i]) EQLevel_Bak[i]--;
}
}
if(Display_Down_Delay==0)
Display_Down_Delay=30;
break;
case 6:
for(i=0;i<15;i++)
{
if(EQLevel[i]!=0)
{
vfdbuf[i*2]=LEVEL_Mod1[EQLevel[i]+1][1]|LEVEL_Mod1[EQLevel_Bak[i]][1];
vfdbuf[i*2+1]=LEVEL_Mod1[EQLevel[i]+1][0]|LEVEL_Mod1[EQLevel_Bak[i]][0];
}
else
{
vfdbuf[i*2]=0;
vfdbuf[i*2+1]=0;
}
if(Display_Down_Delay==0)
{
if(EQLevel_Bak[i]>EQLevel[i]) EQLevel_Bak[i]--;
}
}
if(Display_Down_Delay==0)
Display_Down_Delay=30;
break;
case 7:
for(i=0;i<15;i++)
{
vfdbuf[i*2]=LEVEL_Mod2[EQLevel[i]][1]|LEVEL_Mod1[EQLevel_Bak[i]][1];
vfdbuf[i*2+1]=LEVEL_Mod2[EQLevel[i]][0]|LEVEL_Mod1[EQLevel_Bak[i]][0];
if(Display_Down_Delay==0)
{
if(EQLevel_Bak[i]>0) EQLevel_Bak[i]--;
}
}
if(Display_Down_Delay==0)
Display_Down_Delay=30;
break;
default:
break;
}
}
}
/*************************************************************************/
void MusicModeUpDate()
{
BYTE i;
i=14-Bit_Number;
if(Display_Down_Delay>0) return;
if(Bit_Number==0)
{
Display_Update_Delay=150;
Music_Mode=0;
return;
}
if(Display_Level>EQLevel[i])
Display_Level--;
vfdbuf[i*2]=LEVEL_Mod1[Display_Level][1];
vfdbuf[i*2+1]=LEVEL_Mod1[Display_Level][0];
Display_Down_Delay=4;
if(Display_Level>EQLevel[i]) return;
if(Bit_Number>0)
Bit_Number--;
Display_Level=13;
}
/*************************************************************************/
void FlashDidplsy()
{
bit BitData;
if(Flash_Display==0) return;
if(Flash_Delay>0) return;
Flash_Delay=6;
if(Memo_Save==1)
{
Memo_Save_flag=~Memo_Save_flag;
if(Memo_Save_flag==1)
memo_on;
else
memo_off;
}
else
memo_off;
switch(FlashBitNumber)
{
case 1:
if(FlashSegNumber>8)
{
BitData=(vfdbuf[1]>>(FlashSegNumber-9))&0x01;
vfdbuf[1]=vfdbuf[1]&(~(0x01<<(FlashSegNumber-9)));
BitData=~BitData;
vfdbuf[1]=vfdbuf[1]|((BYTE)BitData<<(FlashSegNumber-9));
}
else
{
BitData=(vfdbuf[0]>>(FlashSegNumber-1))&0x01;
vfdbuf[0]=vfdbuf[0]&(~(0x01<<(FlashSegNumber-1)));
BitData=~BitData;
vfdbuf[0]=vfdbuf[0]|((BYTE)BitData<<(FlashSegNumber-1));
}
break;
case 2:
if(FlashSegNumber>8)
{
BitData=(vfdbuf[3]>>(FlashSegNumber-9))&0x01;
vfdbuf[3]=vfdbuf[3]&(~(0x01<<(FlashSegNumber-9)));
BitData=~BitData;
vfdbuf[3]=vfdbuf[3]|((BYTE)BitData<<(FlashSegNumber-9));
}
else
{
BitData=(vfdbuf[2]>>(FlashSegNumber-1))&0x01;
vfdbuf[2]=vfdbuf[2]&(~(0x01<<(FlashSegNumber-1)));
BitData=~BitData;
vfdbuf[2]=vfdbuf[2]|((BYTE)BitData<<(FlashSegNumber-1));
}
break;
case 3:
if(FlashSegNumber>8)
{
BitData=(vfdbuf[5]>>(FlashSegNumber-9))&0x01;
vfdbuf[5]=vfdbuf[5]&(~(0x01<<(FlashSegNumber-9)));
BitData=~BitData;
vfdbuf[5]=vfdbuf[5]|((BYTE)BitData<<(FlashSegNumber-9));
}
else
{
BitData=(vfdbuf[4]>>(FlashSegNumber-1))&0x01;
vfdbuf[4]=vfdbuf[4]&(~(0x01<<(FlashSegNumber-1)));
BitData=~BitData;
vfdbuf[4]=vfdbuf[4]|((BYTE)BitData<<(FlashSegNumber-1));
}
break;
case 4:
if(FlashSegNumber>8)
{
BitData=(vfdbuf[7]>>(FlashSegNumber-9))&0x01;
vfdbuf[7]=vfdbuf[7]&(~(0x01<<(FlashSegNumber-9)));
BitData=~BitData;
vfdbuf[7]=vfdbuf[7]|((BYTE)BitData<<(FlashSegNumber-9));
}
else
{
BitData=(vfdbuf[6]>>(FlashSegNumber-1))&0x01;
vfdbuf[6]=vfdbuf[6]&(~(0x01<<(FlashSegNumber-1)));
BitData=~BitData;
vfdbuf[6]=vfdbuf[6]|((BYTE)BitData<<(FlashSegNumber-1));
}
break;
case 5:
if(FlashSegNumber>8)
{
BitData=(vfdbuf[9]>>(FlashSegNumber-9))&0x01;
vfdbuf[9]=vfdbuf[9]&(~(0x01<<(FlashSegNumber-9)));
BitData=~BitData;
vfdbuf[9]=vfdbuf[9]|((BYTE)BitData<<(FlashSegNumber-9));
}
else
{
BitData=(vfdbuf[8]>>(FlashSegNumber-1))&0x01;
vfdbuf[8]=vfdbuf[8]&(~(0x01<<(FlashSegNumber-1)));
BitData=~BitData;
vfdbuf[8]=vfdbuf[8]|((BYTE)BitData<<(FlashSegNumber-1));
}
break;
case 6:
if(FlashSegNumber>8)
{