?? lcd.c
字號:
//******************************************************************************
// File Name : LCD.c
// Author : Steaven
// Created : 2008-07-27
// Modified :
// Revision : V0.0
//******************************************************************************
//PIN DESCRIPTION
//01 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
//GND VCC V0 RS RW EN D0 D1 D2 D3 D4 D5 D6 D7 CS1 CS2 RST VEE BLA BLK
//GND +5V V0 PB0 PB1 PB2 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 PC6 PC5 PC7 VEE +5V GND
#include "iom16v.h"
#include "DataType.h"
#include "LCD.h"
#include "macros.h"
#define cLCD_X_MAX 64
#define cLCD_Y_MAX 128
//local functions declaration
void Set_DI(INT8U RS);
void Set_RW(INT8U RW);
void Set_EN(INT8U EN);
void Set_CS1(INT8U CS1);
void Set_CS2(INT8U CS2);
void Set_RST(INT8U RST);
void Set_Data(INT8U data);
void LCD_Command_DispOnOff(INT8U onoff);
void LCD_Command_SetStartLine(INT8U startline);
void LCD_Command_Set_X(INT8U x);
void LCD_Command_Set_Y(INT8U y);
void LCD_Command_WriteByte(INT8U data);
void LCD_Reset(void);
void LCD_Clear_Line(INT8U wStartLine,INT8U wEndLine);
void LCD_Init(void);
void WriteWord(INT8U const *disp,INT8U x,INT8U y);
void WriteCharacter(const INT8U *disp,INT8U x,INT8U y,INT8U cs);
void WritePIC(const INT8U *disp);
void LCD_Write_Char(INT8U y,INT8U x,const INT8U *pdata);
void LCD_Write_Dot(INT8U x,INT8U y);
void LCD_Write_Data(INT8U x,INT8U y,INT8U data);
void LCD_Write_Picture(INT8U x1,INT8U y1,INT8U x2,INT8U y2,const INT8U *pdata);
//******************************************************************************
// Function : Set_RS
// Input : RS - RS Control Line Level
// Output : none
// Description : LCD(1602) Low Level Interface Function
//******************************************************************************
void Set_DI(INT8U RS)
{
if(RS == 0)
{
PORTB &= ~0x01;
}
else
{
PORTB |= 0x01;
}
}
//******************************************************************************
// Function : Set_RW
// Input : RW - RW Control Line Level
// Output : none
// Description : Low Level Interface Function
//******************************************************************************
void Set_RW(INT8U RW)
{
if(RW == 0)
{
PORTB &= ~0x02;
}
else
{
PORTB |= 0x02;
}
}
//******************************************************************************
// Function : Set_EN
// Input : RW - RW Control Line Level
// Output : none
// Description : Low Level Interface Function
//******************************************************************************
void Set_EN(INT8U EN)
{
if(EN == 0)
{
PORTB &= ~0x04;
}
else
{
PORTB |= 0x04;
}
}
//******************************************************************************
// Function : Set_CS2
// Input : CS2 - CS2 Control Line Level
// Output : none
// Description : Low Level Interface Function
//******************************************************************************
void Set_CS2(INT8U CS2)
{
if(CS2 == 0)
{
PORTC &= ~0x20;
}
else
{
PORTC |= 0x20;
}
}
//******************************************************************************
// Function : Set_CS1
// Input : CS1 - CS1 Control Line Level
// Output : none
// Description : Low Level Interface Function
//******************************************************************************
void Set_CS1(INT8U CS1)
{
if(CS1 == 0)
{
PORTC &= ~0x40;
}
else
{
PORTC |= 0x40;
}
}
//******************************************************************************
// Function : Set_CS1
// Input : CS1 - CS1 Control Line Level
// Output : none
// Description : Low Level Interface Function
//******************************************************************************
void Set_RST(INT8U RST)
{
if(RST == 0)
{
PORTC &= ~0x80;
}
else
{
PORTC |= 0x80;
}
}
//******************************************************************************
// Function : Set_Data
// Input : data - Data Line Level
// Output : none
// Description : Low Level Interface Function
//******************************************************************************
void Set_Data(INT8U data)
{
PORTA = data;
}
//******************************************************************************
// Function : LCD_Command_DispOnOff
// Input : onoff = 1 -> LCD Display Enabled,else Disabled
// Output : none
// Description : Command Level Function,Display ONOFF Control
//******************************************************************************
void LCD_Command_DispOnOff(INT8U onoff)
{
Set_RW(0);
Set_DI(0);
Set_EN(0);
Set_Data(0x3E + onoff);
Set_EN(1);
Set_EN(0);
}
//******************************************************************************
// Function : LCD_Command_SetStartLine
// Input : startline - Display Start Line,See Specification
// Output : none
// Description : Command Level Function,Set Display Start Line
//******************************************************************************
void LCD_Command_SetStartLine(INT8U startline)
{
Set_RW(0);
Set_DI(0);
Set_EN(0);
Set_Data(0xC0 + startline);
Set_EN(1);
Set_EN(0);
}
//******************************************************************************
// Function : LCD_Command_Set_X
// Input : x - Display Row,from 0 to 7 for 128*64 LCD
// Output : none
// Description : Command Level Function,Set Operation X Address
//******************************************************************************
void LCD_Command_Set_X(INT8U x)
{
Set_RW(0);
Set_DI(0);
Set_EN(0);
Set_Data(0xB8 + x);
Set_EN(1);
Set_EN(0);
}
//******************************************************************************
// Function : LCD_Command_Set_Y
// Input : y - Display Column,from 0 to 63 for 128*64 LCD
// Output : none
// Description : Command Level Function,Set Operation Y Address
//******************************************************************************
void LCD_Command_Set_Y(INT8U column)
{
Set_RW(0);
Set_DI(0);
Set_EN(0);
Set_Data(0x40 + column);
Set_EN(1);
Set_EN(0);
}
//******************************************************************************
// Function : LCD_Command_WriteByte
// Input : data - Display Data
// Output : none
// Description : Command Level Function,Write Display Data to DDRAM
//******************************************************************************
void LCD_Command_WriteByte(INT8U data)
{
Set_RW(0);
Set_DI(1);
Set_EN(0);
Set_Data(data);
Set_EN(1);
Set_EN(0);
}
//******************************************************************************
// Function : LCD_Reset
// Input : none
// Output : none
// Description : Command Level Function,Soft RESET LCD Module
//******************************************************************************
void LCD_Reset(void)
{
Set_RST(0);
Set_RST(1);
}
//******************************************************************************
// Function : LCD_Init
// Input : none
// Output : none
// Description : Application Level Function,Init LCD
//******************************************************************************
void LCD_Init(void)
{
LCD_Reset();
LCD_Clear_Line(0,7);
LCD_Command_DispOnOff(1);
LCD_Command_SetStartLine(0);
}
//******************************************************************************
// Function : LCD_Clear_Line
// Input : startline,endline - Line Range to be Cleare
// Output : none
// Description : Command Level Function,Clear Screen Display
//******************************************************************************
void LCD_Clear_Line(INT8U startline,INT8U endline)
{
INT8U i,j;
for(i = startline;i <= endline;i++)
{
Set_CS1(1);
Set_CS2(1);
LCD_Command_Set_X(i);
LCD_Command_Set_Y(0);
for(j = 0;j < 64;j++)
{
LCD_Command_WriteByte(0x00);
}
}
}
//******************************************************************************
// Function : LCD_Write_Data
// Input : x in [0,7] and y in [0,127]
// Output : none
// Description : Command Level Function,在指定行列寫一個數據
//******************************************************************************
void LCD_Write_Data(INT8U x,INT8U y,INT8U data)
{
if(y < 64)
{
Set_CS1(1);
Set_CS2(0);
LCD_Command_Set_X(x);
LCD_Command_Set_Y(y);
}
else
{
Set_CS1(0);
Set_CS2(1);
LCD_Command_Set_X(x);
LCD_Command_Set_Y(y - 64);
}
LCD_Command_WriteByte(data);
}
//******************************************************************************
// Function : LCD_Write_Dot
// Input : x in [0,63] and y in [0,127]
// Output : none
// Description : Application Level Function,在LCD的指定象素位置描點,注意此函數
// 是覆蓋式描點,原位置的一個字節數據將被此點取代
//******************************************************************************
void LCD_Write_Dot(INT8U x,INT8U y)
{
INT8U x_address,y_address;
INT8U data = 0;
if((x < 64) && (y < 128))
{
x_address = x >> 3;
y_address = y;
LCD_Write_Data(x_address,y_address,data | (1 << (x % 8)));
}
}
//******************************************************************************
// Function : LCD_Write_Char
// Input : x in [0,3] and y in [0,15],disp - start address of display buffer
// Output : none
// Description : Application Level Function,在LCD的指定顯示單元顯示一個字符。
// 每個顯示單元默認為8*16點陣字體,對128*64點陣LCD,x最多顯示4行
// 字符,y最多顯示16個字符
//******************************************************************************
void LCD_Write_Char(INT8U x,INT8U y,const INT8U *disp)
{
INT8U i;
INT8U x_address;
INT8U y_address;
if((x < 4) && (y < 16))
{
for(i = 0;i < 8;i++)
{
x_address = x << 1;
y_address = (y << 3) + i;
LCD_Write_Data(x_address,y_address,*disp++);
}
for(i = 0;i < 8;i++)
{
x_address = (x << 1) + 1;
y_address = (y << 3) + i;
LCD_Write_Data(x_address,y_address,*disp++);
}
}
}
//******************************************************************************
// Function : LCD_Write_Word
// Input : x in [0,3] and y in [0,14],disp - start address of display buffer
// Output : none
// Description : Application Level Function,在LCD的指定顯示單元顯示一個中文。
// 每個顯示單元默認為16*16點陣字體,對128*64點陣LCD,x最多顯示4行
// 字符,y最多顯示16個字符,但不允許顯示半個漢字
//******************************************************************************
void LCD_Write_Word(INT8U x,INT8U y,const INT8U *disp)
{
INT8U i;
INT8U x_address;
INT8U y_address;
if((x < 4) && (y < 15))
{
for(i = 0;i < 16;i++)
{
x_address = x << 1;
y_address = (y << 3) + i;
LCD_Write_Data(x_address,y_address,*disp++);
}
for(i = 0;i < 16;i++)
{
x_address = (x << 1) + 1;
y_address = (y << 3) + i;
LCD_Write_Data(x_address,y_address,*disp++);
}
}
}
//******************************************************************************
// Function : LCD_Write_Picture
// Input : x in [0,7] and y in [0,127],
// x1_length - 縱向象素 y1_length - 橫向象素,x1_length必須為8的
// 整數倍,y1_length可以不必為8的整數倍。
// Output : none
// Description : Application Level Function,在LCD的指定區域顯示圖片
//******************************************************************************
void LCD_Write_Picture(INT8U x1,INT8U y1,INT8U x_length,INT8U y_length,const INT8U *pdata)
{
INT8U x_address;
INT8U y_address;
for(x_address = x1;x_address <= x1 + (x_length >> 3) - 1;x_address++)
{
for(y_address = y1;y_address < y1 + y_length;y_address++)
{
LCD_Write_Data(x_address,y_address,*pdata++);
}
}
}
//=========================END OF FILE=========================//
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -