这是1602程序
//**********************Disigned By F H X****************************//
//***********************LCD1602é¨Ãè3ìDò*****************************//
//*****1 LCDÃ|¼ì2aoˉêy £o¶ÔLCD½øDDD′Ãüáî D′êy¾YÇ° ¼ì2aLCDêÇ·ñÃ|******//
//*****2 LCDD′Ãüáîoˉêy £o¶ÔLCDD′Ãüáî*********************************//
//*****3 LCD3õê¼»ˉoˉêy £oLCD3õê¼»ˉ***********************************//
//*****4 LCDéè3õê¼×ø±ê £oéèÖÃLCD3õê¼×ø±ê£¨x£¬y£©*********************//
//*****5 LCDD′êy¾Yoˉêy £o¶ÔLCDD′êy¾Y*********************************//
//*****6 LCDÏÔê¾×Ö·û′® £oÔúLCDéÏÏÔê¾×Ö·û′®***************************//
//*****7 LCDÏÔê¾êy¾Y £oÔúLCDéÏÏÔê¾DèòaμÄêy¾Y***********************//
//*****8 LCDÏÔê¾±¨¾ˉÖμ £oÔúLCD£¨x£¬y£©ÏÔê¾±¨¾ˉéÏÏÂÏT*****************//
//*****9 ×Ô¶¨òå×Ö·ûÏÔê¾£oÔúLCDéÏÏÔê¾×Ô¶¨òåμÄ·ûoÅ¡°¡ü¡±******************//
//****10 éèÖýçÃæ3õê¼»ˉ£o½øèëζ豨¾ˉÖμéèÖýçÃæ**********************//
#include "reg52.h"
#define LCD1602_DB P0
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit LCD1602_RS = P1^0;
sbit LCD1602_RW = P1^1;
sbit LCD1602_E = P1^5;
//sbit LCD1602_RS = P2^6;
//sbit LCD1602_RW = P2^5;
//sbit LCD1602_E = P2^7;
void InitLcd1602();
void LcdShowStr(uchar x,uchar y,uchar *str);
void LcdShowDat(uchar x,uchar y,uchar num);
void DisplayLimit(uchar x,uchar y,char dat);
void Display_laba();
uchar code buff[]="0123456789";
uchar code user[]={0x04,0x0E,0x15,0x04,0x04,0x04,0x04,0x04};
uchar code user2[]={
0x01,0x03,0x07,0x1F,0x1F,0x07,0x03,0x01,
0x00,0x02,0x09,0x05,0x15,0x05,0x09,0x02,
};
extern uchar High;
extern uchar Low;
extern uchar cnt;
/**********¼ì2aLcdêÇ·ñÃ|**********/
void LcdWriteReady()
{
uchar sta;
LCD1602_DB=0xFF;
LCD1602_RS=0;
LCD1602_RW=1;
do
{
LCD1602_E=1;
sta=LCD1602_DB;
LCD1602_E=0;
}while(sta&0x80);
}
/**********LcdD′Ãüáîoˉêy**********/
void LcdWriteCmd(uchar cmd)
{
LcdWriteReady();
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_DB=cmd;
LCD1602_E=1;
LCD1602_E=0;
}
/**********Lcd3õê¼»ˉoˉêy**********/
void InitLcd1602()
{
LcdWriteCmd(0x38);
LcdWriteCmd(0x0c);
LcdWriteCmd(0x06);
LcdWriteCmd(0x01);
LcdShowStr(0,0,"H: C L: C");
LcdShowStr(0,1,"TEMP: C");
LcdShowDat(4,0,0xDF);
LcdShowDat(14,0,0xDF);
LcdShowDat(14,1,0xDF);
DisplayLimit(2,0,High);
DisplayLimit(12,0,Low);
LcdShowStr(7,0," ");
cnt=0;
}
/**********LcdéèÖÃ3õê¼1a±ê**********/
void LcdSetCursor(uchar x,uchar y)
{
uchar addr;
if(y==0)
{
addr=0x00+x;
}
else
{
addr=0x40+x;
}
LcdWriteCmd(addr|0x80);
}
/**********LcdD′êy¾Yoˉêy**********/
void LcdWriteDat(uchar dat)
{
LcdWriteReady();
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_DB=dat;
LCD1602_E=1;
LCD1602_E=0;
}
/**********LcdÏÔê¾×Ö·û′®oˉêy**********/
void LcdShowStr(uchar x,uchar y,uchar *str)
{
LcdSetCursor(x,y);
while(*str!='\0')
{
LcdWriteDat(*str++);
}
}
/**********LcdÏÔê¾êy¾Yoˉêy**********/
void LcdShowDat(uchar x,uchar y,uchar num)
{
LcdSetCursor(x,y);
LcdWriteDat(num);
}
//**********ÏÔê¾Î¶豨¾ˉÖμ**********/
void DisplayLimit(uchar x,uchar y,char dat)
{
uchar ge,shi;
ge=dat%10;
shi=dat/10;
if(shi==0)
LcdShowDat(x,y,' ');
else
LcdShowDat(x,y,buff[shi]);
LcdShowDat(x+1,y,buff[ge]);
}
/**********ÏÔê¾×Ô¶¨òå×Ö·û**********/
void Display_user(uchar x)
{
uchar i;
LcdWriteCmd(0x40); //éèÖÃCGRAMÆeê¼μØÖ·
for(i=0;i<=7;i++)
{
LcdWriteDat(user[i]); //½«×Ô¶¨òå×Ö·ûD′èëCGRAM
}
LcdWriteCmd(0x80+0x40+x); //μú¶tDDμúx¸öλÖÃÏÔê¾
LcdWriteDat(0x00);
}
void Display_laba()
{
uchar i,j;
LcdWriteCmd(0x48);
for(i=0;i<=15;i++)
{
LcdWriteDat(user2[i]);
}
for(j=0;j<=1;j++)
{
LcdWriteCmd(0x80+7+j);
LcdWriteDat(0x01+j);
}
}
/**********×î′óÖμ×îD¡ÖμéèÖà 3õê¼»ˉ½çÃæ**********/
void InitMaxMin()
{
LcdWriteCmd(0x38);
LcdWriteCmd(0x0c);
LcdWriteCmd(0x06);
LcdWriteCmd(0x01);
LcdShowStr(0,0,"H: C L: C");
LcdShowDat(4,0,0xDF);
LcdShowDat(14,0,0xDF);
DisplayLimit(2,0,High);
DisplayLimit(12,0,Low);
} |