📄 lcd.c
字号:
/***************************************************************
Copyright(c) Vitro Light All Rights Reserved.
Author: Tenghan
Filename: LCD.c
Description:
This file define the main function of a 12864 LCD.
*****************************************************************
$File: //LCD.c $
$Revision: #1 $
$Date: 2007/09/15 $
****************************************************************/
#include <reg51.h>
#include "type_51.h"
#include "delay.h"
#include "LCD.h"
// Define
sbit CS = P2^0 ;
sbit SID = P2^1 ; //Serial data
sbit SCLK = P2^2 ; //Serial clock
sbit PSB = P2^3 ; // Set PSB 0 is serial control
/*=============================================================================
Function Name: LCDInitial
Description: Initial LCD.
Input: None
Return: None
Note:
=============================================================================*/
void LCDInitial(void)
{
delaynms(10); // Wait to power on, LCM
PSB=0; //Serial control mode
CS=1; // Chip enable in serial mode
WriteCommand(BITBUS8 | BASICSET); // 0011 8 bit interface, 0000 basic instruction
WriteCommand(DISPLAYON); // 1100 display on, cursor off, blink off
WriteCommand(RESETAC); // Clear screen, set DDRAM AC to 0
}
/*=============================================================================
Function Name: WriteCommand
Description: write command.
Input: command
Return: None
Note: Send the sync control firs, then send the highest 4 bits, lowest 4 bits
=============================================================================*/
void WriteCommand(UINT8 Command)
{
UINT8 HCom,LCom;
HCom=Command & 0xf0; //get the high 4 bits
LCom=(Command<<4) & 0xf0; // Low 4 bits
sendbyte(SERIALWCOM); //Write command sync control
delaynms(2); //Delay here is must
sendbyte(HCom); //send the highest 4 bits
delaynms(1);
sendbyte(LCom);
delaynms(1);
}
/*=============================================================================
Function Name: WriteData
Description: write Data.
Input: Data
Return: None
Note:
=============================================================================*/
void WriteData(UINT8 Data)
{
UINT8 Hdata,Ldata;
Hdata=Data&0xf0;
Ldata=(Data<<4)&0xf0;
sendbyte(SERIALWDATA); //Write Data
delaynms(1); //Delay here is must
sendbyte(Hdata);
//delaynms(1);
sendbyte(Ldata);
//delaynms(1);
}
/*=============================================================================
Function Name: sendbyte
Description: send byte.
Input: byte to be sent
Return: None
Note: send bit one by one
=============================================================================*/
void sendbyte(UINT8 bbyte)
{
UINT8 i;
for(i=0;i<8;i++)
{
SID=bbyte & 0x80; //Get the highest bit
SCLK=1;
SCLK=0;
bbyte<<=1; //Shift left
}
}
/*=============================================================================
Function Name: LCDBlack
Description: lcd test, screen set to black at graph mode.
Input: None
Return: None
Note:
=============================================================================*/
void LCDBlack(void)
{
UINT8 i,j;
for(i=0;i<32;i++)
{
WriteCommand(0x80 + i); //Set Vertical point
WriteCommand(0x80); // Set Horizon point, horizon will automatic increase 1 after write it.
for(j=0;j<16;j++)
WriteData(0xff);
}
for(i=0;i<32;i++)
{
WriteCommand(0x80 + i);
WriteCommand(0x88);
for(j=0;j<16;j++)
WriteData(0xff);
}
}
/*=============================================================================
Function Name: LCDClear
Description: LCD Clear, clear screen at graph mode.
Input: None
Return: None
Note:
=============================================================================*/
void LCDClear(void)
{
UINT8 i,j;
for(i=0;i<32;i++)
{
WriteCommand(0x80 + i); //Set Vertical point
WriteCommand(0x80); // Set Horizon point, horizon will automatic increase 1 after write it.
for(j=0;j<16;j++)
WriteData(0x00);
}
for(i=0;i<32;i++)
{
WriteCommand(0x80+i);
WriteCommand(0x88);
for(j=0;j<16;j++)
WriteData(0x00);
}
}
/*=============================================================================
Function Name: Disp_Img
Description: Display Image.
Input: None
Return: None
Note:
=============================================================================*/
void Disp_Img(UINT8 *Img)
{
UINT8 i, j;
UINT16 k =0 ;
for(i=0;i<32;i++)
{
WriteCommand(0x80+i);
WriteCommand(0x80);
for(j=0;j<16;j++)
{
WriteData(Img[k++]);
}
}
for(i=0;i<32;i++)
{
WriteCommand(0x80+i);
WriteCommand(0x88);
for(j=0;j<16;j++)
{
WriteData(Img[k++]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -