📄 bsp_lcd.c
字号:
/*-----------------------------------------------------------------------------
* EUROPE TECHNOLOGIES Software Support
*------------------------------------------------------------------------------
* The software is delivered "AS IS" without warranty or condition of any
* kind, either express, implied or statutory. This includes without
* limitation any warranty or condition with respect to merchantability or
* fitness for any particular purpose, or against the infringements of
* intellectual property rights of others.
*------------------------------------------------------------------------------
*
* Processor : easyCAN
* File Name : bsp_lcd.c
* Description : Function declarations for LCD for the BSP
* Version : 1.01
*
* +----- (NEW | MODify | ADD | DELete)
* |
* No | when who what
*-----+---+----------+------------------+--------------------------------------
* 000 NEW 06/12/99 Patrice VILCHEZ Creation
* 001 MOD 01/04/01 Olivier MAZUYER Clean up
* 002 MOD 23/07/01 Frederic SAMSON - Add CGRAM Pattern definition
* - Create BSP_LCDCustomCharDefinition()
* - Modify BSP_LCDDisplayChar()
* - Add BSP_LCDCustomCharDefinition()
* to BSP_LCDInit()
* 003 ADD Olivier MAZUYER Add BSP_LCDConvertIntASCII function
* 004 MOD 07/08/2001 Frederic SAMSON Corrections in BSP_LCDConvertIntASCII
* to take account of 0
* 005 MOD 31/01/02 Mahmoud Mesgarzadeh Clean Up
*----------------------------------------------------------------------------*/
/******************************************************************************
* Includes
******************************************************************************/
#include "csp.h"
#include "bsp.h"
/* Define to select the VDD_PERIPH voltage : */
/* VDD_PERIPH_3V ==> VDD_PERIPH = 3.3V */
/* VDD_PERIPH_5V ==> VDD_PERIPH = 5.0V */
/* This define is used by the contrast voltage generator (see BSP_LCDInit() */
#define VDD_PERIPH_3V
//#define VDD_PERIPH_5V
/******************************************************************************
* Custom Characters Definition
******************************************************************************/
U8_T CGRAM[NUMB_OF_CHAR_CGRAM*8]=
{
/* ARROW UP */
/* Line 0, Line 1, Line 2, Line 3, Line 4, Line 5, Line 6, Line 7*/
0x04, 0x0E, 0x15, 0x04, 0x04, 0x04, 0x04, 0x04,
/* ARROW DOWN */
0x04, 0x04, 0x04, 0x04, 0x04, 0x15, 0x0E, 0x04
};
/******************************************************************************
Function : BSP_LCDInit
Description : This function initializes the LCD mode: it enables the UPIO
module clock, defines UPIO pins connected to the LCD as
output and then write the LCD sequence initialization
- data length 8 bits,
- 2 lines, 5x7 dots
- set the display on and the cursor off not blinking
- clears the display
- set the entry mode: DDRAM increment mode and no display shift).
- User patterns are defined in the LCD CGRAM memory.
Input : None
Functions called : 创BSP_LCDWrite创, 创BSP_LCDCustomCharDefinition创, 创CSP_PIO_SET_ECR创
创CSP_PIO_SET_OER创
Returns : None
******************************************************************************/
void BSP_LCDInit(void)
{
/* Set the contrast voltage with the PWM channel 1 */
/* frequency = 32768 Hz, dutycycle=23/256 = 9% */
#ifdef VDD_PERIPH_3V
BSP_LCDSetContrast( 32768, 23);
#endif
#ifdef VDD_PERIPH_5V
BSP_LCDSetContrast( 32768, 3);
#endif
/* Enable the PIO clock */
CSP_PIO_SET_ECR(UPIO, PIO);
/* Define Lcd pio as output (Default) */
CSP_PIO_SET_OER(UPIO, (LCD_RW | LCD_E | LCD_RS | LCD_BUS));
/* Write Lcd sequence initialization */
BSP_LCDWrite(LCD_FUNCTION_SET, LCD_CONTROL);
BSP_LCDWrite(LCD_DISPLAY_ON, LCD_CONTROL);
BSP_LCDWrite(LCD_CLEAR_DISPLAY, LCD_CONTROL);
BSP_LCDWrite(LCD_ENTRY_MODE, LCD_CONTROL);
/* Define User Pattern in CGRAM */
BSP_LCDCustomCharDefinition();
}
/******************************************************************************
Function : BSP_LCDClear
Description : This function clears the LCD display
Input : None
Functions called : 创BSP_LCDWrite创
Returns : None
******************************************************************************/
void BSP_LCDClear(void)
{
BSP_LCDWrite(LCD_CLEAR_DISPLAY, LCD_CONTROL);
BSP_LCDWrite(LCD_ENTRY_MODE, LCD_CONTROL);
}
/******************************************************************************
Function : BSP_LCDBusy
Description : This function polls the busy bit of the LCD.
While the LCD is busy, the function reads the busy
flag which indicating internal operation performed.
It is a waiting function.
Input : None
Functions called : 创CSP_PIO_SET_ODR创, 创CSP_PIOClear创, 创CSP_PIOSet创,
创CSP_PIOGetStatus创
Returns : None
******************************************************************************/
void BSP_LCDBusy(void)
{
/* Local Variable */
U32_T data = 0x80;
/* Set LCD Bus as input */
CSP_PIO_SET_ODR(UPIO, LCD_BUS);
/* Clear RS */
CSP_PIOClear(UPIO, LCD_RS);
while( (data & 0x80) == 0x80 )
{
/* Set RW to 1 (Read) */
CSP_PIOSet(UPIO, LCD_RW);
/********************************************************************/
/* Be careful if internal chip clock is faster than 40MHz: */
/* The delay between rising edge for RW and rising edge for enable */
/* need to be at least of 100ns (4 assembler instructions at 40MHz) */
/********************************************************************/
/* Enable LCD */
CSP_PIOSet(UPIO, LCD_E);
/* Read Data */
data = CSP_PIOGetStatus(UPIO);
/* Disable LCD */
CSP_PIOClear(UPIO, LCD_E);
}
}
/******************************************************************************
Function : BSP_LCDRead
Description : Read data on LCD
Input :
- row : row (from 0 to 1)
- column : (from 0 to 15)
- section : RS value (control or data)
Functions called : 创BSP_LCDWrite创, 创BSP_LCDBusy创, 创CSP_PIO_SET_ODR创,
创CSP_PIO_SET_SODR创, 创CSP_PIO_SET_CODR创, 创CSP_PIOGetStatus创
Returns : data read
******************************************************************************/
U8_T BSP_LCDRead(U8_T row, U8_T column, U8_T section)
{
/* Local Variable */
U32_T pio_val;
U8_T lcd_parameter;
/* Calculate LCD start address for string. */
/* Start of first row is address 0x00, start of second row is 0x40 */
if(row == 0)
lcd_parameter = 0x80 + column;
else
lcd_parameter = 0xC0 + column;
/* Set DDRAM address in LCD */
BSP_LCDWrite(lcd_parameter, LCD_CONTROL);
/* Wait Lcd Busy */
BSP_LCDBusy();
/* Set LCD Bus as input */
CSP_PIO_SET_ODR(UPIO, LCD_BUS);
/* Set RS (Control or Data section) */
if( section == LCD_DATA)
CSP_PIO_SET_SODR(UPIO, LCD_RS);
else
CSP_PIO_SET_CODR(UPIO, LCD_RS);
/* Set RW to 1 (Read) */
CSP_PIO_SET_SODR(UPIO, LCD_RW);
/* Enable LCD */
CSP_PIO_SET_SODR(UPIO, LCD_E);
/* Read Data */
pio_val = CSP_PIOGetStatus(UPIO);
/* Disable LCD */
CSP_PIO_SET_CODR(UPIO, LCD_E);
/* Return Value */
return(pio_val);
}
/******************************************************************************
Function : BSP_LCDWrite
Description : Write a data on LCD
Input :
- data : data 8 bits to be written
- section (control or data)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -