⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 substruct.h

📁 本代码详细说明了
💻 H
字号:
#define REG52
#define SUBSTRUCT
#ifndef REG52
 #include <reg52.h>
#endif

#define DELAY_RATE    10            //delay rate
#define DISPALY_MODE    0x02        //display mode set to 11seg 7dig
#define DATA_SET        0x44        //data set to 'write data to display'
#define DISPLAY_CONTROL 0x8F        //display control set to open (1/16)
//#define ADDRESS 0xC2
#define OFFSET 1                    //offset value,be used to get special bit value.

sbit DATA=P1^7;                 //51's 8pin
sbit CLK =P3^0;                 //51's 10pin
sbit STB =P3^1;                 //51's 11pin

#define Seg_B 0           //segment B's number.
#define Seg_F 1
#define Seg_C 2
#define Seg_E 3
#define Seg_A 4
#define Seg_D 5
#define Seg_G 6

//currently used segment address number
unsigned char loc; //{Seg_B----->Seg_G}

//currently segment's grid value
unsigned char grid_value[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 

//unsigned char offset=0x01;      //the based offset number,value(0,2,4,6,8) 

//The Segment's Address.
unsigned char address[]={0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,
                         0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5};

//                   grid      1   2     3    4   5    6    7    8
unsigned char TruesTable[]={0x02,0x04,0x20,0x10,0x08,0x40,0x01,0x80}; //I want's get the bit



/******************************Sub Function***********************************/                        
//---------Delay()-----------
/*** delay time ***/
void Delay(unsigned int i)
{
 unsigned int j;
 for (j=0;j<(i*DELAY_RATE);j++);
} 
/*** end delay ***/


//-------SendCommand()-------------
/***send a command to ET6201***/
void SendCommand(unsigned char cmd)  
{
 int i;
 STB=1;
 Delay(1);
 STB=0;
 for(i=0;i<8;i++)
 {
  CLK=0;
  if (cmd&(OFFSET<<i))
   DATA=1;
  else
   DATA=0;
  CLK=1;
 }
} 
/***end send***/


//----------SendAddress()-----------------
/***send a address to display memo***/
void SendAddress(unsigned char ads)
{
 int i;
 loc=ads;                          //save current location.
 STB=1;
 Delay(1);
 STB=0;
 for(i=0;i<8;i++)
 {
  CLK=0;
  if (address[ads]&(OFFSET<<i))
   DATA=1;
  else
   DATA=0;
  CLK=1;
 }
}
/***end address***/


//--------------InitSys()----------------
/***initializtion System***/ 
void InitSys()
{
 Delay(20000);
 Delay(20000);
 STB=1;
 CLK=1;
 DATA=1;
 SendCommand(DISPALY_MODE);
 SendCommand(DATA_SET);
 SendCommand(DISPLAY_CONTROL);
 SendAddress(Seg_B);    //0xC0
}
/***end initializtion***/


//------------Get_Grid()--------------------
/***get grid***/
unsigned char Get_Grid(unsigned char seg_flag)
{
 return grid_value[seg_flag];           //return seg_flag's gird value,(8 bit)
}
/***end get***/

///***save grid***/
//void Save_Grid(unsigned char seg_flag,unsigned char grid)
//{
// grid_value[seg_flag]=(grid|Get_Grid(seg_flag));
//} 
///***end save***/


//--------------SendData()----------------------
/*** Send Data to Display Memoru***/
void SendData(unsigned char ch)
{
 unsigned char i;
 grid_value[loc]=ch;                  //save currently segment's grid value              
 for(i=0;i<8;i++)
 {
  CLK=0;
  if (ch&(OFFSET<<i))
   DATA=1;
  else
   DATA=0;
  CLK=1;
 }
 Delay(1);
}
/***end send***/



//--------------ClearDisMemo()------------------
/***clear all bit***/
void ClearDisMemo() reentrant
{
 unsigned char k;
 for (k=0;k<22;k++)
 {
  SendCommand(address[k]);
  Delay(1);
  grid_value[k]=0x00;
  SendData(0x00);
 }
 loc=Seg_B;                          //Set Address Seg_B
}
/***end clear***/

//---------------OpenAvi()---------------------
/***start system's flash***/
/*
void OpenAvi()
{
 unsigned char k;
 while(1){
  for (k=0;k<8;k++)
  {
   SendCommand(address[k]);
   Delay(1);
   SendData(0xff);
   Delay(1000);
   SendData(0x00);
   Delay(1000);
  }
  
  }
  
 
} 
*/
             //        0    1    2    3    4    5    6    7    8    9  
unsigned char font[]={0x77,0x24,0x6b,0x6d,0x3c,0x5d,0x5f,0x64,0x7f,0x7d};
                          
unsigned char segment[]={0xC9,0xC1,0xC0,0xC3,0xC2,0xC5,0xC4,0xC7,0xC6,0xC8,0xCA,0xCB};
unsigned char data_grid[]=0;
unsigned char symbol[]={
  // radio,   prog,  rigth-:, total, left_:, bias,  vertical            
      0x97,   0x17,  0x07,   0x37,   0x27,   0x57,   0x77,
  // digtal,   dts,   key,  mikefen, pause,  play,  circle,   all
      0x80,   0x81,  0x82,   0x83,   0x84,   0x85,   0x86,   0x87,
  //   s1,    s2,     s3,     s4,     s5,     s6,     s7,     s8
      0xA0,  0xA1,   0xA2,   0xA3,   0xA4,   0xA5,   0xA6,   0xA7,
  //   s9,    s10,    s11,    s12,    mp3,    vcd,    cd,     dvd
      0xB0,  0xB1,   0xB2,   0xB3,   0xB4,   0xB5,   0xB6,   0xB7};
                          

unsigned char Inversion(unsigned char ch)
{
 ch<<=1;
 ch|=CY;
 return ch;
}  
/*
void OpenAvi()
{
 unsigned char k,j;
 j=0;
 while(1){
  for (k=0;k<8;k++)
  {
   SendCommand(0xCB);
   Delay(1);
 //  if (k%2==0&&k!=0)
  //   if (k%2==0) 
      SendData(1<<k);
 //  else
 //      SendData(Inversion(1<<k)); 
   Delay(1000);
   SendData(0x00);
   Delay(1000);
  }
 //SendCommand(0xC9);
 //Delay(1);
 //SendData(Inversion(font[j]));
 j=(j<10)?j+1:0;
 // (ch<0xff)

 Delay(1000);  
} 
} 
*/
/***end flash***/



//------------------ClearLocation()---------------------
/***Clear specify bit***/
void ClearLocation(unsigned char seg_loc,unsigned char grid) reentrant
//seg_loc:segment,grid:want clear's bit
{
 SendAddress(seg_loc);
 SendData(TruesTable[grid]^(TruesTable[grid]|Get_Grid(seg_loc)));
}
/***end clear***/


//------------------SetLocation()-------------------------
/***Set spectfy bit***/
void SetLocation(unsigned char seg_loc,unsigned char grid) reentrant
{
 SendAddress(seg_loc);
 SendData(TruesTable[grid]|Get_Grid(seg_loc));
}



//-------------------Clear_Char()----------------------------
void Clear_Char(unsigned char grid)
{
 unsigned char i;
 for (i=0;i<7;i++)
 {
  ClearLocation(i,grid);
  // SendAddress(i);
  // SendData(TruesTable[grid]^(TruesTable[grid]|Get_Grid(i)));
  // Delay(2000);
   
 }
}

//-------------------Display_Char()--------------------------
void Display_Char(unsigned char grid,unsigned char ch) reentrant
{
 if (grid<=6)
 {
  grid-=1;
  Clear_Char(grid);
  switch(ch)
  {
   case 0:
    SetLocation(Seg_A,grid);
    SetLocation(Seg_B,grid);
    SetLocation(Seg_C,grid);
    SetLocation(Seg_D,grid);
    SetLocation(Seg_E,grid);
    SetLocation(Seg_F,grid);
    break;
   case 1:
    SetLocation(Seg_B,grid);
    SetLocation(Seg_C,grid);
    break;
   case 2:
    SetLocation(Seg_A,grid);
    SetLocation(Seg_B,grid);
    SetLocation(Seg_D,grid);
    SetLocation(Seg_E,grid);
    SetLocation(Seg_G,grid);
    break;
   case 3:
    SetLocation(Seg_A,grid);
    SetLocation(Seg_B,grid);
    SetLocation(Seg_C,grid);
    SetLocation(Seg_D,grid);
    SetLocation(Seg_G,grid);
    break;
   case 4:
    SetLocation(Seg_B,grid);
    SetLocation(Seg_C,grid);
    SetLocation(Seg_F,grid);
    SetLocation(Seg_G,grid);
    break;
   case 5:
    SetLocation(Seg_A,grid);
    SetLocation(Seg_C,grid);
    SetLocation(Seg_D,grid);
    SetLocation(Seg_F,grid);
    SetLocation(Seg_G,grid);
    break;
   case 6:
    SetLocation(Seg_A,grid);
    SetLocation(Seg_C,grid);
    SetLocation(Seg_D,grid);
    SetLocation(Seg_E,grid);
    SetLocation(Seg_F,grid);
    SetLocation(Seg_G,grid);
    break;
   case 7:
    SetLocation(Seg_A,grid);
    SetLocation(Seg_B,grid);
    SetLocation(Seg_C,grid);
    break;
   case 8:
    SetLocation(Seg_A,grid);
  //  Delay(2000);
    SetLocation(Seg_B,grid);
  //  Delay(2000);
    SetLocation(Seg_C,grid);
  //  Delay(2000);
    SetLocation(Seg_D,grid);
  //  Delay(2000);
    SetLocation(Seg_E,grid);
  //  Delay(2000);
    SetLocation(Seg_F,grid);
  //  Delay(2000);
    SetLocation(Seg_G,grid);
  //  Delay(2000);
    break;
   case 9:
    SetLocation(Seg_A,grid);
    SetLocation(Seg_B,grid);
    SetLocation(Seg_C,grid);
    SetLocation(Seg_D,grid);
    SetLocation(Seg_F,grid);
    SetLocation(Seg_G,grid);
    break;
  }
 }
}

//---------------------Counter()-------------------------
/***Counter ***/
/*
void Counter()
{
 unsigned int i,j,k,l,h,b;
 unsigned long tp=0;
 //---start count number
 for (i=0;i<=9;i++)
 {
  if (tp>=100000) Display_Char(1,i);
  if (i) Display_Char(1,i);
  for (j=0;j<=9;j++)
  {
   if (tp>=10000) Display_Char(2,j);
   if (j) Display_Char(2,j);
   for (k=0;k<=9;k++)
   {
    if (tp>=1000) Display_Char(3,k);
    if (k) Display_Char(3,k);
    for (l=0;l<=9;l++)
    {
     if (tp>=100) Display_Char(4,l);
     if (l) Display_Char(4,l);
     for (h=0;h<=9;h++)
      {
       if (tp>=10) Display_Char(5,h);
       if (h) Display_Char(5,h);
       for(b=0;b<=9;b++)
        {
         Display_Char(6,b);
         tp++;
          Delay(2000);
         Delay(1);
        }
       }
      }
     }
    }
   }

}
*/
/***End Counter***/



//--------------------Display_Flag()-----------------------------
/***Display***/
void Display_Flag(unsigned char flag)
{
 switch(flag)
 {
  case 'P' :   //PLAY;
    SetLocation(Seg_C,6);
    break;
  case 'S' :   //STAY(Pause);
    SetLocation(Seg_D,6);
    break;
  case 'D' :   //DVD
    SetLocation(Seg_E,6);
    break;
  case 'V' :   //VCD
    SetLocation(Seg_F,6);
    break;
  case 'C' :   //CD
    SetLocation(Seg_B,6);
    break;
  case 'T' :   //TRK
    SetLocation(Seg_A,6);
    break;
  case 'R' :   //REP
    SetLocation(Seg_E,7);
    break;
  case 'A' :   //ALL
    SetLocation(Seg_D,7);
    break;
  case 'B' :   //A-B
    SetLocation(Seg_B,7);
    break;
  case 'M' :   //MP3
    SetLocation(Seg_A,7);
    break;
  case 'I' :  // the right ':'
    SetLocation(Seg_C,7);
    break;
  case 'L' :  // the left ':'
    SetLocation(Seg_F,8);
    break;
 }
}
//-------------------OpenAvi_1()-----------------------------
void OpenAvi_1()
{
 unsigned char flag[]={'P','S','D','V','C','T','R','A','B','M'};
 unsigned char i;
 Delay(2000);
 for (i=0;i<10;i++)
 {
  Display_Flag(flag[i]);
  Delay(200);
 }
 ClearDisMemo();
 Delay(2000);
}

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -