资源简介

时钟用液晶显示,红外遥控器改变时间,有年月日显示,还有断电保护功能

资源截图

代码片段和文件信息

#include 
#define uint unsigned int
#define uchar unsigned char
uchar table2[7][3]={“Mon““Tus““Wen““Thu““Fri““Sat““Sun“} ;
char xshifenmiaoyearmonthday weekwrite;
uchar count;
sbit lcden=P3^4;
sbit rs=P3^5;
sbit rw=P3^6;
sbit rd=P3^7;
sbit gn=P3^0;
sbit jia=P3^1;
sbit jian=P3^2;
sbit sda=P2^0;
sbit scl=P2^1;

void delay1()
{;;}
void delay(uint z)
{
uint xy;
for(x=z;x>0;x--)
for(y=110;y>0;y--);}
void start()  //开始信号
{
     sda=1;
 delay1();
 scl=1;
 delay1();
 sda=0;
 delay1();
     

}
void stop()   //停止
{
sda=0;
delay1();
scl=1;
delay1();
sda=1;
delay1();
}
void respons()  //应答
{
 uchar i;
 scl=1;
 delay1();
 while((sda==1)&&(i<255))i++;

 scl=0;
 delay1();

}
void init3()
{
sda=1;
delay1();
scl=1;
delay1();
}
void write_byte(uchar date)
{
uchar itemp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
    delay1();
sda=CY;
delay1();
scl=1;
delay1();
}
scl=0;
delay1();
sda=1;
delay1();
}
uchar read_byte()
{
uchar ik;
scl=0;
delay1();
sda=1;
delay1();
for(i=0;i<8;i++)
{
scl=1;
delay1();
k=(k<<1)|sda;
scl=0;
delay1();
}
return k;
}
void write_add(uchar addressuchar date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
uchar read_add(uchar address)
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}


void write_com(uchar com)
{
rs=0;
rw=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
delay(5);
}

void write_data(uchar date)
{
rs=1;
rw=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
delay(5);
}

void init()
{
lcden=0;
     rw=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
   write_com(0x01);
   

}

void init2()
{
TMOD=0x01;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
}
void write_sfm(uchar lianjieuchar add)
{
uchar shige;
shi=lianjie/10;
ge=lianjie%10;
write_com(0x80+0x40+add);
write_data(0x30+shi);
write_data(0x30+ge);

}
  void write_sfm1(uchar lianjieuchar add)
{
uchar shige;
shi=lianjie/10;
ge=lianjie%10;
write_com(0x80+add);
write_data(0x30+shi);
write_data(0x30+ge);

}
  void write_year(uchar lianjieuchar add)
{
uchar qianbaishige;
ge=lianjie%10;
shi=(lianjie/10)%10;
bai=0;
qian=2;
write_com(0x80+add);
write_data(0x30+qian);
write_data(0x30+bai);
write_data(0x30+shi);
write_data(0x30+ge);

}
void write_week(uchar week )
{  uint i;
    write_com(0x80+12) ;
for(i=0;i<3;i++)
write_data(table2[week][i]);
}

void gnmod() //功能模块
{

 uchar an1;
  if(gn==0)
{
delay(5);
if(gn==0)
{

while(!gn);
TR0=0;
an1++;
if(an1==1)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-08-24 12:57  时钟1\
     文件       95492  2011-07-12 23:16  时钟1\Last Loaded 时钟1.DBK
     文件        6376  2005-03-22 15:22  时钟1\STARTUP.A51
     文件       14048  2011-07-18 19:38  时钟1\STARTUP.LST
     文件         749  2011-07-18 19:38  时钟1\STARTUP.OBJ
     文件       24076  2011-07-18 19:38  时钟1\时钟1
     文件        8306  2011-07-17 20:02  时钟1\时钟1.c
     文件       95490  2011-07-15 11:26  时钟1\时钟1.DSN
     文件        4894  2011-07-18 19:38  时钟1\时钟1.hex
     文件          58  2011-07-18 19:38  时钟1\时钟1.lnp
     文件       29361  2011-07-18 19:38  时钟1\时钟1.LST
     文件       33573  2011-07-18 19:38  时钟1\时钟1.M51
     文件       27831  2011-07-18 19:38  时钟1\时钟1.OBJ
     文件        1150  2011-07-17 20:03  时钟1\时钟1.Opt
     文件         498  2011-07-18 19:38  时钟1\时钟1.plg
     文件         768  2011-08-24 12:57  时钟1\时钟1.PWI
     文件        2152  2011-07-17 20:03  时钟1\时钟1.Uv2
     文件        1027  2011-07-17 17:50  时钟1\时钟1_Opt.Bak
     文件        2148  2011-07-12 18:50  时钟1\时钟1_Uv2.Bak

评论

共有 条评论