|
仿真.png (155.01 KB, 下載次數(shù): 29)
下載附件
lcd一直黑屏
2020-5-12 14:02 上傳
#include"12864.h"
#include"reg52.h"
#include <intrins.h>
sbit CS=P2^5;
sbit SID=P2^6;
sbit SCLK=P2^7;
unsigned char code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
};
void SendByte(unsigned char Dbyte)
{
unsigned char i;
for(i=0;i<8;i++)
{
SCLK = 0;
Dbyte=Dbyte<<1;
SID = CY;
SCLK = 1;
SCLK = 0;
}
}
unsigned char ReceiveByte(void)
{
unsigned char i,temp1,temp2;
temp1=temp2=0;
for(i=0;i<8;i++)
{
temp1=temp1<<1;
SCLK = 0;
SCLK = 1;
SCLK = 0;
if(SID) temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
SCLK = 0;
SCLK = 1;
SCLK = 0;
if(SID) temp2++;
}
return ((0xf0&temp1)+(0x0f&temp2));
}
void CheckBusy( void )
{
do SendByte(0xfc);
while(0x80&ReceiveByte());
}
void WriteCommand( unsigned char Cbyte )
{
CS = 1;
CheckBusy();
SendByte(0xf8);
SendByte(0xf0&Cbyte);
SendByte(0xf0&Cbyte<<4);
CS = 0;
}
void WriteData( unsigned char Dbyte )
{
CS = 1;
CheckBusy();
SendByte(0xfa);
SendByte(0xf0&Dbyte);
SendByte(0xf0&Dbyte<<4);
CS = 0;
}
void LcmInit( void )
{
WriteCommand(0x30);
WriteCommand(0x03);
WriteCommand(0x0c);
WriteCommand(0x01);
WriteCommand(0x06);
}
void Location_xy_12864(unsigned char x,unsigned char y)
{
switch(x)
{
case 0:
x=0x80;break;
case 1:
x=0x90;break;
case 2:
x=0x88;break;
case 3:
x=0x98;break;
default:
x=0x80;
}
y=y&0x07;
WriteCommand(0x30);
WriteCommand(y+x);
WriteCommand(y+x);
}
void LcmClearTXT( void )
{
unsigned char i;
WriteCommand(0x30);
WriteCommand(0x80);
for(i=0;i<64;i++)
WriteData(0x20);
Location_xy_12864(0,0);
}
//??ê???
void PutStr(unsigned char row,unsigned char col,unsigned char *puts)
{
WriteCommand(0x30);
WriteCommand(AC_TABLE[8*row+col]);
while(*puts != '\0')
{
if(col==8)
{
col=0;
row++;
}
if(row==4) row=0;
WriteCommand(AC_TABLE[8*row+col]);
WriteData(*puts);
puts++;
if(*puts != '\0')
{
WriteData(*puts);
puts++;
col++;
}
}
}
void Delay(unsigned int t)
{
unsigned int m,n;
for(m=0;m<t;m++);
for(n=0;n<10;n++);
}
|
|