单片机/MCU论坛
直播中

943347096

11年用户 16经验值
擅长:MEMS/传感技术 嵌入式技术
私信 关注
[文章]

IAP15F2K型号单片机电子钟

#include"STC15F2K.h"
#include

typedef unsigned char uchar;
typedef unsigned int  uint;

***it ds=P4^4;
***it sck=P4^2;
***it rck=P4^1;
***it k1=P3^0;
***it k2=P3^1;
***it k3=P3^2;
***it k4=P3^3;
uchar bdata set;
***it high7=set^7;
uchar counter=0;

uchar code tab[40]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,                //0~F共阴极,无小数点
                                                        //h,p,u,全灭,无小数点
                                        0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1,                //0~F共阴极,有小数点
                                        0xf6,0xf3,0xbe,0x80};                //h,p,u,全灭,有小数点

void oneled_out(uchar n,uchar location)
{ uchar i;
  set=location;
  for(i=1;i<9;i++)
  {ds=high7;
  sck=0;sck=1;sck=0;
  set=set<<1;
  }
  set=~tab[n];
  for(i=1;i<9;i++)
  {ds=high7;
   sck=0;sck=1;sck=0;
   set=set<<1;
  }
  rck=0;rck=1;rck=0;
}

void timer0_initialize()
{
        counter=0;
        TR0=0;
        TMOD=0x01;                                        //定时器0
        TH0=(65535-5000)/256;                //5ms
        TL0=(65535-5000)%256;
        EA=1;
        ET0=1;
        TR0=1;
}
void timer0()interrupt 1                        //中断服务子程序
{
       
        TH0=(65535-5000)/256;                //5ms
        TL0=(65535-5000)%256;       

        counter++;
}

void main()
{ uchar n1,n2,n3,location,i=0;
  uint num1=0,num2=0,num3=0;
  location=0x80;
  timer0_initialize();
  while(1)
  {if(counter==200)
     {counter=0;num1++;
         if(num1==60)
         {num1=0;
         num2++;}
         if(num2==60)
         {num2=0;
         num3++;}
         if(num3==24)
         num3=0;
         }
         if(k1==0){while(!k1);num2++;}
         if(k2==0){while(!k2);num2--;}
         if(k3==0){while(!k3);num3++;}
         if(k4==0){while(!k4);num3--;}
   if(i==0)
   {n1=num1%10;oneled_out(n1,location);}
   else if(i==1)
   {n1=num1/10;oneled_out(n1,location);}
   else if(i==2)
   {n2=num2%10;oneled_out(n2+10,location);}
   else if(i==3)
   {n2=num2/10;oneled_out(n2,location);}
   else if(i==4)
   {n3=num3%10;oneled_out(n3+10,location);}
   else if(i==5)
   {n3=num3/10;oneled_out(n3,location);}   
  
   
   location=location>>1;
   i++;
   if(i==6){i=0;location=0x80;}

  }


}

更多回帖

发帖
×
20
完善资料,
赚取积分