c51实现万年历、温度与闹钟功能程序
/******************************************************************************/
/* 24C08.c*/
//调用方式如下:
//Write_One_Byte(0x10,0x04);
//k=Read_One_Byte(0x10);
/********** 函数定义 ************/
void Delay2408(unsigned int t) /*延时函数*/
{
while(t!=0)
t--;
}
void I2C_Start(void)
{
/*启动I2C总线的函数,当SCL为高电平时使SDA产生一个负跳变*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME);
SDA=0;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}
void I2C_Stop(void)
{
/*终止I2C总线,当SCL为高电平时使SDA产生一个正跳变*/
SDA=0;
SCL=1;
Delay2408(Delay2408_TIME);
SDA=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}
void SEND_0(void) /* SEND ACK */
{
/*发送0,在SCL为高电平时使SDA信号为低*/
SDA=0;
SCL=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}
void SEND_1(void)
{
/*发送1,在SCL为高电平时使SDA信号为高*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME);
SCL=0;
Delay2408(Delay2408_TIME);
}
bit Check_Acknowledge(void)
{
/*发送完一个字节后检验设备的应答信号*/
SDA=1;
SCL=1;
Delay2408(Delay2408_TIME/2);
F0=SDA;
Delay2408(Delay2408_TIME/2);
SCL=0;
Delay2408(Delay2408_TIME);
if(F0==1)
return FALSE;
return TRUE;
}
void WriteI2CByte(unsigned char b)reentrant
{
/*向I2C总线写一个字节*/
unsigned char i;
for(i=0;i<8;i++)
if((bSEND_1();
else
SEND_0();
}
unsigned char ReadI2CByte(void)reentrant
{
/*从I2C总线读一个字节*/
unsigned char b=0,i;
for(i=0;i<8;i++)
{
SDA=1; /*释放总线*/
SCL=1; /*接受数据*/
Delay2408(10);
F0=SDA;
Delay2408(10);
SCL=0;
if(F0==1)
{
b=b<1;
b=b|0x01;
}
else
b=b<1;
}
return b;
}
/**********以下为读写24c02的函数***********************************************/
void Write_One_Byte(unsigned char addr,unsigned char thedata)
{
bit acktemp=1;
/*write a byte to mem*/
I2C_Start();
WriteI2CByte(0xa0);
acktemp=Check_Acknowledge();
WriteI2CByte(addr); /*address*/
acktemp=Check_Acknowledge();
WriteI2CByte(thedata); /*thedata*/
acktemp=Check_Acknowledge();
I2C_Stop();
}
/******************************************************************************/
char Read_One_Byte(unsigned char addr)
{
bit acktemp=1;
unsigned char mydata;
/*read a byte from mem*/
I2C_Start();
WriteI2CByte(0xa0);
acktemp=Check_Acknowledge();
WriteI2CByte(addr);/*address*/
acktemp=Check_Acknowledge();
I2C_Start();
WriteI2CByte(0xa1);
acktemp=Check_Acknowledge();
mydata=ReadI2CByte();
acktemp=Check_Acknowledge();
return mydata;
I2C_Stop();
}
/******************************************************************************/
void Delay(int num)//延时函数
{
while(num--) ;
}
/*12864driver.c*/
/******************************************************************************/
void Delay12864(unsigned int t)//
{
unsigned int i,j;
for(i=0;i
for(j=0;j<10;j++);
}
}
/******************************************************************************/
void write_com(unsigned char cmdcode)//写命令到LCD
{
Di = 0;
RW = 0;
Lcd_Bus = cmdcode;
Delay12864(0);
Enable = 1;
Delay12864(0);
Enable = 0;
}
/******************************************************************************/
void write_data(unsigned char Dispdata)//写数据到LCD
{
Di = 1;
RW = 0;
Lcd_Bus = Dispdata;
Delay12864(0);
Enable = 1;
Delay12864(0);
Enable = 0;
}
/*******************************************************************************/
void frame(void)//显示边框
{
unsigned char i;
Mcs = 1;
Scs = 1;
write_com(Page_Add+0);
write_com(Col_Add+0);
for(i=0;i<64;i++)
{
write_data(0x01);
}
write_com(Page_Add+7);
write_com(Col_Add+0);
for(i=0;i<64;i++)
{
write_data(0x80);
}
for(i=0;i<8;i++)
{
Mcs=0;
Scs=1;
write_com(Page_Add+i);
write_com(Col_Add+63);
write_data(0xff);
Mcs=1;
Scs=0;
write_com(Page_Add+i);
write_com(Col_Add+0);
write_data(0xff);
}
}
/******************************************************************************/
void Clr_Scr(void)//清除内存
{
unsigned char j,k;
Mcs=1;Scs=1;
write_com(Page_Add+0);
write_com(Col_Add+0);
for(k=0;k<8;k++)
{
write_com(Page_Add+k);
for(j=0;j<64;j++)
{
write_data(0x00);
}
}
}
c51万年历温度与闹 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)