Thông báo

Collapse
No announcement yet.

đồng hồ ma trận cơ bản

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • đồng hồ ma trận cơ bản

    đồng hồ ma trận cơ bản
    Attached Files

  • #2
    Nguyên văn bởi rierie Xem bài viết
    đồng hồ ma trận cơ bản
    sao phần hiển thị không rõ vậy anh. anh có thể xử lý lại được không ạ
    caoson.vnatr@gmail.com
    Thiết kế mạch điện tử
    0914024690

    Comment


    • #3
      Nguyên văn bởi rierie Xem bài viết
      đồng hồ ma trận cơ bản
      Bác cho em xin cái code về tham khảo được không?

      Comment


      • #4
        Nguyên văn bởi caoson_vnatr Xem bài viết
        sao phần hiển thị không rõ vậy anh. anh có thể xử lý lại được không ạ
        đổi led mầu khác là nhìn rõ ngay thôi mà

        Email:
        Gmail:

        Comment


        • #5
          Nguyên văn bởi tuankep6 Xem bài viết
          đổi led mầu khác là nhìn rõ ngay thôi mà
          Em đổi rồi mà vẫn thế bác àh. Phải căng mắt ra mới nhìn được. nhưng không rõ lắm.Chủ topic cố gắng sửa lại để em tiến hành làm xem sao
          caoson.vnatr@gmail.com
          Thiết kế mạch điện tử
          0914024690

          Comment


          • #6
            mã nguồn cơ bản bằng cách sử dụng Keil uVision3



            #include "reg52.h"
            //------------------------------------------------------------------------------------------
            #define uchar unsigned char
            #define uint unsigned int

            //
            sbit S_DIO = P3^0;
            sbit S_CLK = P3^1;
            sbit R_CLK = P3^2;

            //
            sbit KEY_1 = P1^1;
            sbit KEY_2 = P1^2;
            sbit KEY_3 = P1^0;

            //
            sbit BEEP = P2^7;

            //
            sbit T_CLK = P3^5;
            sbit T_IO = P3^6;
            sbit T_RST = P3^7;


            sbit ACC0 = ACC^0;
            sbit ACC1 = ACC^1;
            sbit ACC2 = ACC^2;
            sbit ACC3 = ACC^3;
            sbit ACC4 = ACC^4;
            sbit ACC5 = ACC^5;
            sbit ACC6 = ACC^6;
            sbit ACC7 = ACC^7;
            //------------------------------------------------------------------------------------------
            unsigned char code font[][7]={
            0x38,0x44,0x64,0x54,0x4C,0x44,0x38,//0xF8,0x88,0x88,0x88,0x88,0x88,0xF8, //-----------'0'
            0x10,0x18,0x10,0x10,0x10,0x10,0x38,//0x20,0x30,0x28,0x20,0x20,0x20,0xF8, //-----------'1'
            0x38,0x44,0x40,0x20,0x10,0x08,0x7C,//0xF8,0x80,0x80,0xF8,0x08,0x08,0xF8, //-----------'2'
            0x7C,0x20,0x10,0x20,0x40,0x44,0x38,//0xF8,0x80,0x80,0xF8,0x80,0x80,0xF8, //-----------'3'
            0x20,0x30,0x28,0x24,0x7C,0x20,0x20,//0x48,0x48,0x48,0x48,0xF8,0x40,0x40, //-----------'4'
            0x7C,0x04,0x3C,0x40,0x40,0x44,0x38,//0xF8,0x08,0x08,0xF8,0x80,0x80,0xF8, //-----------'5'
            0x70,0x08,0x04,0x3C,0x44,0x44,0x38,//0xF8,0x08,0x08,0xF8,0x88,0x88,0xF8, //-----------'6'
            0x7C,0x40,0x20,0x10,0x08,0x08,0x08,//0xF8,0x80,0x80,0x80,0x80,0x80,0x80, //-----------'7'
            0x38,0x44,0x44,0x38,0x44,0x44,0x38,//0xF8,0x88,0x88,0xF8,0x88,0x88,0xF8, //-----------'8'
            0x38,0x44,0x44,0x78,0x40,0x20,0x1C,//0xF8,0x88,0x88,0xF8,0x80,0x80,0x80, //-----------'9'
            0x00,0x30,0x30,0x00,0x30,0x30,0x00, //-----10----':'
            0x00,0x00,0x00,0x00,0x00,0x00,0x00, //-----11----' '
            };

            unsigned char idata DisTemp[5][7];

            unsigned char idata Dis[5]={1,2,10,0,0};
            //------------------------------------------------------------------------------------------
            //-----------------------------
            unsigned char idata Time[7];

            //------------------------------------------------------------------------------------------
            unsigned char idata CSRow[7]={0x01,0x02,0x04,0x08,0x10,0x20,0x40};

            unsigned char idata second,minute,hour,day,month,week,year;

            unsigned long int idata Disbuf[5];

            unsigned long int idata Disbuftemp[7];
            //------------------------------------------------------------------------------------------
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void Delay(unsigned int i)
            {
            unsigned int j;
            for(j=0;j<i;j++);
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void OutData(unsigned char Data)
            {
            SBUF=~Data;
            while(TI==0);
            TI=0;
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            unsigned char BCD2HEX(unsigned char BCDChar)
            {
            unsigned char temp;
            temp=(BCDChar/16*10+BCDChar%16);
            return temp;
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            unsigned char HEX2BCD(unsigned char HEXChar)
            {
            unsigned char temp;
            temp=(HEXChar/10*16+HEXChar%10);
            return temp;
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void WriteByteDS1302(unsigned char Data)
            {
            unsigned char i;
            ACC = Data;
            for(i=8; i>0; i--)
            {
            T_IO = ACC0;
            T_CLK = 1;
            T_CLK = 0;
            ACC = ACC >> 1;
            }
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            unsigned char ReadByteDS1302(void)
            {
            unsigned char i;
            for(i=8; i>0; i--)
            {
            ACC = ACC >>1;
            ACC7 = T_IO;
            T_CLK = 1;
            T_CLK = 0;
            }
            return(ACC);
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void WriteDS1302(unsigned char Addr,unsigned char Data)
            {
            T_RST = 0;
            T_CLK = 0;
            T_RST = 1;
            WriteByteDS1302(Addr);
            WriteByteDS1302(Data);
            T_CLK = 1;
            T_RST = 0;
            }
            /************************************************** *****************************************

            ************************************************** *****************************************/
            unsigned char ReadDS1302(unsigned char Addr)
            {
            unsigned char Data;
            T_RST = 0;
            T_CLK = 0;
            T_RST = 1;
            WriteByteDS1302(Addr);
            Data = ReadByteDS1302();
            T_CLK = 1;
            T_RST = 0;
            return(Data);
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void Set(unsigned char sel,unsigned char selby)
            {
            unsigned char address,item;
            unsigned char max,min;

            if(sel==0) {address=0x80; max=59;min=0;} //
            if(sel==1) {address=0x82; max=59;min=0;} //
            if(sel==2) {address=0x84; max=23;min=0;} //
            if(sel==3) {address=0x86; max=31;min=1;} //
            if(sel==4) {address=0x88; max=12;min=1;} //
            if(sel==5) {address=0x8a; max=7; min=1;} //
            if(sel==6) {address=0x8c; max=99;min=0;} //
            if(sel==7) {address=0xc0; max=59;min=0;} //
            if(sel==8) {address=0xc2; max=23;min=0;} //

            item=ReadDS1302(address+1)/16*10+ReadDS1302(address+1)%16;
            if (selby==0) item++; else item--;
            if(item>max) item=min;
            if(item<min) item=max;

            WriteDS1302(0x8e,0x00);
            WriteDS1302(address,item/10*16+item%10);
            WriteDS1302(0x90,0xa5);
            WriteDS1302(0x8e,0x80);
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void SetTime(unsigned char *pClock)
            {
            unsigned char h;
            unsigned char Addr=0x80;
            WriteDS1302(0x8e,0x00);
            for(h=7; h>0; h--)
            {
            WriteDS1302(Addr,*pClock);
            pClock++;
            Addr+=2;
            }
            WriteDS1302(0x90,0xa5);
            WriteDS1302(0x8e,0x80);
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void ReadTime()
            {
            second = BCD2HEX(Time[0]=ReadDS1302(0x81));
            minute = BCD2HEX(Time[1]=ReadDS1302(0x83));
            hour = BCD2HEX(Time[2]=ReadDS1302(0x85));
            day = BCD2HEX(Time[3]=ReadDS1302(0x87));
            month = BCD2HEX(Time[4]=ReadDS1302(0x89));
            year = BCD2HEX(Time[5]=ReadDS1302(0x8d));
            week = BCD2HEX(Time[6]=ReadDS1302(0x8b));
            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void WriteTime()
            {
            WriteDS1302(0x8e,0x00);
            WriteDS1302(0x80,HEX2BCD(second));
            WriteDS1302(0x82,HEX2BCD(minute));
            WriteDS1302(0x84,HEX2BCD(hour));
            WriteDS1302(0x86,HEX2BCD(day));
            WriteDS1302(0x88,HEX2BCD(month));
            WriteDS1302(0x8A,HEX2BCD(week));
            WriteDS1302(0x8C,HEX2BCD(year));
            WriteDS1302(0x90,0xa5);
            WriteDS1302(0x8e,0x80);
            }

            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void DisProcess()
            {
            unsigned char i,j;
            for(i=0;i<5;i++)
            for(j=0;j<7;j++)
            DisTemp[i][j]=font[Dis[i]][j];
            for(i=0;i<7;i++)
            {
            Disbuf[0]=DisTemp[4][i];
            Disbuf[1]=DisTemp[3][i];
            Disbuf[2]=DisTemp[2][i];
            Disbuf[3]=DisTemp[1][i];
            Disbuf[4]=DisTemp[0][i];
            Disbuftemp[i]=Disbuf[0]<<24|Disbuf[1]<<18|Disbuf[2]<<12|Disbuf[3]<<6|Disbuf[4];
            }
            }

            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void DisPlay()
            {
            unsigned char i,j;
            for(i=0;i<7;i++)
            {
            P2=~0x00;
            BEEP=1;
            for(j=0;j<4;j++)
            OutData(0x00);
            R_CLK=1;R_CLK=0;

            P2=~CSRow[i];
            BEEP=1;
            for(j=0;j<4;j++)
            OutData(((unsigned char *)&Disbuftemp[i])[3-j]);
            R_CLK=1;R_CLK=0;
            Delay(350);
            }
            P2=~0x00;
            BEEP=1;
            for(j=0;j<4;j++)
            OutData(0x00);
            R_CLK=1;R_CLK=0;

            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void init(void)
            {
            EA=1;
            SCON=0;//
            ReadTime();//
            DisPlay();
            Dis[0]=hour/10;
            Dis[1]=hour%10;
            Dis[3]=minute/10;
            Dis[4]=minute%10;
            Dis[2]=10;
            DisProcess();

            }
            /************************************************** *****************************************
            *
            ************************************************** *****************************************/
            void main()
            {
            init();
            while(1)
            {
            ReadTime();
            DisPlay();
            if((hour/10)==0)
            {
            Dis[0]=11;
            }
            else
            {
            Dis[0]=hour/10;
            }
            Dis[1]=hour%10;
            Dis[3]=minute/10;
            Dis[4]=minute%10;
            if((second%10)%2)
            Dis[2]=11;
            else
            Dis[2]=10;
            DisProcess();
            if(KEY_1==0)
            {
            DisPlay();
            if(KEY_1==0)
            {
            Set(2,0);
            }
            while(KEY_1==0)DisPlay();
            }
            if(KEY_2==0)
            {
            DisPlay();
            if(KEY_2==0)
            {
            Set(1,0);
            }
            while(KEY_2==0)DisPlay();
            }
            if(KEY_3==0)
            {
            DisPlay();
            if(KEY_3==0)
            {
            WriteDS1302(0x8e,0x00);//
            WriteDS1302(0x80,0x00);//
            WriteDS1302(0x90,0xa5);//
            WriteDS1302(0x8e,0x80);//
            }
            while(KEY_3==0)DisPlay();
            }
            }
            }

            Comment

            Về tác giả

            Collapse

            rierie Tìm hiểu thêm về rierie

            Bài viết mới nhất

            Collapse

            Đang tải...
            X