/******************************************************************
* 대원디에스티
* (c) Copyright 2009, DAEWOON DST
* Seoul, Korea All Rights Reserved
-------------------------------------------------------------------
* File Name : LCD.c
* Title : LCD control function
* Author : Her Joung Joo
* Version : 1.0
* Target MCU : PIC32 series
* Edit Tabs : 4
******************************************************************/
/*=================================================================
REVISION HISTORY
=================================================================*/
/*
2009-01-06 PM
- Created the program
- Version 1.0
*/
/*-----------------------------------------------------------------
DEFINES...
-----------------------------------------------------------------*/
/*-------------------------------------------------------------
INCLUDE FILES
-------------------------------------------------------------*/
#include "stm32f2xx.h"
#include "stm32f2xx_conf.h"
#include "lcd.h"
#include "tmr.h"
#include "spi.h"
#include <stdio.h>
#include <string.h> /*-------------------------------------------------------------
VARIABLES DEFINES
-------------------------------------------------------------*/
unsigned char LCD_Cursor=0; // 좌표 x = 0~15 y = 0~3 ex) 0x23 : x=3 y=2
/*-------------------------------------------------------------
LOCAL PROTOTYPES
-------------------------------------------------------------*/
void lcdDatWr (unsigned char); // LCD DATA SEND
void lcdCmdWr (unsigned char); // LCD CMD SEND
void lcdInit(void); // LCD SET INIT
void lcdCls(void); // clean screen
void lcdClsLine(void); // cursor line clear
void lcdSetXY( unsigned char, unsigned char ); // LCD SET xy
/*-----------------------------------------------------------------
FUNCTIONS...
-----------------------------------------------------------------*/
//*****************************************************************
//* Local Functions *
//*****************************************************************
/*-------------------------------------------------------------
* lcdDatWr
*
* Description : LCD data write command
* Arguments : dat(data)
* Return : null
* Notes :
-------------------------------------------------------------*/
void lcdDatWr (unsigned char dat)
{
LCD_RS_HI();
LCD_CS_LO();
tmrDelay_10us(1);
Spi2WriteByte(dat);
LCD_CS_HI();
}
/*-------------------------------------------------------------
* lcdCmdWr
*
* Description : LCD command write command
* Arguments : dat(command)
* Return : null
* Notes :
-------------------------------------------------------------*/
void lcdCmdWr (unsigned char dat)
{
LCD_RS_LO();
LCD_CS_LO();
tmrDelay_10us(1);
Spi2WriteByte(dat);
LCD_CS_HI();
}
//*****************************************************************
//* Public Functions *
//*****************************************************************
/*-------------------------------------------------------------
* lcdInit
*
* Description : LCD 초기화
* Arguments : null
* Return : null
* Notes :
-------------------------------------------------------------*/
void lcdInit ( void ) // LCD SET INIT
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
/* Configure BZ_CON pin as input */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = LCD_CS_PIN;
GPIO_Init(LCD_CS_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LCD_RS_PIN;
GPIO_Init(LCD_RS_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LCD_RES_PIN;
GPIO_Init(LCD_RES_GPIO_PORT, &GPIO_InitStructure);
Spi2Init();
LCD_RES_HI();
LCD_CS_LO();
LCD_RS_LO();
tmrDelay_ms(10);
// LCD_RES_HI();
LCD_CS_HI();
tmrDelay_ms(10);
lcdCmdWr ( LCD_RESET );
tmrDelay_ms(100);
lcdCmdWr ( LCD_BIAS_1OF9 );
lcdCmdWr ( LCD_HORIZONTAL_NORMAL );
lcdCmdWr ( LCD_VERTICAL_REVERSE );
// lcdCmdWr ( LCD_DISPLAY_NORMAL );
lcdCmdWr ( LCD_V5_VOLTAGE_RATIO+4 );
tmrDelay_ms(10);
lcdCmdWr ( LCD_CONTRAST );
lcdCmdWr ( 0x15 ); // contrast value 0x01~0x3f
tmrDelay_ms(10);
lcdCmdWr ( LCD_ALL_POWER_OFF|0x04 );
tmrDelay_ms(10);
lcdCmdWr ( LCD_ALL_POWER_OFF|0x04|0x02 );
tmrDelay_ms(10);
lcdCmdWr ( LCD_ALL_POWER_OFF|0x04|0x02|0x01 );
tmrDelay_ms(10);
//lcdCmdWr ( LCD_ALL_POINT_OFF );
lcdCmdWr ( LCD_DISPLAY_ON );
lcdCmdWr ( LCD_START_LINE );
lcdCmdWr ( LCD_PAGE_ADDRESS | 0x07 );
lcdCmdWr ( LCD_COLUMN_ADDRESS_HI ); //column h
lcdCmdWr ( LCD_COLUMN_ADDRESS_LO ); //column
}
/*-------------------------------------------------------------
* lcdCls
*
* Description : LCD screen clear
* Arguments : null
* Return : null
* Notes :
-------------------------------------------------------------*/
void lcdCls( void ) // clear screen
{
unsigned char ct,cb;
for(ct=0;ct<8;ct++)
{
lcdCmdWr ( LCD_PAGE_ADDRESS | ct ) ; // page adderss set
lcdCmdWr ( LCD_COLUMN_ADDRESS_HI );
lcdCmdWr ( LCD_COLUMN_ADDRESS_LO );
for( cb = 0 ; cb < 128 ; cb++ ) lcdDatWr( 0 );
}
LCD_Cursor=0; //LCD_Cursor Reset
}
/*-------------------------------------------------------------
* lcdClsLine
*
* Description : LCD cursor line clear
* Arguments : null
* Return : null
* Notes :
-------------------------------------------------------------*/
void lcdClsLine( void ) // clear screen
{
unsigned char cb,pg;
if(LCD_Cursor >= 0x40 ) LCD_Cursor =0;
pg = ((LCD_Cursor >> 3) & 0x06 ) | LCD_PAGE_ADDRESS;
lcdSetXY(0,pg);
for(cb=0;cb<128;cb++) lcdDatWr (0);
}
/*-------------------------------------------------------------
* lcdSetXY
*
* Description : LCD X Y cursor set
* Arguments : x = column, y = page
* Return : null
* Notes :
-------------------------------------------------------------*/
void lcdSetXY ( unsigned char x, unsigned char y ) // LCD SET xy
{
lcdCmdWr( y ); // page adderss set
lcdCmdWr( ( x >> 4 ) | LCD_COLUMN_ADDRESS_HI );
lcdCmdWr( x & 0x0f );
}
//*****************************************************************
//* Application Functions *
//*****************************************************************
/*=================================================================
END OF PROGRAM LIST
=================================================================*/