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

📄 lcd_hd44780.c

📁 freescale最新的16位单片机
💻 C
📖 第 1 页 / 共 5 页
字号:
  
  IIC(IIC_STATUS, STATUS_CLEAR);
  IIC(IIC_DATA_SEND, data);               /* Send Data to Device */
 
  while(IIC_STATUS==0){                   /*wait for transfer complete flag, ACK flag*/
      fault++;
        if (fault ==100) return;
  }
  while(IIC_ACK==1){ 
      fault++;
        if (fault ==100) return;
  }
  IIC(IIC_CONDITION,IIC_STOP);						/*free the bus*/
}
#endif
/******************************************************************************
* Module            : static void LcdPutNumberOnPortRST(tUC data, tUC rs, tUC rw)
* Description       : Put data on display data port during LCD INITIALIZATION.
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC data,
*                     tUC rs={LCD_DATA, LCD_CTRL},
*                     tUC rw={LCD_READ, LCD_WRITE}
* Special Issues    : none
******************************************************************************/
static void LcdPutNumberOnPortRST(tUC data, tUC rs, tUC rw)
{
#ifdef IIC_LCD_TRANSMIT
  tUC data_send_iic;
#endif
#ifndef IIC_LCD_TRANSMIT
  LCD_RS	=	rs;
  #ifndef LCD_NO_READ_FUNCTION 
  LCD_RW = rw;
  #endif
#endif

#ifdef LCD_DATAWIDTH_8
    LCD_DPORT =	data;
#endif 

#ifdef LCD_DATAWIDTH_4
#ifdef LCD_DPORTH
/* write MSB data nibble to MSB port nibble  */
  #ifdef IIC_LCD_TRANSMIT
    data_send_iic = (data & 0xF0);
    
    data_send_iic += (8*rs); 				  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();

    data_send_iic += 4; 								  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
    
    data_send_iic -= 4; 								  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
  #else
    LCD_DPORT = (LCD_DPORT & 0x0F) | (data & 0xF0); 
  #endif
#endif

#ifdef LCD_DPORTL
 /* write MSB data nibble to LSB port nibble */
   #ifdef IIC_LCD_TRANSMIT
    data_send_iic = ((data>>4) & 0x0F);

    data_send_iic += (128*rs); 			  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();

    data_send_iic += 64; 								    /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
    
    data_send_iic -= 64; 								    /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
  #else
    LCD_DPORT = (LCD_DPORT & 0xF0) | ((data>>4) & 0x0F); 
  #endif
#endif
#endif 

#ifdef LCD_DATAWIDTH_2
#ifdef LCD_DPORTH
/* write MSB data nibble to MSB port nibble  */
 LCD_DPORT = (LCD_DPORT & 0x0F) | (data & 0xF0); 
#endif

#ifdef LCD_DPORTL
 /* write MSB data nibble to LSB port nibble */
 LCD_DPORT = (LCD_DPORT & 0xF0) | ((data>>4) & 0x0F);
#endif
#endif 

 LcdClock();
}
/******************************************************************************
* Module            : static void LcdPutNumberOnPort(tUC data, tUC rs, tUC rw)
* Description       : Put data on display data port
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC data,
*                     tUC rs={LCD_DATA, LCD_CTRL},
*                     tUC rw={LCD_READ, LCD_WRITE}
* Special Issues    : none
* Special Issues    : none
******************************************************************************/
static void LcdPutNumberOnPort(tUC data, tUC rs, tUC rw)
{
#ifdef IIC_LCD_TRANSMIT
 tUC data_send_iic;
#endif
#ifndef IIC_LCD_TRANSMIT 
  LCD_RS	   =	rs;
  #ifndef LCD_NO_READ_FUNCTION 
  LCD_RW     =  rw;
  #endif
#endif

 LcdSetPortDirection(LCD_OUTPORT);

#ifdef LCD_DATAWIDTH_8
  LCD_DPORT	=	data;														
  LcdClock();
#endif 

#ifdef LCD_DATAWIDTH_4

#ifdef LCD_DPORTH
/* write MSB data nibble to MSB port nibble */
  #ifdef IIC_LCD_TRANSMIT
    data_send_iic = (data & 0xF0);
    
    data_send_iic += (8*rs); 				  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();

    data_send_iic += 4; 								  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
    
    data_send_iic -= 4; 								  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
  #else
    LCD_DPORT = (LCD_DPORT & 0x0F) | (data & 0xF0);       
    LcdClock();
  #endif
/* write LSB data nibble to MSB port nibble */
  #ifdef IIC_LCD_TRANSMIT
    data_send_iic = ((data<<4) & 0xF0);
    
    data_send_iic += (8*rs); 				  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();

    data_send_iic += 4; 								  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
    
    data_send_iic -= 4; 								  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
  #else
    LCD_DPORT = (LCD_DPORT & 0x0F) | ((data<<4) & 0xF0);       
    LcdClock();
  #endif
#endif

#ifdef LCD_DPORTL
/* write MSB data nibble to LSB port nibble */
  #ifdef IIC_LCD_TRANSMIT
    data_send_iic = (data & 0x0F);
    
    data_send_iic += (128*rs); 			  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();

   data_send_iic += 64; 								    /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
    
    data_send_iic -= 64; 								    /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
  #else
    LCD_DPORT = (LCD_DPORT & 0xF0) | ((data>>4) & 0x0F);       
    LcdClock();
  #endif
/* write LSB data nibble to LSB port nibble */
  #ifdef IIC_LCD_TRANSMIT
    data_send_iic = ((data>>4) & 0x0F);
    
    data_send_iic += (128*rs); 			  /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();

   data_send_iic += 64; 								    /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
    
    data_send_iic -= 64; 								    /*LCD Clock + data/ctrl*/
    LcdPutNumberOnIIC(data_send_iic);
    LcdDelay1us();
  #else
    LCD_DPORT = (LCD_DPORT & 0xF0) | (data & 0x0F);       
    LcdClock();
  #endif
#endif

#endif 
}
/******************************************************************************
* Module            : void LcdReset(void)
* Description       : Standard display reset.
*                     Function has to be called before first display using
*                     to be initialized for communication.
*                     The function sets display behavior to :
*                     LCD_CURSORRIGHT,LCD_SHIFTOFF,LCD_DISPLAYON,
*                     LCD_CURSOROFF,LCD_BLONKOFF,LCD_SMALLFONT, and it is ready
*                     to be used.  
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : none
* Special Issues    : none
******************************************************************************/
void LcdReset(void)
{
#ifndef IIC_LCD_TRANSMIT
 LCD_DRS = LCD_TRUE;                          /* set pin direction as output */
 LCD_DE  = LCD_TRUE;                          /* set pin direction as output */
   #ifndef LCD_NO_READ_FUNCTION  
     LCD_DRW = LCD_TRUE;                          /* set pin direction as output */
   #endif

 LcdSetPortDirection(LCD_OUTPORT);           /* set data port pins as output */

 LCD_RS  = LCD_CTRL;                          /* write 0                     */
 LCD_E   = LCD_FALSE;                         /* write 0                     */
   #ifndef LCD_NO_READ_FUNCTION 
     LCD_RW  = LCD_WRITE;                         /* write 0                     */
   #endif
 #endif

 #ifdef IIC_LCD_TRANSMIT											/*reset IIC & HW*/
  LcdPutNumberOnIIC(0x0);
 #endif

 LcdPutNumberOnPortRST(0x30, LCD_CTRL, LCD_WRITE);
 LcdDelay10ms();	                                 /* longer than 4.1ms      */

 LcdPutNumberOnPortRST(0x30, LCD_CTRL, LCD_WRITE);
 LcdDelay10ms();                                   /* longer than 100us      */

 LcdPutNumberOnPortRST(0x30, LCD_CTRL, LCD_WRITE);
 LcdDelay10ms();                               /* from now you can test busy */

#ifdef LCD_DATAWIDTH_4
 LcdPutNumberOnPortRST(0x20, LCD_CTRL, LCD_WRITE);
#endif

 /*display initialization: 
   8bit interface, 2 memory lines, 20 characters, font 5x7
 */
#ifdef LCD_DATAWIDTH_8
 LcdCommand(0x24); /*0010 1000*/	         /*8b interface, 2 lines, font 7x5 */
// LcdCommand(0x3C); /*0011 1000*/	         /*8b interface, 2 lines, font 10x5*/
#endif
#ifdef LCD_DATAWIDTH_4
 LcdCommand(0x28); /*0010 1000*/	         /*4b interface, 2 lines, font 8x5 */
// LcdCommand(0x28); /*0010 1000*/	         /*4b interface, 2 riadky, font 7x5 */
#endif

 LcdCommand(0x08); /*0000 1000*/				   /*display off and cursor on, no blink*/
 LcdCommand(0x01); /*0000 0001*/				   /*clear display		               */
 LcdCommand(0x06); /*0000 0110*/				   /*autoincrement shift cursor      */
 LcdCommand(0x0F); /*0000 1111*/				   /*display on, cursor on          */
 
}

