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

📄 lcd_drivers.c

📁 关于无传感器无刷电机的源程序,其芯片小,功能还行.
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************
 *                                                                     *
 *                        Software License Agreement                   *
 *                                                                     *
 *    The software supplied herewith by Microchip Technology           *
 *    Incorporated (the "Company") for its dsPIC controller            *
 *    is intended and supplied to you, the Company's customer,         *
 *    for use solely and exclusively on Microchip dsPIC                *
 *    products. The software is owned by the Company and/or its        *
 *    supplier, and is protected under applicable copyright laws. All  *
 *    rights are reserved. Any use in violation of the foregoing       *
 *    restrictions may subject the user to criminal sanctions under    *
 *    applicable laws, as well as to civil liability for the breach of *
 *    the terms and conditions of this license.                        *
 *                                                                     *
 *    THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION.  NO           *
 *    WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING,    *
 *    BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND    *
 *    FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE     *
 *    COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,  *
 *    INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.  *
 *                                                                     *
  **********************************************************************/

 /**********************************************************************
 *                                                                     * 
 *    Author: Smart Power Soutions, LLP                                * 
 *                                                                     *
 *    Filename:lcd_drivers.c        	                                *
 *    Date:           6/15/05                                          *
 *    File Version:   5.00                                             *
 *    Project:        53                                               *
 *    Drawing:        2                                                *
 *                                                                     *
 *    Tools used:    MPLAB C30 Compiler v 1.32                         *
 *                                                                     *
 *    Linker File:    p30f6010.gld                                     *
 *                                                                     *
 *                                                                     *
 ***********************************************************************
 *	Code Description
 *  
 *  These are the low level drivers for the character LCD display.
 *  These routines were taken from the Microchip C18 compiler library
 *  and modified for use on the dsPIC.  In particular, these routines
 *  will only work using a 4-bit interface to the LCD.  The 4 data 
 *  lines must be connected to the lower nibble of a dsPIC port.
 *
 *  Note:  These routines contain delay routines which must be modified
 *  based on the device clock frequency.  As written, these routines
 *  work for a device instruction cycle frequency of 7.38 MHz.
 * 
 **********************************************************************/

#include "general.h"
#include "xlcd.h"

/********************************************************************
*       Function Name:  Delays
*       Return Value:   void
*       Parameters:     void
*       Description:   Generates various delay lengths
						Values given depend upon 7MHz processor frequency  
*                       
********************************************************************/
void DelayFor18TCY(void)	//With 7MHz clock this takes 2.9us
{
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	asm(" NOP");
	return;
}

void DelayXLCD(void)		//With 7MHz clock this takes 8.1ms
{
	unsigned int i;

	for(i=0;i<2048;i++)
	{
		DelayFor18TCY();
	}
	return;
}
void DelayPORXLCD(void)			//With 7MHz clock this takes 24ms
{
	DelayXLCD();
	DelayXLCD();
	DelayXLCD();
	return;
}

void Screen_Delay(void)				//With 7MHz clock this takes approx 7s
{
	unsigned int j;
	
	for(j=0;j<150;j++)
	{
		DelayXLCD();
	}
	return;
}	

/********************************************************************
*       Function Name:  BusyXLCD                                    *
*       Return Value:   char: busy status of LCD controller         *
*       Parameters:     void                                        *
*       Description:    This routine reads the busy status of the   *
*                       Hitachi HD44780 LCD controller.             *
********************************************************************/
unsigned char BusyXLCD(void)
{
        RW_PIN = 1;                     // Set the control bits for read
        DelayFor18TCY();
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock in the command
        DelayFor18TCY();
#ifdef BIT8                             // 8-bit interface
        if(DATA_PORT&0x0080)            // Read bit 7 (busy bit)
        {                               // If high
                E_PIN = 0;              // Reset clock line
                DelayFor18TCY();
                RW_PIN = 0;             // Reset control line
                return 1;               // Return TRUE
        }
        else                            // Bit 7 low
        {
                E_PIN = 0;              // Reset clock line
                DelayFor18TCY();
                RW_PIN = 0;             // Reset control line
                return 0;               // Return FALSE
        }
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        if(DATA_PORT&0x0080)
#else                                   // Lower nibble interface
        if(DATA_PORT&0x0008)
#endif
        {
                E_PIN = 0;              // Reset clock line
                DelayFor18TCY();
                E_PIN = 1;              // Clock out other nibble
                DelayFor18TCY();
                E_PIN = 0;
                DelayFor18TCY();
                RW_PIN = 0;             // Reset control line
                return 1;               // Return TRUE
        }
        else                            // Busy bit is low
        {
                E_PIN = 0;              // Reset clock line
                DelayFor18TCY();
                E_PIN = 1;              // Clock out other nibble
                DelayFor18TCY();
                E_PIN = 0;
                DelayFor18TCY();
                RW_PIN = 0;             // Reset control line
                return 0;               // Return FALSE
        }
#endif
}


/********************************************************************
*       Function Name:  OpenXLCD                                     *
*       Return Value:   void                                         *
*       Parameters:     lcdtype: sets the type of LCD (lines)        *
*       Description:    This routine configures the LCD. Based on    *
*                       the Hitachi HD44780 LCD controller. The      *
*                       routine will configure the I/O pins of the   *
*                       microcontroller, setup the LCD for 4-bit     *
*                       mode and clear the display. The user  	     *
*                       must provide three delay routines:           *
*                       DelayFor18TCY() provides a 18 Tcy delay      *
*                       DelayPORXLCD() provides at least 15ms delay  *
*                       DelayXLCD() provides at least 5ms delay      *
**********************************************************************/
void OpenXLCD(unsigned char lcdtype)
{
   // The data bits are the lower 4-bits of the port. These pins are made into inputs
    
    	DATA_PORT &= 0xfff0;
        DATA_PORT |= 0x0003;        	// Function set cmd(4-bit interface)
        TRIS_DATA_PORT &= 0xfff0;
               
        RW_PIN = 0;                     // R/W pin made low
        DelayFor18TCY();
        RS_PIN = 0;                     // Register select pin made low
        DelayFor18TCY();
        E_PIN = 0;                      // Clock pin made low
        DelayFor18TCY();
		TRIS_RW = 0;                    // All control signals made outputs
		DelayFor18TCY();
        TRIS_RS = 0;
        DelayFor18TCY();
        TRIS_E = 0;
        
        // Delay for 15ms to allow for LCD Power on reset
        DelayPORXLCD();
		        
        // Setup interface to LCD

        E_PIN = 1;                      // Clock the cmd in
        DelayFor18TCY();
        E_PIN = 0;
        
        // Delay for at least 4.1ms
        DelayXLCD();

        // Setup interface to LCD
                     
        //DATA_PORT &= 0xfff0;            // Function set cmd(4-bit interface)

⌨️ 快捷键说明

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