#include<reg51.h>
#include"SEGx8.H"
#include"DELAY.H"
#include"DS1302.H"
#include"NONGLI.H"
#define SEGx8_Port P0 //硬件端口定义
extern unsigned char dtime[7][2];
extern unsigned char ntime[3][2];
#define uchar unsigned char
#define uint unsigned int
sbit E1=P2^0; //定义数码管使能引脚1
sbit E2=P2^1; //定义数码管使能引脚2
sbit E3=P2^2; //定义数码管使能引脚3
sbit E4=P2^3; //定义数码管使能引脚4
sbit E5=P1^0; //定义数码管使能引脚5
sbit E6=P1^1; //定义数码管使能引脚6
unsigned char SEGx8_code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char SEGx8_bits[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
/*--------------------------底层驱动-----------------------------*/
void SEGx8_WEI(unsigned char _Numb) //位选
{
switch(_Numb)
{
case 0: P2=0X00;break;
case 1: P2=0X01;break;
case 2: P2=0X02;break;
case 3: P2=0X03;break;
case 4: P2=0X04;break;
case 5: P2=0X05;break;
case 6: P2=0X06;break;
case 7: P2=0X07;break;
case 8: P2=0X08;break;
case 9: P2=0X09;break;
case 10: P2=0X0A;break;
case 11: P2=0X0B;break;
case 12: P2=0X0C;break;
case 13: P2=0X0D;break;
case 14: P2=0X0E;break;
case 15: P2=0X0F;break;
case 16: P1=0X00;break;
case 17: P1=0X01;break;
case 18: P1=0X02;break;
case 19: P1=0X03;break;
default :break;
}
}
void SEGx8_DUAN(unsigned char _Numb) //位选
{
switch(_Numb)
{
case 0: SEGx8_Port=0X3f;break;
case 1: SEGx8_Port=0X06;break;
case 2: SEGx8_Port=0X5b;break;
case 3: SEGx8_Port=0X4f;break;
case 4: SEGx8_Port=0X66;break;
case 5: SEGx8_Port=0X6d;break;
case 6: SEGx8_Port=0X7d;break;
case 7: SEGx8_Port=0X07;break;
case 8: SEGx8_Port=0X7f;break;
case 9: SEGx8_Port=0X6f;break;
default :break;
}
}
/*----------------------------实际应用------------------------*/
void showtime(void)
{
unsigned char i,d1,d2,m1,m2;
Conversion(0,YEAR,MONTH,DATE);
m1=month_moon/10;
m2=month_moon%10;
d1=day_moon/10;
d2=day_moon%10;
for(i=0;i<10;i++)
{
SEGx8_WEI(0);SEGx8_Port=0X5b;delayms(1);//显示年
SEGx8_WEI(1);SEGx8_Port=0X3f;delayms(1);
SEGx8_WEI(2);SEGx8_DUAN(dtime[5][0]-0x30); delayms(1);
SEGx8_WEI(3);SEGx8_DUAN(dtime[5][1]-0x30); delayms(1);
SEGx8_WEI(4);SEGx8_DUAN(dtime[4][0]-0x30);delayms(1);//显示月
SEGx8_WEI(5);SEGx8_DUAN(dtime[4][1]-0x30);delayms(1);
SEGx8_WEI(6);SEGx8_DUAN(dtime[3][0]-0x30);delayms(1);//显示日
SEGx8_WEI(7);SEGx8_DUAN(dtime[3][1]-0x30);delayms(1);
SEGx8_WEI(8);SEGx8_DUAN(dtime[2][0]-0x30);delayms(1); //显示时
SEGx8_WEI(9);SEGx8_DUAN(dtime[2][1]-0x30);delayms(1);
SEGx8_WEI(10);SEGx8_DUAN(dtime[1][0]-0x30);delayms(1);//显示分
SEGx8_WEI(11);SEGx8_DUAN(dtime[1][1]-0x30);delayms(1);
SEGx8_WEI(12);SEGx8_DUAN(dtime[0][0]-0x30);delayms(1);//显示秒
SEGx8_WEI(13);SEGx8_DUAN(dtime[0][1]-0x30);delayms(1);
SEGx8_WEI(14);SEGx8_DUAN(dtime[6][0]-0x30);delayms(1);//显示星期
SEGx8_WEI(15);SEGx8_DUAN(dtime[6][1]-0x30);delayms(1);
SEGx8_WEI(16);SEGx8_DUAN(m1-0x30); delayms(1);//农历月
SEGx8_WEI(17);SEGx8_DUAN(m2-0x30); delayms(1);
SEGx8_WEI(18);SEGx8_DUAN(d1-0x30); delayms(1);//农历日
SEGx8_WEI(19);SEGx8_DUAN(d2-0x30); delayms(1);
}
}
|