📄 lcd.c
字号:
#include<io8515.h>
//*********************************************
//**the data port,use the port a,if donot change it
#define Db PORTA
#define DbIn PINA
#define DbDir DDRA
//** DB0--PA0 DB1--PA1 DB2--PA2 DB3--PA3 DB4--PA4
//** DB5--PA5 DB6--PA6 DB7--PA7
//*****************************************************
//**the contral port,use the port c,if not change it
#define ContrPort PORTC
#define ContrIn PINC
#define ContrDir DDRC
//**D_I--PC0
#define D_I 0b00000001
//**R_W--PC1
#define R_W 0b00000010
//**E--PC4
#define E 0b00010000
//**CS1--PC7
#define CS1 0b10000000
//**CS2--PC6
#define CS2 0b01000000
//**RESET--PC5
#define RESET 0b00100000
#define All 0b11110011
//*******************************************************
/* 1 vss 2 vdd 3 vo 4 d\i 5 r\w 6 e 7 db0
8 db1 9 db2 10 db3 11 db4 12 db5 13 db6 14 db7
15 cs1 16 cs2 17 reset 18 vee 19 a 20 k */
//*********************************************************
#include"C:\icc\project\LCD\code.c"
void WriInsn(unsigned char command)
{ unsigned char state;
ContrDir=ContrDir|All;//set the direction out
ContrPort=ContrPort&~D_I;//D_I=0
ContrPort=ContrPort|R_W;//R_w=1
DbDir=0b00000000;//data input module
do
{ContrPort=ContrPort|E;//E=1,read the status;
state=DbIn;//status trans to state
ContrPort=ContrPort&~E;}//E=0,
while(state&0b10000000);//if "busy"
ContrPort=ContrPort&~R_W;//R_w=0
DbDir=0b11111111;//data output module
Db=command;
ContrPort=ContrPort|E;//E=1
ContrPort=ContrPort&~E;//E=0,
}
//*********************************************************
void WriData(unsigned char WriData)
{ unsigned char state;
ContrDir=ContrDir|All;//set the direction out
ContrPort=ContrPort&~D_I;//D_I=0
ContrPort=ContrPort|R_W;//R_w=1
DbDir=0b00000000;//data input module
do
{ContrPort=ContrPort|E;//E=1,read the status;
state=DbIn;//status trans to state
ContrPort=ContrPort&~E;}//E=0,
while(state&0b10000000);//if "busy"
ContrPort=ContrPort|D_I;//D_I=1
ContrPort=ContrPort&~R_W;//R_w=0
DbDir=0b11111111;
Db=WriData;
ContrPort=ContrPort|E;//E=1
ContrPort=ContrPort&~E;//E=0,
}
/************************************************************
unsigned char Readdata(void)
{ unsigned char state,ReadData;
ContrDir=ContrDir|All;//set the direction out
ContrPort=ContrPort&~D_I;//D_I=0
ContrPort=ContrPort|R_W;//R_w=1
DbDir=0b00000000;//data input module
do
{ContrPort=ContrPort|E;//E=1,read the status;
state=DbIn;//status trans to state
ContrPort=ContrPort&~E;}//E=0,
while(state&0b10000000);//if "busy"
ContrPort=ContrPort|D_I;//D_I=1
ContrPort=ContrPort|E;//E=1
ReadData=PINA;
ContrPort=ContrPort&~E;//E=0,
DbDir=0b11111111;
return(ReadData);
} */
//************************************************************
//**clear CGRAM**********
void ClearRam(void)
{
unsigned char Clear_page,Clear_Y;
//***************************************************
ContrPort=ContrPort|CS1; //cs1=1
ContrPort=ContrPort&~CS2;//cs2=0
Clear_page=8;
while(Clear_page)
{
Clear_Y=64;
while(Clear_Y)
{
WriInsn((Clear_page-1)+0b10111000);
WriInsn((Clear_Y-1)+0b01000000);
WriData(0x00);
Clear_Y--;
}
Clear_page--;
}
//***************************************************
ContrPort=ContrPort&~CS1; //cs1=0
ContrPort=ContrPort|CS2;//cs2=1
Clear_page=8;
while(Clear_page)
{
Clear_Y=64;
while(Clear_Y)
{
WriInsn((Clear_page-1)+0b10111000);
WriInsn((Clear_Y-1)+0b01000000);
WriData(0x00);
Clear_Y--;
}
Clear_page--;
}
}
//********************************************************
//**setup CGRAM**********************
void WriteCgram(unsigned char DataSequent, unsigned char Point)
{
unsigned char NumPage; //the data page
unsigned NumCs1,NumCs2;//chip select
unsigned NumTemp01,i,j;
if(DataSequent<8)
{
NumPage=0;
if(DataSequent<4)
{NumCs1=1;
NumCs2=0;
NumTemp01=16*DataSequent;
}
else
{NumCs1=0;
NumCs2=1;
NumTemp01=16*(DataSequent-4);
}
}
else if((DataSequent)<16&&(DataSequent>7))
{
NumPage=2;
if(DataSequent<12)
{NumCs1=1;
NumCs2=0;
NumTemp01=16*(DataSequent-8);
}
else
{NumCs1=0;
NumCs2=1;
NumTemp01=16*(DataSequent-12);
}
}
else if((DataSequent>15)&&(DataSequent<24))
{
NumPage=4;
if(DataSequent<20)
{NumCs1=1;
NumCs2=0;
NumTemp01=16*(DataSequent-16);
}
else
{NumCs1=0;
NumCs2=1;
NumTemp01=16*(DataSequent-20);
}
}
else if((DataSequent>23)&&(DataSequent<32))
{
NumPage=6;
if(DataSequent<28)
{NumCs1=1;
NumCs2=0;
NumTemp01=16*(DataSequent-24);
}
else
{NumCs1=0;
NumCs2=1;
NumTemp01=16*(DataSequent-28);
}
}
if(NumCs1)
{ContrPort=ContrPort|CS1;}
else
{ContrPort=ContrPort&~CS1;}
if(NumCs2)
{ContrPort=ContrPort|CS2;}
else
{ContrPort=ContrPort&~CS2;}
NumPage=NumPage&0b00000111;
NumPage=NumPage|0b10111000;
NumTemp01=NumTemp01&0b00111111;
NumTemp01=NumTemp01|0b01000000;
WriInsn(NumPage);//set the page
WriInsn(NumTemp01);// y address
i=16;j=0;
while(i)
{
WriData(TAB[Point][j]);
i--;
j++;
}
WriInsn(NumPage+1);//set the page
WriInsn(NumTemp01);// y address
i=16;
while(i)
{
WriData(TAB[Point][j]);
i--;
j++;
}
}
//**************************************************
//开始显示
void StartDiaplay(void)
{
//***********use the left hand number******
PORTC=PORTC|~0b01111111; //cs1=1
PORTC=PORTC&~0b01000000; //cs2=0
//****************************************
WriInsn(0b11000000);//the first line
PORTC=PORTC&0b01111111; //cs1=0
PORTC=PORTC|0b01000000; //cs2=1
WriInsn(0b11000000);//the first line
PORTC=PORTC|~0b01111111; //cs1=1
PORTC=PORTC&~0b01000000; //cs2=0
WriInsn(0b00111111);//start
WriInsn(0b00111111);
PORTC=PORTC&0b01111111; //cs1=0
PORTC=PORTC|0b01000000; //cs2=1
WriInsn(0b00111111);//start
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -