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

📄 panel.c

📁 基于MST-G240128点阵液晶的 状态机机制 人机界面四级滚屏菜单 源代码 ,带时间片机制模拟操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "LZK.H"

extern uint8 code su[];
extern uint8 code zhou[];
extern uint8 code shi[];
extern uint8 code you0[];
extern uint8 code ming[];
extern uint8 code ke[];
extern uint8 code ji[];
extern uint8 code you1[];
extern uint8 code xian[];
extern uint8 code gong[];
extern uint8 code si[];
extern uint8 code FONT8x8ASCII[][8];

extern uint8 code Matrix001[];
extern uint8 code Matrix002[];

extern uint8 code Matrix004[];
extern uint8 code Matrix005[];
extern uint8 code Matrix006[];
extern uint8 code Matrix007[];
extern uint8 code Matrix008[];
extern uint8 code Matrix009[];

extern uint8 code du[];
extern uint8 code du2[];
extern uint8 code ASCII_0[];
extern uint8 code ASCII_1[];
extern uint8 code ASCII_2[];
extern uint8 code ASCII_3[];
extern uint8 code ASCII_4[];
extern uint8 code ASCII_5[];
extern uint8 code ASCII_6[];
extern uint8 code ASCII_7[];
extern uint8 code ASCII_8[];
extern uint8 code ASCII_9[];
extern uint8 code ASCII_Dot[];
extern uint8 code Arrow[];
extern uint8 code Blank[];


/************************************************************
 ***  定义LCM显示缓冲区
 ***********************************************************/
//uint8 xdata GUI_disp_buff[GUI_LCM_YMAX][GUI_LCM_XMAX/8];


/***********************************************************************
 ***  常量声明
 **********************************************************************/
uint8 code DCB_HEX_TAB[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};

/*
int8  code SIN[32] = 
{
    0,  8, 15, 22, 28, 33, 37, 39,
   40, 39, 37, 33, 28, 22, 15, 8,
    0, -8,-15,-22,-28,-33,-37,-39,
  -40,-39,-37,-33,-28,-22,-15,-8
};
*/

int8  code SIN[32] = 
{
    0,  4,  7, 11, 14, 16, 18, 19,
   20, 19, 18, 16, 14, 11,  7,  4,
    0, -4, -7,-11,-14,-16,-18,-19,
  -20,-19,-18,-16,-14,-11, -7, -4
};

/***********************************************************************
* 名称:LED_On_Off()
* 功能:LED开关控制
* 入口参数:LedNum:LED No分别为LCD背光、运行指示灯、设置指示灯和故障指示灯;
*           bCMD:  位变量,“1”=On、“0”=Off。     
* 出口参数:无
* 说明:    
***********************************************************************/
void LED_OnOff(uint8 LedNum,bit bCMD)
{
   uint8 ucTMP;
   if(bCMD)                          // LED Light ON.
   {
      if(LedNum == BLED)             // LCD_nBLED(EBD.2) = 0.
	    ucTMP = 0xfb;
      if(LedNum == RunLED)           // LED0(EBD.5) = 0.
	    ucTMP = 0xdf;
      if(LedNum == SetLED)           // LED1(EBD.6) = 0.
	    ucTMP = 0xbf;
      if(LedNum == ErrLED)           // LED2(EBD.7) = 0.
	    ucTMP = 0x7f;

      SFRPAGE = 0x0f;  // P5 SFR PAGE.
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       
      
	  ucPanDATA = ucPanDATA & ucTMP; 
      P5 = ucPanDATA;                

      PanelLE = 1;
      PanelLE = 1;
      PanelLE = 0;
   }
   else                              // LED Light Off.
   { 
      if(LedNum == BLED)             // LCD_nBLED(EBD.2) = 1.
	    ucTMP = 0x04;
      if(LedNum == RunLED)           // LED0(EBD.5) = 1.
	    ucTMP = 0x20;
      if(LedNum == SetLED)           // LED1(EBD.6) = 1.
	    ucTMP = 0x40;
      if(LedNum == ErrLED)           // LED2(EBD.7) = 1.
	    ucTMP = 0x80;

      SFRPAGE = 0x0f;  // P5 SFR PAGE.
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       

      ucPanDATA = ucPanDATA | ucTMP; 
      P5 = ucPanDATA;                

      PanelLE = 1;
      PanelLE = 1;
      PanelLE = 0;
   }
}

