日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] Keil C51沒有 《stdbool.h》頭文件,自己做一個(gè)stdbool.h#ifndef__STDBOOL_H__#define__STDBOOL_H__typedefenum{false=0,true=1,}bool;#endif最簡(jiǎn)單的數(shù)組模擬循環(huán)隊(duì)列Queue.h#ifndef__QUEUE__#define_

Keil C51沒有 《stdbool.h》頭文件,自己做一個(gè)


stdbool.h


  1. #ifndef__STDBOOL_H__

  2. #define__STDBOOL_H__

  3. typedefenum{

  4. false=0,

  5. true=1,

  6. }bool;

  7. #endif




最簡(jiǎn)單的數(shù)組模擬循環(huán)隊(duì)列


Queue.h


  1. #ifndef__QUEUE__

  2. #define__QUEUE__

  3. #include

  4. #include"stdbool.h"

  5. #defineu8unsignedchar

  6. #defineMaxsize10

  7. typedefstruct{

  8. u8element[Maxsize];

  9. u8front;

  10. u8rear;

  11. }SeqCycleQueue;

  12. voidInit_Cycle_Queue(SeqCycleQueue*Q);

  13. boolEntry_Queue(SeqCycleQueue*Q,u8x);

  14. boolDelete_Queue(SeqCycleQueue*Q,u8*x);

  15. boolGet_front_value(SeqCycleQueue*Q,u8*x);

  16. boolIs_Queue_Full(SeqCycleQueue*Q);

  17. boolIs_Queue_Empty(SeqCycleQueue*Q);

  18. #endif





Queue.c


  1. #include"Queue.h"

  2. SeqCycleQueueQ;

  3. voidInit_Cycle_Queue(SeqCycleQueue*Q)

  4. {

  5. Q->front=0;

  6. Q->rear=0;

  7. }

  8. boolEntry_Queue(SeqCycleQueue*Q,u8x)

  9. {

  10. if((Q->rear+1)%Maxsize==Q->front)

  11. {

  12. returnfalse;

  13. }

  14. Q->element[Q->rear]=x;

  15. Q->rear=(Q->rear+1)%Maxsize;

  16. returntrue;

  17. }

  18. boolDelete_Queue(SeqCycleQueue*Q,u8*x)

  19. {

  20. if(Q->front==Q->rear)

  21. returnfalse;

  22. *x=Q->element[Q->front];

  23. Q->front=(Q->front+1)%Maxsize;

  24. returntrue;

  25. }

  26. boolGet_front_value(SeqCycleQueue*Q,u8*x)

  27. {

  28. if(Q->front==Q->rear)

  29. {

  30. returnfalse;

  31. }

  32. else

  33. {

  34. *x=Q->element[Q->front];

  35. returntrue;

  36. }

  37. }

  38. boolIs_Queue_Full(SeqCycleQueue*Q)

  39. {

  40. if((Q->rear+1)%Maxsize==Q->front)

  41. {

  42. returntrue;

  43. }

  44. else

  45. {

  46. returnfalse;

  47. }

  48. }

  49. boolIs_Queue_Empty(SeqCycleQueue*Q)

  50. {

  51. if(Q->front==Q->rear)

  52. {

  53. returntrue;

  54. }

  55. else

  56. {

  57. returnfalse;

  58. }

  59. }




main.c


  1. #include"Queue.h"

  2. volatileunsignedcharrx_data;

  3. externSeqCycleQueueQ;

  4. voidSend_Char(u8ch)

  5. {

  6. SBUF=ch;

  7. while(TI==0);

  8. TI=0;

  9. }

  10. //----------------------------------------------

  11. voidmain(void)

  12. {

  13. volatileunsignedchartmp=0;

  14. TMOD=0x20;//T1方式2

  15. TH1=0xFD;//Baud:9600bps@11.0592MHz

  16. TL1=0xFD;

  17. TR1=1;//啟動(dòng)定時(shí)器1

  18. SCON=0x50;//串口方式1,8-n-1,允許接收

  19. REN=1;//使能串口接收

  20. EA=1;//打開總中斷

  21. ES=1;//打開串口中斷開關(guān)

  22. Init_Cycle_Queue(&Q);

  23. while(1)

  24. {

  25. if(!Is_Queue_Empty(&Q))

  26. {

  27. Delete_Queue(&Q,&tmp);

  28. Send_Char(tmp);

  29. }

  30. }

  31. }

  32. //----------------------------------------------

  33. voidserial(void)interrupt4

  34. {

  35. if(RI)

  36. {

  37. rx_data=SBUF;

  38. //P1=rx_data;

  39. Entry_Queue(&Q,rx_data);

  40. RI=0;

  41. }

  42. }

  43. //----------------------------------------------




閱讀 51 手冊(cè),發(fā)送緩沖與接收緩沖是獨(dú)立的兩個(gè)SBUF(雖然都對(duì)應(yīng) 名字一樣的SUBF 特殊功能寄存器)


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