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

📄 lcd.c

📁 使用MC9S12DG128芯片
💻 C
字号:
//液晶子程序
#include "includes.h"
/**********************************************************************
display the first menu
1.PWM  2.ACD  3.ECT 
4.SCI  5.IIC  6.IRQ 
**********************************************************************/
void  LcdFirstMenu(void) {
 //                      
  INT8U FirstMenu[] = {"Car1 Car2 Distance Motor ScaAng "};
   
  LcdWriteAll(FirstMenu);
  
}


/**********************************************************************
initial the lcd
there are four works
1、38H- data bus 8bits,two line ,5*7
2、0fH- open display,display cursor,twinkle
3、06H- AC auto add 1 after lcd have a word
4、14H- cursor move to right in one word
5、01H- clean all display
**********************************************************************/
void LcdInitial(void){
  
  LcdControlLine();      //the direction of DDRE is output
  
  LcdWriteCommon(0x38);
  
  LcdWriteCommon(0x01);
          
  LcdWriteCommon(0x06);
  
  LcdWriteCommon(0x0f); 
  
  LcdWriteCommon(0x14);
  
}
/***********************************************************************
LCD Write All Data

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

void LcdWriteAll (INT8U *pData) {

 INT8U i;
 
 LcdWriteCommon(0x80);
 
 for (i=0;i<16;i++) {LcdWriteData(*pData);pData++;}
 
 LcdWriteCommon(0xC0);
 
 for (i=16;i<32;i++){LcdWriteData(*pData);pData++;} 
 
  
}

/***********************************************************************
LCD Write All Data

***********************************************************************/
void LcdWriteOne (INT8U address,INT8U *data,INT8U num) {
 
LcdWriteCommon(address);

for (;num>0;num--)

  {
  
    LcdWriteData((*data++)+0x30);
  
  }

}

/***********************************************************************/
void LcdWrite16U (INT8U add,INT16U Value,INT8U n) {

  INT16U DisValue[5];    //

  INT16U  *data;

  INT16U Temp1;
                     //
  Temp1 = Value; 
  
  DisValue[0] = (Temp1/10000);
  
  DisValue[1] = ((Temp1-DisValue[0]*10000)/1000);
  
  DisValue[2] = ((Temp1-DisValue[0]*10000-DisValue[1]*1000)/100);

  DisValue[3] = ((Temp1-DisValue[0]*10000-DisValue[1]*1000-DisValue[2]*100)/10);
  
  DisValue[4] = (Temp1-DisValue[0]*10000-DisValue[1]*1000-DisValue[2]*100-DisValue[3]*10);
  
  data = DisValue;
  
  LcdWriteCommon(add);
  
  n++;
  
  for (;n>0;n--)

  {
  
   LcdWriteData((*data++)+0x30);                //
  
  }           //

}                       //
  
  



/***********************************************************************
write data to lcd
***********************************************************************/
 void LcdWriteData(INT8U LcdData) {   
  
  ReadBusy();
  
  RS = 1;
  
  RW = 0;
  
  PORTA = LcdData;
  
  E = 1;
  
   _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  E = 0;
  
 }

/**********************************************************************
write common to lcd
**********************************************************************/
void LcdWriteCommon(INT8U LcdCommon) {
  
  ReadBusy();
  
  RS = 0;
  
  RW = 0;
  
  PORTA = LcdCommon;
  
  E = 1;
  
  _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  _NOP_;
  
  E = 0;
   
}

/**********************************************************************
read busy bit as the highest bit in data bus (port A.7)
**********************************************************************/
void ReadBusy(void){
  
  DDRA = 0x00;    //direction
  
  PUCR_PUPAE = 1;  //pull-up
  
  RS = 0;
  
  RW = 1;
  
  E = 1;
  
  while (PORTA_BIT7);
  
  E = 0;
  
  DDRA = 0xFF;
 
}

⌨️ 快捷键说明

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