Ds3231+12864液晶顯示AT89C51帶溫度功能的時鐘程序
Ds3231+12864液晶顯示AT89C51帶溫度功能的時鐘程序。
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS=P2^6;
sbit LCD_RW=P2^5;
sbit LCD_EN=P2^4;
sbit LCD_PSB=P2^3;
sbit DQ=P3^7; //18b20
sbit SDA=P1^4; //ds32321 //模擬I2C數(shù)據(jù)傳送位SDA
sbit SCL=P1^3; //模擬I2C時鐘控制位SCL
//
////
////
////
////
sbit K1=P3^2;
sbit K2=P3^3;
sbit K3=P3^4;
sbit K4=P3^5;
//定義變量
uchar numbr[10]="0123456789"; //字模
uchar dis4[]=" "; // 第四行顯示 自己添加
uchar t[]=" . ℃" ; //18b20
uint sdata,xiaoshu1,xiaoshu2; //整數(shù)、小數(shù)1位、小數(shù)2位
bit fg=1; //溫度正負(fù)標(biāo)志
uchar tempL=0,tempH=0; // 變量
uchar year,month,date,hour,min,sec; // ds3231
uchar a[]="2011年22月33日";
uchar b[]="11時22分33秒";
///函數(shù)
/
void write_cmd(uchar cmd)
{
LCD_RS=0;
LCD_RW=0;
LCD_EN=0;
P0=cmd;
delay1ms(5);
LCD_EN=1;
delay1ms(5);
LCD_EN=0;
}
void lcd_pos(uchar X, uchar Y)
{
ucharpos;
if(X== 0)
{
X= 0x80;
}
elseif(X == 1)
{
X= 0x90;
}
elseif(X == 2)
{
X= 0x88;
}
elseif(X == 3)
{
X= 0x98;
}
pos= X + Y;
write_cmd(pos); //顯示地址
}
void write_dat(uchar dat)
{
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=dat;
delay1ms(5);
LCD_EN=1;
delay1ms(5);
LCD_EN=0;
}
void lcd_init()
{ uinti;
LCD_PSB=1; //并口方式