天堂草原最受欢迎的角色,天堂动漫,天堂在线,色天堂下载,天堂中文在线资源,亚洲男人天堂

技術熱線: 4007-888-234

技術支持

PIC單片機開發鬧鐘程序

更新時間: 2019-03-23

十年專注單片機方案開發的方案公司英銳恩,分享PIC單片機開發鬧鐘程序。英銳恩現提供服務產品涉及主控芯片:8位單片機、16位單片機、32位單片機及各類運算放大器等。

#include
#include
#define uchar  unsigned char
#define uint   unsigned int
 #define  T_IOIO  TRISA1
#define  KS1    RA3
#define  KS2    RA4
#define  KS3    RA5
#define  T_CLK  RA0
#define  T_IO   RA1
#define  T_RST  RA2
#define  Fm     RC0

union {
      struct {
         unsigned b0:1;
         unsigned b1:1;
         unsigned b2:1;
         unsigned b3:1;
         unsigned b4:1;
         unsigned b5:1;
         unsigned b6:1;
         unsigned b7:1;
         }oneBit;
        unsigned char allBits;
       } myFlag;
union {
      struct {
         unsigned b0:1;
         unsigned b1:1;
         unsigned b2:1;

unsigned b3:1;
         unsigned b4:1;
         unsigned b5:1;
         unsigned b6:1;
         unsigned b7:1;
         }tpBit;
        unsigned char tpBits;
       } tp;
#define acc0 tp.tpBit.b0
#define acc7 tp.tpBit.b7
#define acc  tp.tpBits 

#define FMbit myFlag.oneBit.b2
       
const  unsigned char table[11]={ 0x0C0, 0x0F9, 0x0A4,0x0B0, 0x99, 0x92,0x82, 0x0F8,0x80,0x90,0xff};
const  unsigned char  Ds1302[] = {2, 9, 5,9};//被調整數據上下對比值
                               // //   時   分  
//////////ROM區///////////////
 uchar  BCD[4];//數據送LED的數據 暫存區
 //uchar  Reeprom[6];
 uchar   appear[8];//2送LED的數據 暫存區
 uchar   get1302[4];//從1302讀出 秒 分 時 日 月 星期 年 暫存區
 uchar  DisCash[3];//合字->1302

unsigned char temp,temp1;
//延時子程序
void delay(unsigned  int i )

  while(i--);
}
     
 void display(unsigned char x)//顯示程序
    {  
       unsigned char b,c ,i;
         i=x;
         b=0x10;
        for(c=0;c<4;c++)
         { 
      PORTB=table[ appear[i]] ;

    if(( myFlag.oneBit.b0==1)&& (c==1)) RB7=0;//點閃
            if(( myFlag.oneBit.b1==1)&& (c==2)) RB7=0;//點閃
      PORTC=(PORTC&0x0f)|b;
            CLRWDT();
      delay(300);//延時子程序
            b=b<<1;
            i=i++;
          }
       
     }

/////往1302寫入1Byte數據////////////////////////////////////////////////
void RTInputByte(uchar d)                                           ////
{                                                                   ////
    uchar i;                                                        ////
    acc = d;    // tp.tpBits//                                      ////

T_IOIO=0;                                                       ////
    for(i=8; i>0; i--)                                              ////
    {                                                               ////
      T_IO = acc0;//CARRY;//ACC0;  //*相當于匯編中的 RRC */         ////
      T_CLK = 1;                                                    ////
      T_CLK = 0;                                                    ////
     acc = acc >> 1;                                                ////
    }                                                               ////
}                                                                   ////

///////從1302讀取1Byte數據////////////////////////                  ////
uchar RTOutputByte(void)                                            ////
{                                                                   ////
    uchar i;                                                        ////
    T_IOIO=1;                                                       ////
    for(i=8; i>0; i--)                                              ////
    {                                                               ////
      acc = acc >>1;         //*相當于匯編中的 RRC */               ////

 acc7= T_IO;// CARRY                                           ////
      T_CLK = 1;                                                    ////
      T_CLK = 0;                                                    ////
    }                                                               ////
     return(acc);                                                   ////
}                                                                   ////
///////先寫地址,后寫命令/數據//////////////////////////            ////
void W1302(uchar ucAddr, uchar ucDa)                                ////

{                                                                   ////
    T_RST = 0;                                                      ////
    T_CLK = 0;                                                      ////
    T_RST = 1;                                                      ////
    RTInputByte(ucAddr);      // /* 地址,命令 */                   ////
    RTInputByte(ucDa);        // /* 寫1Byte數據*/                   ////
    T_CLK = 1;                                                      ////
    T_RST = 0;                                                      ////
}                                                                   ////

///////先寫地址,后讀命令/數據////////////////////////              ////
uchar R1302(uchar ucAddr)                                           ////
{                                                                   ////
    uchar ucData;                                                   ////
    T_RST = 0;                                                      ////
    T_CLK = 0;                                                      ////
    T_RST = 1;                                                      ////
    RTInputByte(ucAddr);            // /* 地址,命令 */             ////
    ucData = RTOutputByte();        // /* 讀1Byte數據 */            ////
    T_CLK = 1;                                                      ////

  T_RST = 0;                                                      ////
    return(ucData);                                                 ////
}                                                                   ////
/////////向1302寫入 秒 分 時 日 月 星期 年 */////////////           ////
void Set1302(uchar *pClock ,uchar a )                                ////
{                                                                   ////
    uchar i;                                                        ////
    uchar ucAddr = a;//0x80;// 秒. 分   /0x0C0 RAM                  ////
    W1302(0x8e,0x00);           ///* 控制命令,WP=0,允許寫操作*/     ////
    for(i =3; i>0; i--)                                             ////

  {                                                               ////
      W1302(ucAddr,*pClock);    ///* 秒 分 時 日 月 星期 年 */      ////
      pClock++;                                                     ////
      ucAddr +=2;                                                   ////
    }                                                               ////
     W1302(0x8e,0x80);          // /* 控制命令,WP=1,寫保護*/        ////
}                                                                   ////
////////從1302讀出 秒 分 時 日 月 星期 年 *//////////////////       ////
void v_Get1302(unsigned char  ucCurtime[],uchar a)                  ////
{                                                                   ////
 unsigned char i;                                                   ////
 unsigned char ucAddr = a;//0x83  分 0x0C1 RAM                     ////

 for (i=0;i<2;i++)                                                  ////
   {                                                                ////
      ucCurtime[i] = R1302(ucAddr);///*格式為: 秒 分 時 日 月 星期 年 */
      ucAddr += 2;                                                  ////
   }                                                                ////
}                                                                   ////
//////////拆字子程序////////////////////////////////////////////////////
 void  bcd_bcd( uchar  x )
  {  uchar  i,b, a=1;
      i=x;
     for (b=0;b<2;b++)
     {
           appear[i]=(get1302[a]&0xf0)>>4;
           i++;
           appear[i]=get1302[a]&0x0f;
           i++;
           a--;
     }

}                                                                   ////
 ////////蜂名器//////////////////////////////////////////////////////////
void  F_m()
{    

(文源網絡,侵刪)


404
返回首頁 |  返回上一頁
联系我们: 楚雄市| 克拉玛依市| 黔江区| 宁波市| 正阳县| 德化县| 吉水县| 花莲市| 万源市| 柯坪县| 城市| 浦县| 本溪市| 扬中市| 双牌县| 宁晋县| 海城市| 常州市| 赤峰市| 秀山| 宁国市| 同江市| 孝义市| 商河县| 库伦旗| 永丰县| 隆昌县| 饶平县| 西昌市| 江门市| 望奎县| 乌兰县| 略阳县| 宁河县| 普兰店市| 武汉市| 木兰县| 合江县| 隆化县| 辽中县| 龙南县|