在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51單片機(jī)的FIFO(先入先出)循環(huán)隊(duì)列實(shí)現(xiàn)

            51單片機(jī)的FIFO(先入先出)循環(huán)隊(duì)列實(shí)現(xiàn)

            作者: 時(shí)間:2016-11-23 來(lái)源:網(wǎng)絡(luò) 收藏
            //////////////////////////////////////////////////////////
            // 文件:config.h
            //////////////////////////////////////////////////////////
            #ifndef __CONFIG_H
            #define __CONFIG_H
            //這一段無(wú)需改動(dòng)
            //This segment should not be modified
            #ifndef TRUE
            #define TRUE 1
            #endif
            #ifndef FALSE
            #define FALSE 0
            #endif
            typedef unsigned char uint8; /* defined for unsigned 8-bits integer variable 無(wú)符號(hào)8位整型變量 */
            typedef signed char int8; /* defined for signed 8-bits integer variable有符號(hào)8位整型變量 */
            typedef unsigned short uint16; /* defined for unsigned 16-bits integer variable 無(wú)符號(hào)16位整型變量 */
            typedef signed short int16; /* defined for signed 16-bits integer variable 有符號(hào)16位整型變量 */
            typedef unsigned int uint32; /* defined for unsigned 32-bits integer variable 無(wú)符號(hào)32位整型變量 */
            typedef signed int int32; /* defined for signed 32-bits integer variable 有符號(hào)32位整型變量 */
            typedef float fp32; /* single precision floating point variable (32bits) 單精度浮點(diǎn)數(shù)(32位長(zhǎng)度) */

            #i nclude "FIFOQUEUE.h"
            #endif
            //////////////////////////////////////////////////////////
            // 文件:FIFOQUEUE.h
            //////////////////////////////////////////////////////////
            #ifndef _FIFOQUEUE_H
            #define _FIFOQUEUE_H
            #define ElemType uint8
            #define QueueSize 20
            #define QueueFull 0
            #define QueueEmpty 1
            #define QueueOperateOk 2
            struct FifoQueue
            {
            uint16 front;
            uint16 rear;
            uint16 count;
            ElemType dat[QueueSize];
            };
            //Queue Initalize
            extern void QueueInit(struct FifoQueue *Queue);
            // Queue In
            extern uint8 QueueIn(struct FifoQueue *Queue,ElemType sdat);
            // Queue Out
            extern uint8 QueueOut(struct FifoQueue *Queue,ElemType *sdat);
            #endif
            //////////////////////////////////////////////////////////
            // 文件:FIFOQUEUE.C
            //////////////////////////////////////////////////////////
            #i nclude "config.h"
            //Queue Init
            void QueueInit(struct FifoQueue *Queue)
            {
            Queue->front = Queue->rear;
            Queue->count = 0;
            }
            // Queue In
            uint8 QueueIn(struct FifoQueue *Queue,ElemType sdat)
            {
            if((Queue->front == Queue->rear) && (Queue->count == QueueSize))
            { // full
            return QueueFull;
            }else
            { // in
            Queue->dat[Queue->rear] = sdat;
            Queue->rear = (Queue->rear + 1) % QueueSize;
            Queue->count = Queue->count + 1;
            return QueueOperateOk;
            }
            }
            // Queue Out
            uint8 QueueOut(struct FifoQueue *Queue,ElemType *sdat)
            {
            if((Queue->front == Queue->rear) && (Queue->count == 0))
            { // empty
            return QueueEmpty;
            }else
            { // out
            *sdat = Queue->dat[Queue->front];
            Queue->front = (Queue->front + 1) % QueueSize;
            Queue->count = Queue->count - 1;
            return QueueOperateOk;
            }
            }
            //////////////////////////////////////////////////////////
            // 文件:Main.C
            //////////////////////////////////////////////////////////
            #i nclude
            #i nclude "config.h"
            void main(void)
            {
            struct FifoQueue MyQueue;
            ElemType sh;
            uint8 i;
            QueueInit(&MyQueue);
            while(1)
            {
            for(i = 0;i < 30;i++)
            {
            if(QueueIn(&MyQueue,i) == QueueFull) break;
            }
            for(i = 0;i < 30;i++)
            {
            if(QueueOut(&MyQueue,&sh) == QueueEmpty) break;
            }
            }
            while(1);
            }



            評(píng)論


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

            關(guān)閉