/***********************************************************************
* 名称:BELL_OnOff()
* 功能:BELL开关控制
* 入口参数:bCMD:  位变量,“1”=On、“0”=Off。     
* 出口参数:无
* 说明:    
***********************************************************************/
void BELL_OnOff(bit bCMD)
{
   if(bCMD)                          // BELL ON.
   {
      SFRPAGE = 0x0f;  // P5 SFR PAGE.
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       

      ucPanDATA = ucPanDATA | 0x10;  // BP(EBD.4) = 1.
      P5 = ucPanDATA;                

      PanelLE = 1;
      PanelLE = 1;
      PanelLE = 0;
   }
   else                              // BELL Off.
   { 
      SFRPAGE = 0x0f;  // P5 SFR PAGE.
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       
      P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       

      ucPanDATA = ucPanDATA & 0xef;  // BP(EBD.4) = 0.
      P5 = ucPanDATA;                

      PanelLE = 1;
      PanelLE = 1;
      PanelLE = 0;
   }
}

/***********************************************************************
* 名称:LCD_nCS()
* 功能:LCD片选
* 入口参数:bCMD:位变量,“0”= LCD Selected.     
* 出口参数:无
* 说明:LCD片选有效前使nMCS = “1”,避免总线冲突.    
***********************************************************************/
void LCD_nCS(bit bCMD)
{
   if(bCMD)                        // LCD_nCS Output "1", Invalid
   {
      LCD_nCS0 = 1;

      SFRPAGE = 0x0f;              // P4 SFR PAGE.
      ucP4DATA = ucP4DATA & 0xf7;  // nMCS = '0'. 
      P4 = ucP4DATA;  
   }
   else                            // LCD_nCS Output "0", Valid
   {
      SFRPAGE = 0x0f;              // P4 SFR PAGE.
      ucP4DATA = ucP4DATA | 0x08;  // nMCS = '1'. 
      P4 = ucP4DATA;  

      LCD_nCS0 = 0;  
   }	    
}
/***********************************************************************
* 名称:LCD_Reset()
* 功能:对LCM复位,对相关I/O口初始化
* 入口参数:无     
* 出口参数:无
* 说明:    
***********************************************************************/
void LCD_Reset(void)
{
   LCD_nCS(1);                    // LCD nCS0 Output "1", Invalid.

   PanelLE = 0;
   nReInLE = 1;
   ReOutLE = 0;
   PulseLE = 0;   

   LCD_nCS(0);                    // LCD nCS0 Output "0", Valid.

   SFRPAGE = 0x0f;  // P5 SFR PAGE.
   P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       
   P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       

   ucPanDATA = ucPanDATA & 0xf7;  // LCD_nRST(EBD.3) = 0.
   P5 = ucPanDATA;

   PanelLE = 1;
   PanelLE = 1;
   PanelLE = 0;

   DmS(10);

   SFRPAGE = 0x0f;  // P5 SFR PAGE.
   P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       
   P5MDOUT = 0xff;  // P5口设置为推挽输出方式.       

   ucPanDATA = ucPanDATA | 0x08;  // LCD_nRST(EBD.3) = 1.
   P5 = ucPanDATA;                

   PanelLE = 1;
   PanelLE = 1;
   PanelLE = 0;

   LCD_nCS(1);                    // LCD nCS0 Output "1", Invalid.
}

/***********************************************************************
* 名称:LCD_WriteCommand()
* 功能:写命令子程序。(发送命令前,不检查液晶模块的状态)
* 入口参数:ucCMD     (要写入LCM的命令字)
* 出口参数:无
* 说明:函数会设置LCM数据总线为输出方式
***********************************************************************/
void LCD_WriteCommand(uint8 ucCMD)
{
   LCD_CnD = 1;

   LCD_nCS(0);                   // LCD nCS0 Output "0", Valid.
   LCD_COMMAND = ucCMD;
   LCD_nCS(1);                   // LCD nCS0 Output "1", Invalid.
}

/***********************************************************************
* 名称:LCD_WriteData()
* 功能:写数据子程序。(发送数据前,不检查液晶模块的状态)
* 入口参数:ucDATA    (要写入LCM的数据)
* 出口参数:无
* 说明:函数会设置LCM数据总线为输出方式
***********************************************************************/
void LCD_WriteData(uint8 ucDATA)
{
   LCD_CnD = 0;

   LCD_nCS(0);                   // LCD nCS0 Output "0", Valid.
   LCD_COMMAND = ucDATA;
   LCD_nCS(1);                   // LCD nCS0 Output "1", Invalid.
}

/***********************************************************************
* 名称:LCD_ReadState()
* 功能:读取状态字子程序。
* 入口参数:无
* 出口参数:返回值即为读出的状态字
* 说明:函数会设置LCM数据总线为输入方式
***********************************************************************/
uint8 LCD_ReadState(void)
{
   uint8 ucTMP;

   LCD_CnD = 1;

   LCD_nCS(0);                   // LCD nCS0 Output "0", Valid.
   ucTMP = LCD_STATUS;
   LCD_nCS(1);                   // LCD nCS0 Output "1", Invalid.

   return ucTMP;
}

