微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > IAP15F2K型号单片机电子钟

IAP15F2K型号单片机电子钟

时间:10-02 整理:3721RD 点击:
#include"STC15F2K.h"
#include<intrins.H>
typedef unsigned char uchar;
typedef unsigned int  uint;
sbit ds=P4^4;
sbit sck=P4^2;
sbit rck=P4^1;
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
uchar bdata set;
sbit 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;}
  }

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top