/******************************************************************************
* Module            : LcdSetUpIIC
* Description       : Standard IIC configuration.
*                     Function has to be called before first display using
*                     to be initialized for communication.
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : none
* Special Issues    : none
******************************************************************************/
void LcdSetUpIIC(void)
{
 /*Frequency Divider Register*/
 IIC0_IBFD = 0x00; //64  0x50 //0d   // prescaler clock 
 IIC0_IBAD = 0xFF;                   // slave adress
 
 /*IIC control register*/
 IIC0_IBCR_IBEN   = 0;	  //Disable IIC
 IIC0_IBCR_IBEN   = 1;	  //Enable IIC
 IIC0_IBCR_TX_RX  = 1;    //1 - transmit mode //0 - recieve mode
 //IIC0_IBCR_IBIE   = 0;    //1 - enable interrupt on IIC //0 - disable interrupt
 //IIC0_IBCR_IBSWAI = 0;		//1 - halt clock in wait mode		//0 - normal mode
}
/******************************************************************************
* Module            : LcdShowFaultStatus
* Description       : Write errormesage into LCD
* Global Data       : systemStatus
* Static Global Data: none
* Returns           : none
* Arguments         : messageNumber
* Special Issues    : none
******************************************************************************/
void LcdShowFaultStatus(tUC messageNumber)
{
char *originalString, *String = "Xx";
char *resultXx = NULL;
char *resultASCII = NULL;
char messageNumberASCI[] = "[  ]";
char *messageNumberAdress = &messageNumberASCI[0];
char firstline=0,zeroline=0;
 
if(messageNumber != 0){
 		messageNumberASCI[1] = ((messageNumber/10)+48);			      /*messagenumber to ASCII*/
 		messageNumberASCI[2] = ((messageNumber%10)+48);
 		
    for(firstline=0; resultASCII == NULL; firstline++){		    /*find message number*/
      originalString = (signed char *)&messages[firstline][0];
      resultASCII = (signed char *volatile)strstr(originalString,messageNumberAdress);
    }                                                                          /**/
    
    for(zeroline=firstline-2; resultXx == NULL; zeroline--){	 /*what kind of message ?*/
      originalString = (signed char *)&messages[zeroline][0];
      resultXx = (signed char *volatile)strstr(originalString,String);
    }
    LcdClear();																								 /*send messages to LCD*/
    LcdOutTextL(0,(signed char *)&(messages[(zeroline+1)][0]));
    LcdOutTextL(1,(signed char *)&(messages[(firstline-1)][0]));
}else{
  LcdClear();
  LcdOutTextL(0,(signed char *)&(messages[(0)][0]));
}
 LcdSetCursorOnOff(LCD_CUR

⌨️ 快捷键说明

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