/***********************************************************************
* 名称:LCD_ReadData()
* 功能:读取数据子程序。
* 入口参数:无
* 出口参数:返回值即为读出的数据
* 说明:函数会设置LCM数据总线为输入方式
***********************************************************************/
uint8 LCD_ReadData(void)
{
   uint8 ucTMP;

   LCD_CnD = 0;

   LCD_nCS(0);                   // LCD nCS0 Output "0", Valid.
   ucTMP = LCD_DATA;
   LCD_nCS(1);                   // LCD nCS0 Output "1", Invalid.

   return ucTMP;
}

/***********************************************************************
* 名称:LCD_TestStaBit01()
* 功能:判断读写指令和读写数据是否允许。
* 入口参数:无
* 出口参数:返回0表示禁止,否则表示允许
***********************************************************************/
bit LCD_TestStaBit01(void)
{  
   uint8 i;

   for(i=100; i>0; i--)
   {  
      if( (LCD_ReadState() & 0x03) == 0x03 ) 
	    break;
   } 
   if(i>0)
     return 1;
   else
     return 0;
}

/***********************************************************************
* 名称:LCD_TestStaBit03()
* 功能:数据自动写状态是否允许。
* 入口参数:无
* 出口参数:返回0表示禁止,否则表示允许
***********************************************************************/
bit LCD_TestStaBit03(void)
{  
   uint8 i;

   for(i=100; i>0; i--)
   {  
      if( (LCD_ReadState() & 0x08) == 0x08 ) 
	    break;
   } 
   if(i>0)
     return 1;
   else
     return 0;
}

/***********************************************************************
* 名称:LCD_WriteTCommand1()
* 功能:写无参数命令子程序。会先判断LCM状态字。
* 入口参数:ucCMD (要写入LCM的命令字)
* 出口参数:      (操作出错返回0,否则返回)
***********************************************************************/
bit LCD_WriteTCommand1(uint8 ucCMD)
{  
   if( LCD_TestStaBit01()==0 ) 
     return 0;
   LCD_WriteCommand(ucCMD);		// 发送命令字
   return 1;
}

/***********************************************************************
* 名称:LCD_WriteTCommand2()
* 功能:写单参数命令子程序。会先判断LCM状态字。
* 入口参数:ucCMD  (要写入LCM的命令字)
*           ucDATA1 (参数1)
* 出口参数:操作出错返回0,否则返回1
* 说明:先发送参数据数据,再发送命令字
***********************************************************************/
bit LCD_WriteTCommand2(uint8 ucCMD, uint8 ucDATA1)
{  
   if( LCD_TestStaBit01()==0 ) 
     return 0;
   LCD_WriteData(ucDATA1);			// 发送数据1
   
   if( LCD_TestStaBit01()==0 ) 
     return 0;
   LCD_WriteCommand(ucCMD);		    // 发送命令字
   
   return 1;
}

/***********************************************************************
* 名称:LCD_WriteTCommand3()
* 功能:写双参数命令子程序。会先判断LCM状态字。
* 入口参数:ucCMD   (要写入LCM的命令字)
*           ucDATA1	(参数1)
*           ucDATA2	(参数2)
* 出口参数:操作出错返回0,否则返回1
* 说明:先发送两字节参数据数据,再发送命令字
***********************************************************************/
bit LCD_WriteTCommand3(uint8 ucCMD, uint8 ucDATA1, uint8 ucDATA2)
{  
   if( LCD_TestStaBit01()==0 ) 
     return 0;
   LCD_WriteData(ucDATA1);		    // 发送数据1
   
   if( LCD_TestStaBit01()==0 ) 
     return 0;
   LCD_WriteData(ucDATA2);		    // 发送数据2
   
   if( LCD_TestStaBit01()==0 ) 
     return 0;
   LCD_WriteCommand(ucCMD);	    	// 发送命令字
     
   return 1;
}

/***********************************************************************
* 名称:LCD_WriteTData1()
* 功能:写1字节数据子程序。先判断状态字。
* 入口参数:ucDATA  	   要写入LCM的数据
* 出口参数:操作出错返回0,否则返回1
***********************************************************************/
bit LCD_WriteTData1(uint8 ucDATA)
{  
   if( LCD_TestStaBit03()==0 ) 
     return 0;
   LCD_WriteData(ucDATA);			// 发送命令字
   
   return 1;
}

/***********************************************************************

⌨️ 快捷键说明

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