?? 1602串.bak
字號:
//1602串口顯示不需判別忙信號//
#include"AT89X51.H"
#define uchar unsigned char
#define ufloat unsigned float
sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^2;
sbit CLK=P2^3;
sbit Clear=P2^4;
sbit LCD_Data=P2^5;
char a[]={'1','q','w','e','f','s','c','f','s','c','v'};
char b[]={'0','1','2','3','4','5','6','7','8','9'};
int h,m,s,count=1;
void delay(unsigned char time)
{
uchar i,k;
for(i=time;i>0;i--)
for(k=248;k>0;k--) ;
}
/////將一個字節轉換成數據流/////////////
void TransBit(uchar WCLCD) //char->bit
{
int i;
// CLK=0;
Clear=1; //CLK上升沿時輸出全為零
for(i=0;i<8;i++) //數據流處理
{
LCD_Data=WCLCD&0x80;
CLK=0; ////CLK下降沿時讀取數據
delay(2);
CLK=1;
WCLCD<<=1;
}
}
////////寫指令////////
void WriteCommandLCD(uchar WDLCD)
{
TransBit(WDLCD);
LCD_RS=0;
LCD_RW=0;
LCD_E=0;
LCD_E=0;
LCD_E=1;
}
////////寫數據////////
void WriteDataLCD(uchar WDLCD)
{
TransBit(WDLCD);
LCD_RS=1;
LCD_RW=0;
LCD_E=0;
LCD_E=0;
LCD_E=1;
}
/////按指定位置顯示一個字符X不能大于15,Y不能大于1/////
void DisplayOneChar(uchar X,uchar Y,uchar Num)
{
Y&=0x01;
X&=0x0F; //限制X不能大于15,Y不能大于1
if(Y) X+=0xc0; //當要顯示第二行時地址碼+0xc0;
else X+=0x80;
WriteCommandLCD(X); //發送地址碼
WriteDataLCD(Num);
}
/////按指定位置顯示一串字符/////
void DisplayListChar(uchar X,uchar Y,uchar *DData)
{
uchar ListLength;
ListLength=0;
while(DData[ListLength]>0x20) //若到達字串尾則退出
{
if(X<=15) //X坐標應小于15
{
DisplayOneChar(X,Y,DData[ListLength]); //顯示單個字符
ListLength++;
++X;
}
}
}
///顯示數字////
void DisplayNumChar(uchar X,uchar Y,int Num,char length)
{
char i;
int e=1,num;
num=Num;
for(i=0;i<length-1;i++)
{
e*=10;
}
for(i=0;i<length;i++)
{
if(X<=15)
{
DisplayOneChar(X,Y,b[(num/e)]);
X++;
num-=(num/e)*e;
e/=10;
}
}
}
//////顯示光標程序////////
void LocateXY(uchar X,uchar Y)
{ uchar temp;
Y&=0x01;
X&=0x0F; //限制X不能大于15,Y不能大于1
if(Y) X+=0xc0; //當要顯示第二行時地址碼+0xc0;
else X+=0x80;
temp=X;
WriteCommandLCD(temp);
}
void LCDInit(void) //LCM初始化
{
delay(3);
WriteCommandLCD(0x38); //顯示模式設置
delay(3);
WriteCommandLCD(0x38);
delay(3);
WriteCommandLCD(0x38);
delay(3);
WriteCommandLCD(0x38);
delay(3);
WriteCommandLCD(0x0f);//整體顯示的開,光標開,光標是否閃爍,
delay(3);
WriteCommandLCD(0x01);
delay(3);
WriteCommandLCD(0x06);
}
void main(void)
{
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
ET0=1;
EA=1;
TR0=0;
LCDInit();
CLK=1;
//DisplayListChar(8,1,"time");
DisplayOneChar(1,0,':');
DisplayOneChar(13,0,':');
// LocateXY(12,1);
while(1);
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
// DisplayListChar(8,1,"time");
// DisplayOneChar(10,0,':');
// DisplayOneChar(13,0,':');
count++;
if(count==1000)
{
s++;
count=1;
if(s==59)
{
m++;
s=0;
if(m==59)
{
h++;
m=0;
if(h==12)
h=0;
}
}
DisplayNumChar(8,0,h,2);
DisplayNumChar(11,0,m,2);
DisplayNumChar(14,0,s,2);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -