中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        c語言模塊化編程的方法

        作者: 時(shí)間:2012-09-15 來源:網(wǎng)絡(luò) 收藏

        模塊化設(shè)計(jì)原則:
        第一步:創(chuàng)建頭文件(源文件與頭文件同名如delay.c與delay.h)
        第二步:防止重復(fù)包含處理
        在.h文件里加入
        #ifndefXXXX
        #defineXXXX
        .......
        #endif

        例如:
        #ifndef_DELAY_H__
        #define_DELAY_H__
        .......
        #endif
        第三步: 代碼封裝(內(nèi)部調(diào)用【.h封裝外部調(diào)用的部分】)
        封裝成函數(shù)或者宏定義以便提高可讀性和可修改文件,盡量少用或者不用全局變量
        第四步:使用源文件
        .c文件添加到文件中
        實(shí)例:
        delay.h文件

        #ifndef __DELAY_H__
        #define __DELAY_H__
        #define uchar unsingned char
        #define uint unsigned int
        void delay50us(uint t);
        void delay50ms(uint t);
        #endif

        delay.c文件
        #includereg52.h>
        #include"實(shí)例.h"
        void delayus(uint t)//延時(shí)函數(shù)
        { uint j;
        for(;t>0;t--)
        for(j=6245;j>0;j--);


        }
        void delayms(uint t)//延時(shí)函數(shù)
        { uint j;
        for(;t>0;t--)
        for(j=6245;j>0;j--);


        }
        數(shù)碼管.h文件

        #ifndef __DELAY_H__
        #define __DELAY_H__
        #define"實(shí)例.h"
        #define uint unsigned int
        void dispaytable(uchar *p);
        void dispayt(uchar num0,uchar num1,uchar num2,uchar num3,uchar num4,uchar num5,uchar num6,uchar num7,);
        #endif

        數(shù)碼管.c文件
        #include"數(shù)碼管.h"
        #include"模塊化編程實(shí)例.h"
        unsigned char code smg_du[]={0xfe,0xfd,0xfb,0xf7,0xef,0xbf,0x7f};
        unsigned char code smg_we[]={0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00};
        void display_table(uchar *p)
        {
        uchar i;
        foe(i=0;i8;i++)
        {
        P1=smg_du[*p];
        P2=smg_we[i];
        delay_50us(20);
        }
        }
        void display(uchar num0,uchar num1,uchar num2,uchar num3,uchar num4,uchar num5,uchar num6,uchar num7,)
        {
        P1=smg_du[mun0];
        P2=smg_we[0];
        delay_50us(20);

        P1=smg_du[mun1];
        P2=smg_we[1];
        delay_50us(20);

        P1=smg_du[mun2];
        P2=smg_we[2];
        delay_50us(20);

        P1=smg_du[mun3];
        P2=smg_we[3];
        delay_50us(20);

        P1=smg_du[mun4];
        P2=smg_we[4];
        delay_50us(20);

        P1=smg_du[mun5];
        P2=smg_we[5];
        delay_50us(20);

        P1=smg_du[mun6];
        P2=smg_we[6];
        delay_50us(20);

        P1=smg_du[mun7];
        P2=smg_we[7];
        delay_50us(20);

        }


        mian.c文件
        #include"數(shù)碼管.h"
        #includereg52.h>
        #include"模塊化編程實(shí)例.h"
        sbit rst=P3^6;
        unsigned char table[]={2,3,4,5,6,7,8,9};
        void main()
        {
        rst=0;
        while(1)
        { display_tale(table);
        }
        }

        pid控制相關(guān)文章:pid控制原理


        c語言相關(guān)文章:c語言教程




        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