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

📄 lcd.c

📁 使用msp430f448测量脉冲宽度
💻 C
字号:
#include "lcdhead.h"

/*******************************************/
//延时函数
/*******************************************/
void TimeDelay(ulint m)        
{
	ulint j;
	ulint i;
	
	for(i=0; i<m; i++)
	    for(j=0; j<109; j++)
	        _NOP();
}

/****************************************************/
// IO Routine
/******************************************************/

/***********************************************************/
//发送命令字
/***********************************************************/

void SendCmd(uchar command)
{
     LCD_WR_HI;
     LCD_RS_LO;               //for command
     
     LCD_Data = command;
     
     LCD_CS_LO;
     _NOP();
     LCD_WR_LO;
     _NOP();
     LCD_WR_HI;
     _NOP();
     LCD_CS_HI;
}

/*************************************************************/
//发送数据字
/*************************************************************/

void SendData(uchar data)
{
     LCD_WR_HI;
     LCD_RS_HI;                 //for data
     
     LCD_Data = data;
     
     LCD_CS_LO;
     _NOP();
     LCD_WR_LO;
     _NOP();
     LCD_WR_HI;
     _NOP();
     LCD_CS_HI;     
}

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

void LCDInit(void)
{
        LCD_RESET_HI;
        LCD_RESET_LO;
        TimeDelay(1);
        LCD_RESET_HI;
        TimeDelay(1);
      
        SendCmd(0x00);SendCmd(0xcd); TimeDelay(1);
        SendCmd(0x10);SendCmd(0x29); TimeDelay(1);
        SendCmd(0x11);SendCmd(0x10); TimeDelay(1);
      
        SendCmd(0x90);SendCmd(0x04); TimeDelay(1);
      
        SendCmd(0xF0);SendCmd(0xA0); TimeDelay(1); 

        SendCmd(0x20);SendCmd(0x27); TimeDelay(1); 
	SendCmd(0x30);SendCmd(0xEF); TimeDelay(1); 
	SendCmd(0x40);SendCmd(0x00); TimeDelay(1); 
	SendCmd(0x50);SendCmd(0x00); TimeDelay(1);

	SendCmd(0x21);SendCmd(0x27); TimeDelay(1); 
	SendCmd(0x31);SendCmd(0xEF); TimeDelay(1);  
	SendCmd(0x41);SendCmd(0x00); TimeDelay(1);
	SendCmd(0x51);SendCmd(0x00); TimeDelay(1); 

	SendCmd(0x81);SendCmd(0x40); TimeDelay(1); 
	SendCmd(0xD0);SendCmd(0x06); TimeDelay(1);           
}

/****************************************************************/
// LCD Contrast Contral
/****************************************************************/

void LCD_Contrast(uchar level)
{
        uchar i;
        i = 0x10 + level;
        SendCmd(0xD0);SendCmd(i); TimeDelay(20);   
}


/****************************************************************************/
void SetAddr(uchar code ,uchar x,uchar y)
{
        if(code==0)
        {
            SendCmd(0x00);
            SendCmd(0xc5);
        }
        if(code==1)
        {
            SendCmd(0x00);
            SendCmd(0xcd);
        }
       
        SendCmd(0x60);
        SendCmd(x);                //set cursor X location to 0
        SendCmd(0x70);
        SendCmd(y);                //set cursor Y location to 0
}

/*****************************************************************************/
void Display(const uchar *data,uchar code,uchar x,uchar y,uchar tx,uchar ty )
{
       uchar i;
       uchar j;
       
       for(i=0;i<ty;i++)
         for(j=0;j<tx;j++)
          {  
             SetAddr(code ,x+j, y+i);
             SendData(*(data+(i*tx)+j));
         } 
}


/**************************************************************************/
void DispalyGraphicScreen(uchar *Pic)
{
        uchar tempdata;
        uchar i,j;
       
        SendCmd(0x00);SendCmd(0xc5);
        
        SendCmd(0x60);SendCmd(0x00);                //set cursor X location to 0
        SendCmd(0x70);SendCmd(0x00);                //set cursor Y location to 0
      
       for(i=0;i<240;i++)
	{
      	   for(j=0;j<40;j++)
     		{
     		  tempdata=(*(Pic+(i*40)+j));
     		  SendData(tempdata);
 	        }
        }
       
}

/**************************************************************************************/
void WriteTextScreen(uchar *TxtData)
// DisplayData should be 20(x2)x15 = 600byte
// set to char display
{
	uchar TempData;
	uchar i,j;
        SendCmd(0x00); SendCmd(0xCD); TimeDelay(1);  // normal power mode, Char mode
                                                     // display on, normal display
        SendCmd(0x60); SendCmd(0x00); TimeDelay(1);  // set cursor X location to 0
        SendCmd(0x70); SendCmd(0x00); TimeDelay(1);  // set cursor Y location to 0

        for (j=0; j<15; j++)
		{
	 	for(i=0; i<40; i++)
   			{
	   		          TempData=(*(TxtData+(j*40)+i));
	   		          SendData(TempData);   	                
			}
	    }
}

/*****************************************************************************************/
void LCDClear(void)
{     
        uchar i,j;
       
        SendCmd(0x00);SendCmd(0xc5);
        
        SendCmd(0x60);SendCmd(0x00);
        SendCmd(0x70);SendCmd(0x00);
        for(i=0;i<240;i++)
        {
              for(j=0;j<40;j++)
              {
                   SendData(0x00);
               }
        }
}
/**********************************************************************************************/



⌨️ 快捷键说明

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