?? 1602.c.bak
字號:
#include <at89x51.h>
#include <wendu.h>
#include <daojishi.h>
sbit LcdRs = P2^0;
sbit LcdRw = P2^1;
sbit LcdEn = P2^2;
#define DBPort P0
unsigned char code tab[]={'0','1','2','3','4','5','6','7','8','9'}; //1602液晶顯示代碼表
//內部等待函數**************************************************************************
unsigned char LCD_Wait(void)
{
LcdRs=0;
LcdRw=1; //_nop_();
LcdEn=1; //_nop_();
LcdEn=0;
return DBPort;
}
//向LCD寫入命令或數據************************************************************
#define LCD_COMMAND 0 // Command
#define LCD_DATA 1 // Data
void LCD_Write(bit style, unsigned char input)
{
LcdEn=0;
LcdRs=style;
LcdRw=0; //_nop_();
DBPort=input; //_nop_();//注意順序
LcdEn=1; //_nop_();//注意順序
LcdEn=0; //_nop_();
LCD_Wait();
}
void LCD_Initial() //初始化LCD************************
{
LcdEn=0;
LCD_Write(LCD_COMMAND,0x38); //8位數據端口,2行顯示,5*7點陣
LCD_Write(LCD_COMMAND,0x38);
LCD_Write(LCD_COMMAND,0x0c); //開啟顯示, 無光標
LCD_Write(LCD_COMMAND,0x01); //清屏
LCD_Write(LCD_COMMAND,0x06); //AC遞增, 畫面不動
}
void GotoXY(unsigned char x, unsigned char y)
{
if(y==0)
LCD_Write(LCD_COMMAND,0x80|x);
if(y==1)
LCD_Write(LCD_COMMAND,0x80|(x-0x40));
}
void Print(unsigned char *str)
{
while(*str!='\0')
{
LCD_Write(LCD_DATA,*str);
str++;
}
}
unsigned char TempBuffer[10];
void IntToStr( unsigned char *str, unsigned char n)
{
unsigned char a[5]; char i, j;
daojishi();
a[0]=buffer[0] ; //取得整數值到數組
a[1]=buffer[1] ;
a[2]=':' ;
a[3]=buffer[2] ;
a[4]=buffer[3] ;
for(i=0; i<5; i++) //轉成ASCII碼
{if (i!=2) a[i]=a[i]+'0'; }
for(i=0; a[i]=='0' && i<=3; i++);
for(j=5-n; j<i; j++) //填充空格
{ *str=' '; str++; }
for(; i<5; i++)
{ *str=a[i]; str++; } //加入有效的數字
*str='\0';
}
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
unsigned char tep[10];
void charToStr( unsigned char *str, unsigned char n)
{
unsigned char a[5]; char i, j,t;
t= ReadTemperature() ;
// if(sflag==1)
a[0]=' '; //取得整數值到數組
a[1]=(t%100)/10;
a[2]=(t%100)%10;
a[3]=0xdf;
a[4]='c';
for(i=1; i<3; i++) //轉成ASCII碼
a[i]=a[i]+'0';
for(i=0; a[i]=='0' && i<=3; i++);
for(j=5-n; j<i; j++) //填充空格
{ *str=' '; str++; }
for(; i<5; i++)
{ *str=a[i]; str++; } //加入有效的數字
*str='\0';
}
main()
{
unsigned int Count = 0;
LCD_Initial();
GotoXY(0,0);
Print("temp: ");
GotoXY(0,1);
Print("time: ");
while(1)
{ IntToStr(&TempBuffer[0],5);
GotoXY(8,1);
Print(&TempBuffer[0]);
Delay1ms(100);
charToStr(&tep[0],5);
GotoXY(8,0);
Print(&tep[0]);
Delay1ms(100);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -