找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7183|回复: 12
收起左侧

一个简单的基于STC89C52单片机的排队叫号系统设计

  [复制链接]
ID:284943 发表于 2018-6-29 13:46 | 显示全部楼层 |阅读模式
这个是我同学搞的设计,他是网上买的程序,本质上就是个基于STC89C52的排队叫号,组成的东西也简单,2个STC,2个1602,蜂鸣器,一堆独立按键,还有个WT588D语言芯片和喇叭,通信用的是有线的串口。具体实现的功能我会发个视频链接。发出来也是为需要的人省点钱。具体的电气连接参考keil程序的引脚定义就可以了,语言芯片要导入的源文件也在压缩包里面。总体来讲这个设计没什么复杂的东西,正常的设计是不需要语音播报的。如果觉得独立按键较多也可以自己改成矩阵键盘,反正这东西焊独立按键也是要花点时间的。

视频的连接如下
https://pan.baidu.com/s/1vc_4T3Y6zcxwFNuki_eOEA
单片机源码:
  1. /*************************************************************************
  2. *工程名称: 排队叫号系统----叫号模块程序                             *
  3. *单片机型号:STC89C52RC                                                  *
  4. *晶振频率:11.0592MHz                                                                                                        *
  5. *作者:新兴光电                                                          *
  6. *日期:2016-03-01                                                        *
  7. *************************************************************************/
  8. #include<reg51.h>
  9. #include <intrins.h>
  10. #include "LCD1602.h"

  11. #define uchar unsigned char
  12. #define uint unsigned int
  13. #define FOSC 11059200L      //系统晶振频率
  14. #define BAUD 9600           //串口波特率
  15. #define SMOD 1              //为1,加倍波特率计算
  16. #if SMOD
  17.         #define TC_VAL (256-FOSC/16/12/BAUD)
  18. //#else   #define TC_VAL (256-FOSC/32/12/BAUD)
  19. #endif
  20. /**********端口定义*******************************/
  21. sbit call_key1=P1^0;        //呼叫键
  22. sbit recall_key1=P1^1;  //重复呼叫键
  23. sbit mute_key1=P1^2;        //消音键
  24. sbit stop_key1=P1^3;        //暂停键

  25. sbit call_key2=P1^4;        //呼叫键
  26. sbit recall_key2=P1^5;  //重复呼叫键
  27. sbit mute_key2=P1^6;        //消音键
  28. sbit stop_key2=P1^7;        //暂停键

  29. sbit call_key3=P3^2;        //呼叫键
  30. sbit recall_key3=P3^3;  //重复呼叫键
  31. sbit mute_key3=P3^4;        //消音键
  32. sbit stop_key3=P3^5;        //暂停键

  33. sbit beep=P3^6;   //蜂鸣器
  34. //语音相关
  35. sbit RST=P2^4;                        //复位脚  在非工业场合下这个可以不要
  36. sbit busy=P2^3;         //WT588D忙检测端口                无播放时输出高电平
  37. sbit SDA=P2^2;
  38. sbit CS =P2^1;
  39. sbit SCL=P2^0;
  40. /**************************************************/
  41. /***********寄存器定义*****************************/
  42. /*
  43. uchar code TAB[12]  =  {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40,0x00};
  44. //以上为共阴数码管段码表 0    1    2    3    4    5    6    7    8   9     -   无
  45. uchar dis_buf[9];  //显示缓存
  46. uchar dis_cnt;     //显示计数  */
  47. //以下为串口用到的寄存器
  48. bit uart_busy;               //串口忙检测
  49. bit uart_R_flag=0;      //串口数据接收完毕标志
  50. bit uart_T_flag=0;  //串口数据发送标志
  51. //uchar uart_buf;       //串口数据寄存器         
  52. //uchar count;        
  53. uchar receive[4];         //数据接收格式  0xa5(起始位) 机器号(1~3) 呼叫号码(0x01取号) 0x5a(结束位)
  54. uchar send_buf[4];  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 指令(0x01取号) 0x5a(结束位)
  55. uchar rec_cnt=0;
  56. //呼叫相关寄存器
  57. //uchar get_cnt=0;   //取号计数
  58. //uchar call_cnt=0;  //呼叫计数
  59. bit NO1_sta=0;  //一号窗状态  0暂停呼叫,1开始呼叫
  60. bit NO2_sta=0; //二号窗状态
  61. bit NO3_sta=0; //三号窗状态
  62. uchar NO1_number; //窗口一号码
  63. uchar NO2_number; //窗口二号码
  64. uchar NO3_number; //窗口三号码

  65. //蜂鸣器相关定义
  66. bit beep_flag=0;  //蜂鸣标志
  67. bit beep_end_flag=0;
  68. uchar beep_cnt=0;   //蜂鸣器计数
  69. uchar beep_end_cnt=0;
  70. //语音播放地址定义:
  71. //0--播放"0"; 1--播放"1"; 2--播放"2"; 3--播放"3"; 4--播放"4"; 5--播放"5"; 6--播放"6"; 7--播放"7";
  72. //8--播放"8"; 9--播放"9"; 10--播放"请"; 11--播放"号到"; 12--播放"号窗口";
  73. // 三线串口,音频输出PWM,忙信号输出LOW
  74. //WT588D相关寄存器定义
  75. //一线,二线,三线有关
  76. #define         H                  1        //定义1为高电平
  77. #define         L                 0        //定义0为低电平
  78. //////////////变量/////////////////
  79. //bit         flag           = 1;
  80. bit         B_DATA;                                                //传输数据一位
  81. unsigned char          SB_DATA   = 0;                //一字节公用数据缓存器
  82. unsigned char          S_DATA    = 0x00;

  83. bit play_flag=0;      //播放标志
  84. uchar play_part_sta=0; //0为一号窗口,1为二号窗口,3为三号窗口
  85. uchar play_cnt;
  86. uchar play_end_cnt=7;
  87. uchar idata sound_buf1[7];
  88. uchar idata sound_buf2[7];
  89. uchar idata sound_buf3[7];
  90. /**************************************************/
  91. /***************延时程序***************************/
  92. void Delay1ms(uint t)    //1ms延时程序
  93. {
  94.         uchar j;
  95.         while(t--)
  96.         {
  97.                 for(j=0;j<125;j++)
  98.                 { ; }
  99.         }
  100. }
  101. /**************************************************/
  102. /*************串口初始化程序***********************/
  103. void serial_init(void)
  104. {
  105.     PCON=0x80;
  106.         SCON=0x50;            //8位数据串口,波特率可变  无校验位
  107.         TMOD=0x21;                                  //定时器1设为8位自动重装
  108.         TH1=TC_VAL;        //定时初始值
  109.         TL1=TH1;
  110.         ES = 1;                 //串口中断允许
  111.         EA = 1;                 //总中断允许
  112.         TR1=1;
  113. }
  114. /**************************************************/
  115.   /***********串口中断服务程序*********************/
  116. void serial() interrupt 4
  117. {
  118.     if (RI)
  119.     {
  120.         RI = 0;            //串口接收中断完毕标志清0
  121.             //uart_buf=SBUF;   //接收数据
  122.         //        call_cnt=SBUF;      //接收数据  获得叫号数
  123.                 receive[rec_cnt]=SBUF;   //接收数据
  124.                 rec_cnt++;
  125.                 if(receive[0]==0xa5) //判断起始位
  126.                 {
  127.                         if(receive[rec_cnt-1]==0x5a&&rec_cnt==4)  //数据接收完毕
  128.                         {
  129.                                 uart_R_flag=1;   //串口接收完毕标志
  130.                         }
  131.                 }
  132.                 else rec_cnt=0;
  133.                 if(rec_cnt>=4)
  134.                         rec_cnt=0;
  135.     }
  136.     if (TI)
  137.     {
  138.         TI = 0;             //串口发送中断完毕标志清0
  139.         uart_busy = 0;           //串口忙标志清0
  140.     }
  141. }
  142. /***************************************************/
  143. /*************串口发送一字节数据程序****************/
  144. void send_uart_dat(uchar dat)
  145. {
  146.     while (uart_busy);           //忙检测标志 等后上一字节数据发送完毕
  147.     ACC = dat;              //Calculate the even parity bit P (PSW.0)
  148.     uart_busy = 1;
  149.     SBUF = ACC;             //发送数据至串口发送缓冲寄存器
  150. }
  151. /***************************************************/
  152. /*************串口发送字符串数据程序****************
  153. void send_uart_stringdat(uchar *s)
  154. {
  155.     while (*s)              //检查数据是否结束
  156.     {
  157.         send_uart_dat(*s++);     //发送字符串
  158.     }
  159. }
  160. /***************************************************/
  161. /********串口发送字符串数据程序*********************
  162. void send_uart_stringdat(uchar *send_dat)
  163. {
  164.     do              
  165.     {            
  166.         send_uart_dat(*send_dat);     //发送字符
  167.                 send_dat++;
  168.     }while(*send_dat!='\0');     //检查数据是否结束   
  169. }
  170. /***************************************************/
  171. /********数据转换用于显示***************************
  172. void cov_dis(uchar num1,uchar num2,uchar num3)
  173. {
  174.         dis_buf[0]=TAB[num1/100];     //显示缓存
  175.         dis_buf[1]=TAB[num1%100/10];  //显示缓存
  176.         dis_buf[2]=TAB[num1%100%10];  //显示缓存
  177.         
  178.         dis_buf[3]=TAB[num2/100];     //显示缓存
  179.         dis_buf[4]=TAB[num2%100/10];  //显示缓存
  180.         dis_buf[5]=TAB[num2%100%10];  //显示缓存
  181.         
  182.         dis_buf[6]=TAB[num3/100];     //显示缓存
  183.         dis_buf[7]=TAB[num3%100/10];  //显示缓存
  184.         dis_buf[8]=TAB[num3%100%10];  //显示缓存
  185. }
  186. /***************************************************/
  187. /*********定时器0中断服务程序***********************/
  188. void timer0(void) interrupt 1
  189. {

  190.         TL0 = 0x00;                //设置定时初值         20ms  11.0592MHz
  191.         TH0 = 0xB8;                //设置定时初值
  192. /*        P2=0xff;  
  193.         DIG1=1;
  194.         Dport=0x00;
  195.     dis_cnt++;  //显示计数
  196.         switch(dis_cnt)
  197.         {
  198.                 case 1: DIG1=0; Dport=dis_buf[0]; break;
  199.                 case 2: DIG2=0; Dport=dis_buf[1]; break;
  200.                 case 3: DIG3=0; Dport=dis_buf[2]; break;
  201.                 case 4: DIG4=0; Dport=dis_buf[3]; break;
  202.                 case 5: DIG5=0; Dport=dis_buf[4]; break;
  203.                 case 6: DIG6=0; Dport=dis_buf[5]; break;
  204.                 case 7: DIG7=0; Dport=dis_buf[6]; break;
  205.                 case 8: DIG8=0; Dport=dis_buf[7]; break;
  206.                 case 9: dis_cnt=0; DIG9=0; Dport=dis_buf[8]; break;
  207.         }
  208.                   */
  209.         if(beep_flag==1)  //蜂鸣标志
  210.         {
  211.                 beep_cnt++;          //蜂鸣计数
  212.                 if(beep_cnt>=25)  //500ms计时
  213.                 {
  214.                     beep_cnt=0;
  215.                         beep=~beep;
  216.                         beep_end_cnt--;
  217.                         if(beep_end_cnt==0||beep_end_cnt==255)
  218.                         {
  219.                                 beep_flag=0;
  220.                                 beep_end_flag=1;
  221.                         }
  222.                 }
  223.         }
  224.         else
  225.         {
  226.                 beep_cnt=0;
  227.                 beep=1; //关蜂鸣器
  228.         }
  229. }
  230. /**********************************************************/
  231. /**********显示3位数据**************************/
  232. void dis_3byte(uchar dat)
  233. {
  234.     LCD1602_Write(LCD1602_data,dat/100+0x30);
  235.         LCD1602_Write(LCD1602_data,dat%100/10+0x30);
  236.         LCD1602_Write(LCD1602_data,dat%10+0x30);
  237. }
  238. /***********************************************/
  239. /****************************************************/
  240. void Delay150us()                //@12.000MHz
  241. {
  242.         unsigned char i;

  243.         _nop_();
  244.         i = 72;
  245.         while (--i);
  246. }
  247. /*--------------------------------------
  248. ;功    能:实现三线单字节低位在前串口通信函数适用于WT588D
  249. ;入    参:无
  250. ;出    参:0            返回主函数
  251. ;-------------------------------------*/
  252. /*************三线串口通信程序***********************/
  253.         Send_threelines(unsigned char addr) //三线发码子程序
  254.         {
  255.                 unsigned char i;
  256.                 RST=0;
  257.                 Delay1ms(5);
  258.                 RST=1;
  259.                 Delay1ms(20); /* 复位拉高20ms*/
  260.                 CS=0;
  261.                 Delay1ms(5); /* 片选拉低5ms */
  262.                 for(i=0;i<8;i++)
  263.                 {
  264.                         SCL=0;
  265.                         if(addr & 1)SDA=1;
  266.                         else SDA=0;
  267.                         addr>>=1;
  268.                         Delay150us(); /* 150us */
  269.                         SCL=1;
  270.                         Delay150us();
  271.                 }
  272.                 CS=1;
  273.                 Delay1ms(30);
  274.         }
  275. /***************************************************/
  276. /***********语音数据转换****************************/
  277. sound_dat_cov(uchar num,uchar dat,uchar *buf)  //窗口号,窗口数值 播放缓存
  278. {
  279.     uchar n=0;
  280.     *(buf+n)=10; //播放'请'
  281.         n++;
  282.         *(buf+n)=dat/100; //播放数值
  283.         n++;
  284.         *(buf+n)=dat%100/10; //播放数值
  285.         n++;
  286.         *(buf+n)=dat%10; //播放数值
  287.         n++;
  288.     *(buf+n)=11; //播放'号到'
  289.         n++;
  290.     *(buf+n)=num; //播放数值
  291.         n++;
  292.     *(buf+n)=12; //播放'号窗口'
  293. }
  294. /***************************************************/
  295. /***********语音播报数据****************************/
  296. void play_data(void)           
  297. {
  298.         if(busy) //不播放时为1,播放时为0
  299.         {
  300.                 if(play_cnt<play_end_cnt)
  301.                 {
  302.                     if(play_cnt==0)
  303.                         {
  304.                             if(NO1_sta==1||NO2_sta==1||NO3_sta==1)
  305.                                 {
  306.                                         if(beep_flag==0&&beep_end_flag==0)  //蜂鸣标志
  307.                                         {
  308.                                             beep_flag=1;
  309.                                                 beep_end_cnt=2;         
  310.                                         }
  311.                                 }
  312.                         }
  313.                         if(beep_end_flag==1)
  314.                         {
  315.                                 switch(play_part_sta)
  316.                                 {
  317.                                         case 0:
  318.                                                 if(NO1_sta==1)
  319.                                                         {
  320.                                                                 Send_threelines(sound_buf1[play_cnt]);        //播放语音
  321.                                                                 play_cnt++;
  322.                                                         }
  323.                                                         else
  324.                                                                 play_cnt=7;
  325.                                                         break;
  326.                                         case 1:
  327.                                                 if(NO2_sta==1)
  328.                                                         {
  329.                                                                 Send_threelines(sound_buf2[play_cnt]);        //播放语音
  330.                                                                 play_cnt++;
  331.                                                         }
  332.                                                         else
  333.                                                                 play_cnt=7;
  334.                                                         break;
  335.                                         case 2:
  336.                                                 if(NO3_sta==1)
  337.                                                         {
  338.                                                                 Send_threelines(sound_buf3[play_cnt]);        //播放语音
  339.                                                                 play_cnt++;
  340.                                                         }
  341.                                                         else
  342.                                                                 play_cnt=7;
  343.                                                         break;
  344.                                 }
  345.                         }
  346.                 }
  347.                 else         //一段语音播放完毕
  348.                 {
  349.                         beep_end_flag=0;
  350.                         //播放切换
  351.                     play_part_sta++; //0为一号窗口,1为二号窗口,3为三号窗口
  352.                         if(play_part_sta>=3)
  353.                         {
  354.                                 play_part_sta=0;
  355.                         }
  356.                         if(play_part_sta==0)
  357.                         {
  358.                         if(NO1_sta==1&&NO1_number!=0)
  359.                                 {
  360.                                         play_cnt=0;
  361.                                 }
  362.                                 else play_part_sta++;
  363.                         }
  364.                         if(play_part_sta==1)
  365.                         {
  366.                         if(NO2_sta==1&&NO2_number!=0)
  367.                                 {
  368.                                         play_cnt=0;
  369.                                 }
  370.                                 else play_part_sta++;
  371.                         }
  372.                         if(play_part_sta==2)
  373.                         {
  374.                         if(NO3_sta==1&&NO3_number!=0)
  375.                                 {
  376.                                         play_cnt=0;
  377.                                 }
  378.                         }
  379.                 }
  380.         }
  381. }
  382. /****************************************************/
  383. /**************按键扫描程序********************************/
  384. void key_check(void)
  385. {
  386.         //一号窗
  387.         if(call_key1==0)        //呼叫键
  388.         {
  389.                 Delay1ms(80);
  390.                 if(call_key1==0)
  391.                 {
  392.                         send_buf[1]=1;  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 呼叫号码(1~255) 0x5a(结束位)
  393.                         uart_T_flag=1;  //串口数据发送标志
  394.                         while(!call_key1); //等待按键释放
  395.                 }  
  396.         }
  397.         else if(recall_key1==0)  //重复呼叫键
  398.         {
  399.                 Delay1ms(100);
  400.             if(recall_key1==0)
  401.                 {
  402.                     if(NO1_number!=0)
  403.                         NO1_sta=1;  //一号窗状态  0暂停呼叫,1开始呼叫
  404.                 }
  405.         }
  406.         else if(mute_key1==0)        //消音键
  407.         {
  408.                 Delay1ms(100);
  409.                 if(mute_key1==0)
  410.                 {
  411.                     NO1_sta=0;  //一号窗状态  0暂停呼叫,1开始呼叫
  412.                 }
  413.         }
  414.         else if(stop_key1==0)        //暂停键
  415.         {
  416.             Delay1ms(100);
  417.                 if(stop_key1==0)
  418.                 {
  419.                         NO1_sta=0;  //一号窗状态  0暂停呼叫,1开始呼叫
  420.                         NO1_number=0;
  421.                     LCD1602_Print(0,1,"---");
  422.                 }
  423.         }
  424.         //二号窗
  425.         if(call_key2==0)        //呼叫键
  426.         {
  427.                 Delay1ms(80);
  428.                 if(call_key2==0)
  429.                 {
  430.                         send_buf[1]=2;  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 呼叫号码(1~255) 0x5a(结束位)
  431.                         uart_T_flag=1;  //串口数据发送标志
  432.                         while(!call_key2); //等待按键释放
  433.                 }  
  434.         }
  435.         else if(recall_key2==0)  //重复呼叫键
  436.         {
  437.                 Delay1ms(100);
  438.             if(recall_key2==0)
  439.                 {
  440.                     if(NO2_number!=0)
  441.                         NO2_sta=1;  //一号窗状态  0暂停呼叫,1开始呼叫
  442.                 }
  443.         }
  444.         else if(mute_key2==0)        //消音键
  445.         {
  446.                 Delay1ms(100);
  447.                 if(mute_key2==0)
  448.                 {
  449.                     NO2_sta=0;  //一号窗状态  0暂停呼叫,1开始呼叫
  450.                 }
  451.         }
  452.         else if(stop_key2==0)        //暂停键
  453.         {
  454.             Delay1ms(100);
  455.                 if(stop_key2==0)
  456.                 {
  457.                         NO2_sta=0;  //一号窗状态  0暂停呼叫,1开始呼叫
  458.                         NO2_number=0;
  459.                     LCD1602_Print(6,1,"---");
  460.                 }
  461.         }
  462.         //三号窗
  463.         if(call_key3==0)        //呼叫键
  464.         {
  465.                 Delay1ms(80);
  466.                 if(call_key3==0)
  467.                 {
  468.                         send_buf[1]=3;  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 呼叫号码(1~255) 0x5a(结束位)
  469.                         uart_T_flag=1;  //串口数据发送标志
  470.                         while(!call_key3); //等待按键释放
  471.                 }  
  472.         }
  473.         else if(recall_key3==0)  //重复呼叫键
  474.         {
  475.                 Delay1ms(100);
  476.             if(recall_key3==0)
  477.                 {
  478.                     if(NO3_number!=0)
  479.                         NO3_sta=1;  //一号窗状态  0暂停呼叫,1开始呼叫
  480.                 }
  481.         }
  482.         else if(mute_key3==0)        //消音键
  483.         {
  484.                 Delay1ms(100);
  485.                 if(mute_key3==0)
  486.                 {
  487.                     NO3_sta=0;  //一号窗状态  0暂停呼叫,1开始呼叫
  488.                 }
  489.         }
  490.         else if(stop_key3==0)        //暂停键
  491.         {
  492.             Delay1ms(100);
  493.                 if(stop_key3==0)
  494.                 {
  495.                         NO3_sta=0;  //一号窗状态  0暂停呼叫,1开始呼叫
  496.                         NO3_number=0;
  497.                     LCD1602_Print(12,1,"---");
  498.                 }
  499.         }
  500. }
  501. /**********************************************************/
  502. /**************主程序**************************************/
  503. void main(void)
  504. {
  505.     LCD1602_init(); //初始化液晶
  506.         LCD1602_Print(0,0,"NO.1  NO.2  NO.3");
  507.         LCD1602_Print(0,1,"---   ---   --- ");
  508.     serial_init();  //串口初始化程序
  509.     TMOD=0x21;      //设置定时器0为16位模式
  510.         TL0 = 0x00;                //设置定时初值         20ms  11.0592MHz
  511.         TH0 = 0xB8;                //设置定时初值
  512.         TR0=1;
  513.         ET0=1;
  514.         EA=1;

  515.         while(1)
  516.         {
  517.                 key_check();      //按键扫描程序         
  518.                 if(uart_R_flag==1)//串口数据接收完毕标志
  519.                 {
  520.                     switch(receive[1])  //判断机器号
  521.                         {
  522.                                 case 1:
  523.                                         NO1_number=receive[2]; //窗口一号码
  524.                                                 if(receive[2]!=0)
  525.                                                 {
  526.                                                         GotoXY(0,1);
  527.                                                         dis_3byte(NO1_number);
  528.                                                         NO1_sta=1;  //一号窗状态  0暂停呼叫,1开始呼叫
  529.                                                         //语音数据转换
  530.                                                         sound_dat_cov(1,NO1_number,sound_buf1);  //窗口号,窗口数值 播放缓存

  531.                                                 }
  532.                                                 break;
  533.                                 case 2:
  534.                                         NO2_number=receive[2]; //窗口二号码
  535.                                                 if(receive[2]!=0)
  536.                                                 {
  537.                                                         GotoXY(6,1);
  538.                                                         dis_3byte(NO2_number);
  539.                                                         NO2_sta=1;  //一号窗状态  0暂停呼叫,1开始呼叫
  540.                                                         //语音数据转换
  541.                                                         sound_dat_cov(2,NO2_number,sound_buf2);  //窗口号,窗口数值 播放缓存
  542.                                                 }
  543.                                                 break;
  544.                                 case 3:
  545.                                         NO3_number=receive[2]; //窗口三号码
  546.                                                 if(receive[2]!=0)
  547.                                                 {
  548.                                                         GotoXY(12,1);
  549.                                                         dis_3byte(NO3_number);
  550.                                                         NO3_sta=1;  //一号窗状态  0暂停呼叫,1开始呼叫
  551.                                                         //语音数据转换
  552.                                                         sound_dat_cov(3,NO3_number,sound_buf3);  //窗口号,窗口数值 播放缓存
  553.                                                 }
  554.                                                 break;
  555.                         }
  556.                         uart_R_flag=0;      //串口数据接收完毕标志
  557.                 }
  558.                 if(uart_T_flag==1)  //串口数据发送标志
  559.                 {
  560.                         send_buf[0]=0xa5;  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 指令(0x01取号) 0x5a(结束位)
  561.                         send_buf[2]=0x01;  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 指令(0x01取号) 0x5a(结束位)
  562.                         send_buf[3]=0x5a;
  563.                         send_uart_dat(send_buf[0]); //发送数据
  564.                         send_uart_dat(send_buf[1]); //发送数据  
  565.                         send_uart_dat(send_buf[2]); //发送数据
  566.                         send_uart_dat(send_buf[3]); //发送数据
  567.                         uart_T_flag=0;  //串口数据发送标志
  568.                 }
  569.                 //语音播报
  570.                 play_data(); //语音播报数据
  571.         }
  572. }


  573. /*************************************************************************
  574. *工程名称: 排队叫号系统----取号模块程序                             *
  575. *单片机型号:STC89C52RC                                                  *
  576. *晶振频率:11.0592MHz                                                                                                        *
  577. *功能描述:按下取号键,开始取号                                          *
  578. *作者:新兴光电                                                          *
  579. *日期:2016-03-01                                                        *
  580. *************************************************************************/
  581. #include<reg51.h>
  582. #include <intrins.h>
  583. #include "LCD1602.h"

  584. #define uchar unsigned char
  585. #define uint unsigned int
  586. #define FOSC 11059200L      //系统晶振频率
  587. #define BAUD 9600           //串口波特率
  588. #define SMOD 1              //为1,加倍波特率计算
  589. #if SMOD
  590.         #define TC_VAL (256-FOSC/16/12/BAUD)
  591. //#else   #define TC_VAL (256-FOSC/32/12/BAUD)
  592. #endif
  593. /**********端口定义********************************/
  594. sbit get_key=P2^0;  //取号键
  595. sbit clear_key=P2^1; //清0键
  596. /**************************************************/
  597. /***********寄存器定义*****************************/
  598. uchar dis_buf[4];
  599. //以下为串口用到的寄存器
  600. bit uart_R_flag=0;   //串口接收完毕标志
  601. bit busy=0;               //串口忙检测
  602. uchar receive[4];         //数据接收格式  0xa5(起始位) 机器号(1~3) 指令(0x01取号) 0x5a(结束位)
  603. uchar send_buf[4];  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 呼叫号码(1~255) 0x5a(结束位)
  604. uchar rec_cnt=0;
  605. //呼叫取号相关寄存器
  606. uchar get_cnt=0;   //取号计数
  607. uchar call_cnt=0;  //呼叫计数
  608. /**************************************************/
  609. /***************延时程序***************************/
  610. void Delay1ms(uint t)    //1ms延时程序
  611. {
  612.         uchar j;
  613.         while(t--)
  614.         {
  615.                 for(j=0;j<125;j++)
  616.                 { ; }
  617.         }
  618. }
  619. /**************************************************/
  620. /**********转换显示*********************************/
  621. void cov_dis(uchar dis_dat)
  622. {
  623.         dis_buf[0]=dis_dat/100+0x30;
  624.         dis_buf[1]=dis_dat%100/10+0x30;
  625.         dis_buf[2]=dis_dat%100%10+0x30;
  626.         dis_buf[3]='\0';
  627. }
  628. /***************************************************/
  629. /*************串口初始化程序***********************/
  630. void serial_init(void)
  631. {
  632.         TMOD=0x21;                                  //定时器1设为8位自动重装
  633.         SCON=0x50;            //8位数据串口,波特率可变  无校验位
  634.         TH1=TC_VAL;        //定时初始值
  635.         TL1=TH1;
  636.         PCON=0x80;
  637.         ES = 1;                 //串口中断充许
  638.         EA = 1;                 //总中断允许
  639.         TR1=1;
  640. }
  641. /**************************************************/
  642. /***********串口中断服务程序*********************/
  643. void serial() interrupt 4
  644. {
  645.     if (RI)
  646.     {
  647.         RI = 0;            //串口接收中断完毕标志清0
  648.             //uart_buf=SBUF;   //接收数据
  649.         //        call_cnt=SBUF;      //接收数据  获得叫号数
  650.                 receive[rec_cnt]=SBUF;   //接收数据
  651.                 rec_cnt++;
  652.                 if(receive[0]==0xa5) //判断起始位
  653.                 {
  654.                         if(receive[rec_cnt-1]==0x5a&&rec_cnt==4)  //数据接收完毕
  655.                         {
  656.                                 uart_R_flag=1;   //串口接收完毕标志
  657.                             send_buf[1]=receive[1]; //获取机器号
  658.                         }
  659.                 }
  660.                 else rec_cnt=0;
  661.                 if(rec_cnt>=4)
  662.                         rec_cnt=0;
  663.     }
  664.     if (TI)
  665.     {
  666.         TI = 0;             //串口发送中断完毕标志清0
  667.         busy = 0;           //串口忙标志清0
  668.     }
  669. }
  670. /***************************************************/
  671. /*************串口发送一字节数据程序****************/
  672. void send_uart_dat(uchar dat)
  673. {
  674.     while (busy);           //忙检测标志 等后上一字节数据发送完毕
  675.     ACC = dat;              //Calculate the even parity bit P (PSW.0)
  676.     busy = 1;
  677.     SBUF = ACC;             //发送数据至串口发送缓冲寄存器
  678. }
  679. /***************************************************/
  680. /*************串口发送字符串数据程序****************
  681. void send_uart_stringdat(uchar *s)
  682. {
  683.     while (*s)              //检查数据是否结束
  684.     {
  685.         send_uart_dat(*s++);     //发送字符串
  686.     }
  687. }
  688. /***************************************************/
  689. /********串口发送字符串数据程序*********************
  690. void send_uart_stringdat(uchar *send_dat)
  691. {
  692.     do              
  693.     {            
  694.         send_uart_dat(*send_dat);     //发送字符
  695.                 send_dat++;
  696.     }while(*send_dat!='\0');     //检查数据是否结束   
  697. }
  698. /***************************************************/
  699. /**************主程序*******************************/
  700. void main(void)
  701. {
  702.     serial_init();  //串口初始化程序
  703.         LCD1602_init(); //LCD1602初始化程序
  704.         GotoXY(0,0);
  705.         Print("  number:       "); //显示英文”排号系统“
  706.         GotoXY(0,1);
  707.         Print("  Waiting:      ");
  708.         get_cnt=0; //号码计数
  709.         call_cnt=0;        //排队号
  710.         while(1)
  711.         {
  712.                 if(get_key==0)         //取号键
  713.                 {
  714.                     Delay1ms(100);
  715.                         if(get_key==0)
  716.                         {
  717.                                 if(get_cnt<255)
  718.                                 {
  719.                                         get_cnt++;   //取号计数
  720.                                 }
  721.                                 else
  722.                                 {
  723.                                         get_cnt=255;
  724.                                 }
  725.                         }
  726.                 }
  727.                 if(clear_key==0) //清0键
  728.                 {
  729.                         Delay1ms(100);
  730.                         if(clear_key==0)
  731.                         {
  732.                                 get_cnt=0;
  733.                                 call_cnt=0;
  734.                                 while(!clear_key); //等待按键释放
  735.                         }
  736.                 }
  737.                 if(uart_R_flag==1)   //串口接收完毕标志
  738.                 {
  739.                         if(receive[2]==0x01)  //取号指令
  740.                         {
  741.                             send_buf[0]=0xa5;  //发送缓存  格式 0xa5(起始位) 机器号(1~3) 呼叫号码(1~255) 0x5a(结束位)
  742.                                 send_buf[3]=0x5a;  
  743.                                 call_cnt++;
  744.                                 if(get_cnt!=0)
  745.                                 {
  746.                                         if(call_cnt<=get_cnt)
  747.                                                 send_buf[2]=call_cnt;  //排队号         有人等候
  748.                                         else
  749.                                         {
  750.                                             call_cnt=call_cnt-1;
  751.                                             send_buf[2]=0;  //排队号   无人等候,
  752.                                         }
  753.                                 }
  754.                                 else
  755.                                 {
  756.                                         send_buf[2]=0;
  757.                                         call_cnt=0;
  758.                                 }

  759.                                 send_uart_dat(send_buf[0]); //发送数据
  760.                                 send_uart_dat(send_buf[1]); //发送数据  
  761.                                 send_uart_dat(send_buf[2]); //发送数据
  762.                                 send_uart_dat(send_buf[3]); //发送数据
  763.                         }
  764.                         uart_R_flag=0;
  765.                 }
  766.                         cov_dis(get_cnt);
  767.                         LCD1602_Print(10,0,dis_buf);   //显示取号数
  768.                         if(get_cnt!=call_cnt)
  769.                         {
  770.                                 cov_dis(get_cnt-call_cnt);
  771.                                 LCD1602_Print(11,1,dis_buf);   //显示等候人数
  772.                         }
  773.                         else LCD1602_Print(11,1,"000");   //显示等候人数
  774.                         
  775.                         
  776.         }
  777. }
  778. /***************************************************/
复制代码



源程序.rar

427.69 KB, 下载次数: 114, 下载积分: 黑币 -5

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:347892 发表于 2018-10-19 09:55 | 显示全部楼层
学习了,谢谢
回复

使用道具 举报

ID:426970 发表于 2018-11-15 12:05 来自手机 | 显示全部楼层
有文字备注,很不错,谢谢
回复

使用道具 举报

ID:431034 发表于 2018-11-29 08:20 | 显示全部楼层
谢谢楼主分享,谢谢喽
回复

使用道具 举报

ID:478351 发表于 2019-3-5 11:46 | 显示全部楼层
谢谢楼主分享,谢谢喽
回复

使用道具 举报

ID:48413 发表于 2019-3-5 13:19 | 显示全部楼层
太牛了吧!!!
回复

使用道具 举报

ID:399179 发表于 2019-3-5 19:20 来自手机 | 显示全部楼层
这个真不错!
回复

使用道具 举报

ID:567110 发表于 2019-6-19 20:15 | 显示全部楼层
你好,请问有proteus的仿真图吗
回复

使用道具 举报

ID:564496 发表于 2019-6-21 08:39 | 显示全部楼层
很有用吖吖
回复

使用道具 举报

ID:567110 发表于 2019-6-22 14:32 | 显示全部楼层

请问你做过排队叫号系统的设计吗
回复

使用道具 举报

ID:423911 发表于 2020-2-19 18:19 | 显示全部楼层
谢谢楼主分享,谢谢喽
回复

使用道具 举报

ID:89286 发表于 2020-2-22 09:05 | 显示全部楼层
thanks for sharing
回复

使用道具 举报

ID:248073 发表于 2020-5-27 11:39 | 显示全部楼层
太厉害啦
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表