DS1302和51单片机设计电子钟数码管显示.doc
文本预览下载声明
DS1302和51单片机设计电子钟数码管显示
2010-09-03 10:39
DS1302和51单片机设计电子钟数码管显示(未作出防真)
#includereg51.h
#define uchar unsigned char
#define uint unsigned int
uchar dis[16]={0,0,0,0,10,10,0,0,7,2,9,0,9,0,0,2};
uchar P2_scan[4]={0xf7,0xfb,0xfd,0xfe}; //位选择 显示扫描
uchar P0_scan[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//数字显示 不带小数点
uchar P0_scan1[11]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x7f};//数字显示 带小数点
char clock[7]={4,0,15,10,27,9,9};
uchar tiao,m=0,n=8,S;
bit time=0,p=0;
sbit CLK = P1^0;
sbit IO = P1^1;
sbit RST = P1^2;
sbit P32 = P3^2;
sbit P33 = P3^3;
sbit P34 = P3^4;
sbit P35 = P3^5;
/**************************** 延时函数 **************************/
void delay(uchar time)//延时0.1ms
{
uchar i,j;
do{
for(i=0;i10;i++)
for(j=0;j20;j++);
time--;
}while (time0);
}
/***************************** 复位函数 ******************************/
void reset()
{
CLK = 0;
RST = 0;
RST = 1;
}
/****************************** 字节写入函数 ***************************/
void wbyte(uchar W_Byte)
{
uchar i;
for(i =0;i8;++i)
{
IO=0;
if(W_Byte0x01)IO=1;
CLK=0;
CLK=1; //一次上升沿写一位,zwj注
W_Byte=1;
}
}
/****************************** 字节读取函数 ****************************/
uchar rbyte()
{
uchar i;
uchar R_Byte;
uchar TmpByte;
R_Byte=0x00;
IO=1;
for(i=0;i8;++i)
{
CLK=1;
CLK=0;
TmpByte=(uchar)IO; //读IO口
TmpByte=7;
R_Byte=1 ;
R_Byte|=TmpByte;
}
return R_Byte;
}
/**************************** DS1302初始化函数 **************************/
void initialize_DS1302(void)
{
reset();
wbyte(0x8e); // 写保护控制寄存器
wbyte(0); // 允许写入
reset();
wbyte(0x90); // 涓流充电控制寄存器
wbyte(0xab); // 允许充电, 双二极管, 8K 电阻
reset();
wbyte(0xbe); // 以多字节突发方式写入时钟数据(8个字节)
wbyte(clock[1]); //秒
wbyte(clock[2]); //分
wby
显示全部