|
調了很長時間,才弄好。主要是串口通信,跟串口助手來進行調試的,程序里面有液晶顯示的程序,可以跟串口助手進行對比。液晶是串行顯示。
#include "stc12c5a60s2.h"
#define uchar unsigned char
#define uint unsigned int
uchar tmp;
uint count;
sbit rs = P3^5;
sbit rw = P3^6;
sbit en = P3^4;
uchar str[]="000000";
uchar code tab[]={
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 sendb(uchar byte)
{
uchar i;
for(i=0;i<8;i++)
{
en=0;
byte=byte<<1;
rw = CY;
en = 1;
en = 0;
}
}
uchar reedbyte(void)
{
uchar i,temp1,temp2;
temp1 = 0;
temp2 = 0;
for(i=0;i<8;i++)
{
temp1 = temp1<<1;
en=0;
en=1;
en=0;
if(rw)temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
en=0;
en=1;
en=0;
if(rw)temp2++;
}
return((0xf0&temp1)+(0x0f&temp2));
}
void lcdbusy()
{
do sendb(0xfc);
while(0x80&reedbyte());
}
void writecmd(uchar byte)
{
rs=1;
lcdbusy();
sendb(0xf8);
sendb(0xf8&byte);
sendb(0xf8&byte<<4);
rs=0;
}
void writedata(uchar byte)
{
rs=1;
lcdbusy();
sendb(0xfa);
sendb(0xf8&byte);
sendb(0xf8&byte<<4);
rs=0;
}
void delaylcd(uint ms)
{
uchar us,usn;
while(ms!=0)
{
usn=2;
while(usn!=0)
{
us=0xf5;
while(us!=0)
{
us--;
};
usn--;
}
ms--;
}
}
void lcdlnit()
{
writecmd(0x30);
writecmd(0x03);
writecmd(0x0c);
writecmd(0x01);
writecmd(0x06);
}
void lcdtxt()
{
uchar i;
writecmd(0x30);
writecmd(0x80);
for(i=0;i<64;i++)
writedata(0x20);
}
void write(uchar row,uchar col,uchar *puts)
{
writecmd(0x30);
writecmd(tab[8*row+col]);
while(*puts!='\0')
{
if(col==8)
{
col='0';
row++;
}
if(row==4)row='0';
writecmd(tab[8*row+col]);
writedata(*puts);
puts++;
writedata(*puts);
puts++;
col++;
}
}********完整在附件里
|
-
-
串口通信.rar
2019-7-30 11:26 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
28.71 KB, 下載次數: 42, 下載積分: 黑幣 -5
評分
-
查看全部評分
|