|
這個(gè)是我同學(xué)搞的設(shè)計(jì),他是網(wǎng)上買的程序,本質(zhì)上就是個(gè)基于STC89C52的排隊(duì)叫號(hào),組成的東西也簡(jiǎn)單,2個(gè)STC,2個(gè)1602,蜂鳴器,一堆獨(dú)立按鍵,還有個(gè)WT588D語(yǔ)言芯片和喇叭,通信用的是有線的串口。具體實(shí)現(xiàn)的功能我會(huì)發(fā)個(gè)視頻鏈接。發(fā)出來(lái)也是為需要的人省點(diǎn)錢。具體的電氣連接參考keil程序的引腳定義就可以了,語(yǔ)言芯片要導(dǎo)入的源文件也在壓縮包里面。總體來(lái)講這個(gè)設(shè)計(jì)沒(méi)什么復(fù)雜的東西,正常的設(shè)計(jì)是不需要語(yǔ)音播報(bào)的。如果覺得獨(dú)立按鍵較多也可以自己改成矩陣鍵盤,反正這東西焊獨(dú)立按鍵也是要花點(diǎn)時(shí)間的。
視頻的連接如下
https://pan.baidu.com/s/1vc_4T3Y6zcxwFNuki_eOEA
單片機(jī)源碼:
- /*************************************************************************
- *工程名稱: 排隊(duì)叫號(hào)系統(tǒng)----叫號(hào)模塊程序 *
- *單片機(jī)型號(hào):STC89C52RC *
- *晶振頻率:11.0592MHz *
- *作者:新興光電 *
- *日期:2016-03-01 *
- *************************************************************************/
- #include<reg51.h>
- #include <intrins.h>
- #include "LCD1602.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define FOSC 11059200L //系統(tǒng)晶振頻率
- #define BAUD 9600 //串口波特率
- #define SMOD 1 //為1,加倍波特率計(jì)算
- #if SMOD
- #define TC_VAL (256-FOSC/16/12/BAUD)
- //#else #define TC_VAL (256-FOSC/32/12/BAUD)
- #endif
- /**********端口定義*******************************/
- sbit call_key1=P1^0; //呼叫鍵
- sbit recall_key1=P1^1; //重復(fù)呼叫鍵
- sbit mute_key1=P1^2; //消音鍵
- sbit stop_key1=P1^3; //暫停鍵
- sbit call_key2=P1^4; //呼叫鍵
- sbit recall_key2=P1^5; //重復(fù)呼叫鍵
- sbit mute_key2=P1^6; //消音鍵
- sbit stop_key2=P1^7; //暫停鍵
- sbit call_key3=P3^2; //呼叫鍵
- sbit recall_key3=P3^3; //重復(fù)呼叫鍵
- sbit mute_key3=P3^4; //消音鍵
- sbit stop_key3=P3^5; //暫停鍵
- sbit beep=P3^6; //蜂鳴器
- //語(yǔ)音相關(guān)
- sbit RST=P2^4; //復(fù)位腳 在非工業(yè)場(chǎng)合下這個(gè)可以不要
- sbit busy=P2^3; //WT588D忙檢測(cè)端口 無(wú)播放時(shí)輸出高電平
- sbit SDA=P2^2;
- sbit CS =P2^1;
- sbit SCL=P2^0;
- /**************************************************/
- /***********寄存器定義*****************************/
- /*
- uchar code TAB[12] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40,0x00};
- //以上為共陰數(shù)碼管段碼表 0 1 2 3 4 5 6 7 8 9 - 無(wú)
- uchar dis_buf[9]; //顯示緩存
- uchar dis_cnt; //顯示計(jì)數(shù) */
- //以下為串口用到的寄存器
- bit uart_busy; //串口忙檢測(cè)
- bit uart_R_flag=0; //串口數(shù)據(jù)接收完畢標(biāo)志
- bit uart_T_flag=0; //串口數(shù)據(jù)發(fā)送標(biāo)志
- //uchar uart_buf; //串口數(shù)據(jù)寄存器
- //uchar count;
- uchar receive[4]; //數(shù)據(jù)接收格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 呼叫號(hào)碼(0x01取號(hào)) 0x5a(結(jié)束位)
- uchar send_buf[4]; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 指令(0x01取號(hào)) 0x5a(結(jié)束位)
- uchar rec_cnt=0;
- //呼叫相關(guān)寄存器
- //uchar get_cnt=0; //取號(hào)計(jì)數(shù)
- //uchar call_cnt=0; //呼叫計(jì)數(shù)
- bit NO1_sta=0; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- bit NO2_sta=0; //二號(hào)窗狀態(tài)
- bit NO3_sta=0; //三號(hào)窗狀態(tài)
- uchar NO1_number; //窗口一號(hào)碼
- uchar NO2_number; //窗口二號(hào)碼
- uchar NO3_number; //窗口三號(hào)碼
- //蜂鳴器相關(guān)定義
- bit beep_flag=0; //蜂鳴標(biāo)志
- bit beep_end_flag=0;
- uchar beep_cnt=0; //蜂鳴器計(jì)數(shù)
- uchar beep_end_cnt=0;
- //語(yǔ)音播放地址定義:
- //0--播放"0"; 1--播放"1"; 2--播放"2"; 3--播放"3"; 4--播放"4"; 5--播放"5"; 6--播放"6"; 7--播放"7";
- //8--播放"8"; 9--播放"9"; 10--播放"請(qǐng)"; 11--播放"號(hào)到"; 12--播放"號(hào)窗口";
- // 三線串口,音頻輸出PWM,忙信號(hào)輸出LOW
- //WT588D相關(guān)寄存器定義
- //一線,二線,三線有關(guān)
- #define H 1 //定義1為高電平
- #define L 0 //定義0為低電平
- //////////////變量/////////////////
- //bit flag = 1;
- bit B_DATA; //傳輸數(shù)據(jù)一位
- unsigned char SB_DATA = 0; //一字節(jié)公用數(shù)據(jù)緩存器
- unsigned char S_DATA = 0x00;
- bit play_flag=0; //播放標(biāo)志
- uchar play_part_sta=0; //0為一號(hào)窗口,1為二號(hào)窗口,3為三號(hào)窗口
- uchar play_cnt;
- uchar play_end_cnt=7;
- uchar idata sound_buf1[7];
- uchar idata sound_buf2[7];
- uchar idata sound_buf3[7];
- /**************************************************/
- /***************延時(shí)程序***************************/
- void Delay1ms(uint t) //1ms延時(shí)程序
- {
- uchar j;
- while(t--)
- {
- for(j=0;j<125;j++)
- { ; }
- }
- }
- /**************************************************/
- /*************串口初始化程序***********************/
- void serial_init(void)
- {
- PCON=0x80;
- SCON=0x50; //8位數(shù)據(jù)串口,波特率可變 無(wú)校驗(yàn)位
- TMOD=0x21; //定時(shí)器1設(shè)為8位自動(dòng)重裝
- TH1=TC_VAL; //定時(shí)初始值
- TL1=TH1;
- ES = 1; //串口中斷允許
- EA = 1; //總中斷允許
- TR1=1;
- }
- /**************************************************/
- /***********串口中斷服務(wù)程序*********************/
- void serial() interrupt 4
- {
- if (RI)
- {
- RI = 0; //串口接收中斷完畢標(biāo)志清0
- //uart_buf=SBUF; //接收數(shù)據(jù)
- // call_cnt=SBUF; //接收數(shù)據(jù) 獲得叫號(hào)數(shù)
- receive[rec_cnt]=SBUF; //接收數(shù)據(jù)
- rec_cnt++;
- if(receive[0]==0xa5) //判斷起始位
- {
- if(receive[rec_cnt-1]==0x5a&&rec_cnt==4) //數(shù)據(jù)接收完畢
- {
- uart_R_flag=1; //串口接收完畢標(biāo)志
- }
- }
- else rec_cnt=0;
- if(rec_cnt>=4)
- rec_cnt=0;
- }
- if (TI)
- {
- TI = 0; //串口發(fā)送中斷完畢標(biāo)志清0
- uart_busy = 0; //串口忙標(biāo)志清0
- }
- }
- /***************************************************/
- /*************串口發(fā)送一字節(jié)數(shù)據(jù)程序****************/
- void send_uart_dat(uchar dat)
- {
- while (uart_busy); //忙檢測(cè)標(biāo)志 等后上一字節(jié)數(shù)據(jù)發(fā)送完畢
- ACC = dat; //Calculate the even parity bit P (PSW.0)
- uart_busy = 1;
- SBUF = ACC; //發(fā)送數(shù)據(jù)至串口發(fā)送緩沖寄存器
- }
- /***************************************************/
- /*************串口發(fā)送字符串?dāng)?shù)據(jù)程序****************
- void send_uart_stringdat(uchar *s)
- {
- while (*s) //檢查數(shù)據(jù)是否結(jié)束
- {
- send_uart_dat(*s++); //發(fā)送字符串
- }
- }
- /***************************************************/
- /********串口發(fā)送字符串?dāng)?shù)據(jù)程序*********************
- void send_uart_stringdat(uchar *send_dat)
- {
- do
- {
- send_uart_dat(*send_dat); //發(fā)送字符
- send_dat++;
- }while(*send_dat!='\0'); //檢查數(shù)據(jù)是否結(jié)束
- }
- /***************************************************/
- /********數(shù)據(jù)轉(zhuǎn)換用于顯示***************************
- void cov_dis(uchar num1,uchar num2,uchar num3)
- {
- dis_buf[0]=TAB[num1/100]; //顯示緩存
- dis_buf[1]=TAB[num1%100/10]; //顯示緩存
- dis_buf[2]=TAB[num1%100%10]; //顯示緩存
-
- dis_buf[3]=TAB[num2/100]; //顯示緩存
- dis_buf[4]=TAB[num2%100/10]; //顯示緩存
- dis_buf[5]=TAB[num2%100%10]; //顯示緩存
-
- dis_buf[6]=TAB[num3/100]; //顯示緩存
- dis_buf[7]=TAB[num3%100/10]; //顯示緩存
- dis_buf[8]=TAB[num3%100%10]; //顯示緩存
- }
- /***************************************************/
- /*********定時(shí)器0中斷服務(wù)程序***********************/
- void timer0(void) interrupt 1
- {
- TL0 = 0x00; //設(shè)置定時(shí)初值 20ms 11.0592MHz
- TH0 = 0xB8; //設(shè)置定時(shí)初值
- /* P2=0xff;
- DIG1=1;
- Dport=0x00;
- dis_cnt++; //顯示計(jì)數(shù)
- switch(dis_cnt)
- {
- case 1: DIG1=0; Dport=dis_buf[0]; break;
- case 2: DIG2=0; Dport=dis_buf[1]; break;
- case 3: DIG3=0; Dport=dis_buf[2]; break;
- case 4: DIG4=0; Dport=dis_buf[3]; break;
- case 5: DIG5=0; Dport=dis_buf[4]; break;
- case 6: DIG6=0; Dport=dis_buf[5]; break;
- case 7: DIG7=0; Dport=dis_buf[6]; break;
- case 8: DIG8=0; Dport=dis_buf[7]; break;
- case 9: dis_cnt=0; DIG9=0; Dport=dis_buf[8]; break;
- }
- */
- if(beep_flag==1) //蜂鳴標(biāo)志
- {
- beep_cnt++; //蜂鳴計(jì)數(shù)
- if(beep_cnt>=25) //500ms計(jì)時(shí)
- {
- beep_cnt=0;
- beep=~beep;
- beep_end_cnt--;
- if(beep_end_cnt==0||beep_end_cnt==255)
- {
- beep_flag=0;
- beep_end_flag=1;
- }
- }
- }
- else
- {
- beep_cnt=0;
- beep=1; //關(guān)蜂鳴器
- }
- }
- /**********************************************************/
- /**********顯示3位數(shù)據(jù)**************************/
- void dis_3byte(uchar dat)
- {
- LCD1602_Write(LCD1602_data,dat/100+0x30);
- LCD1602_Write(LCD1602_data,dat%100/10+0x30);
- LCD1602_Write(LCD1602_data,dat%10+0x30);
- }
- /***********************************************/
- /****************************************************/
- void Delay150us() //@12.000MHz
- {
- unsigned char i;
- _nop_();
- i = 72;
- while (--i);
- }
- /*--------------------------------------
- ;功 能:實(shí)現(xiàn)三線單字節(jié)低位在前串口通信函數(shù)適用于WT588D
- ;入 參:無(wú)
- ;出 參:0 返回主函數(shù)
- ;-------------------------------------*/
- /*************三線串口通信程序***********************/
- Send_threelines(unsigned char addr) //三線發(fā)碼子程序
- {
- unsigned char i;
- RST=0;
- Delay1ms(5);
- RST=1;
- Delay1ms(20); /* 復(fù)位拉高20ms*/
- CS=0;
- Delay1ms(5); /* 片選拉低5ms */
- for(i=0;i<8;i++)
- {
- SCL=0;
- if(addr & 1)SDA=1;
- else SDA=0;
- addr>>=1;
- Delay150us(); /* 150us */
- SCL=1;
- Delay150us();
- }
- CS=1;
- Delay1ms(30);
- }
- /***************************************************/
- /***********語(yǔ)音數(shù)據(jù)轉(zhuǎn)換****************************/
- sound_dat_cov(uchar num,uchar dat,uchar *buf) //窗口號(hào),窗口數(shù)值 播放緩存
- {
- uchar n=0;
- *(buf+n)=10; //播放'請(qǐng)'
- n++;
- *(buf+n)=dat/100; //播放數(shù)值
- n++;
- *(buf+n)=dat%100/10; //播放數(shù)值
- n++;
- *(buf+n)=dat%10; //播放數(shù)值
- n++;
- *(buf+n)=11; //播放'號(hào)到'
- n++;
- *(buf+n)=num; //播放數(shù)值
- n++;
- *(buf+n)=12; //播放'號(hào)窗口'
- }
- /***************************************************/
- /***********語(yǔ)音播報(bào)數(shù)據(jù)****************************/
- void play_data(void)
- {
- if(busy) //不播放時(shí)為1,播放時(shí)為0
- {
- if(play_cnt<play_end_cnt)
- {
- if(play_cnt==0)
- {
- if(NO1_sta==1||NO2_sta==1||NO3_sta==1)
- {
- if(beep_flag==0&&beep_end_flag==0) //蜂鳴標(biāo)志
- {
- beep_flag=1;
- beep_end_cnt=2;
- }
- }
- }
- if(beep_end_flag==1)
- {
- switch(play_part_sta)
- {
- case 0:
- if(NO1_sta==1)
- {
- Send_threelines(sound_buf1[play_cnt]); //播放語(yǔ)音
- play_cnt++;
- }
- else
- play_cnt=7;
- break;
- case 1:
- if(NO2_sta==1)
- {
- Send_threelines(sound_buf2[play_cnt]); //播放語(yǔ)音
- play_cnt++;
- }
- else
- play_cnt=7;
- break;
- case 2:
- if(NO3_sta==1)
- {
- Send_threelines(sound_buf3[play_cnt]); //播放語(yǔ)音
- play_cnt++;
- }
- else
- play_cnt=7;
- break;
- }
- }
- }
- else //一段語(yǔ)音播放完畢
- {
- beep_end_flag=0;
- //播放切換
- play_part_sta++; //0為一號(hào)窗口,1為二號(hào)窗口,3為三號(hào)窗口
- if(play_part_sta>=3)
- {
- play_part_sta=0;
- }
- if(play_part_sta==0)
- {
- if(NO1_sta==1&&NO1_number!=0)
- {
- play_cnt=0;
- }
- else play_part_sta++;
- }
- if(play_part_sta==1)
- {
- if(NO2_sta==1&&NO2_number!=0)
- {
- play_cnt=0;
- }
- else play_part_sta++;
- }
- if(play_part_sta==2)
- {
- if(NO3_sta==1&&NO3_number!=0)
- {
- play_cnt=0;
- }
- }
- }
- }
- }
- /****************************************************/
- /**************按鍵掃描程序********************************/
- void key_check(void)
- {
- //一號(hào)窗
- if(call_key1==0) //呼叫鍵
- {
- Delay1ms(80);
- if(call_key1==0)
- {
- send_buf[1]=1; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 呼叫號(hào)碼(1~255) 0x5a(結(jié)束位)
- uart_T_flag=1; //串口數(shù)據(jù)發(fā)送標(biāo)志
- while(!call_key1); //等待按鍵釋放
- }
- }
- else if(recall_key1==0) //重復(fù)呼叫鍵
- {
- Delay1ms(100);
- if(recall_key1==0)
- {
- if(NO1_number!=0)
- NO1_sta=1; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- }
- }
- else if(mute_key1==0) //消音鍵
- {
- Delay1ms(100);
- if(mute_key1==0)
- {
- NO1_sta=0; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- }
- }
- else if(stop_key1==0) //暫停鍵
- {
- Delay1ms(100);
- if(stop_key1==0)
- {
- NO1_sta=0; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- NO1_number=0;
- LCD1602_Print(0,1,"---");
- }
- }
- //二號(hào)窗
- if(call_key2==0) //呼叫鍵
- {
- Delay1ms(80);
- if(call_key2==0)
- {
- send_buf[1]=2; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 呼叫號(hào)碼(1~255) 0x5a(結(jié)束位)
- uart_T_flag=1; //串口數(shù)據(jù)發(fā)送標(biāo)志
- while(!call_key2); //等待按鍵釋放
- }
- }
- else if(recall_key2==0) //重復(fù)呼叫鍵
- {
- Delay1ms(100);
- if(recall_key2==0)
- {
- if(NO2_number!=0)
- NO2_sta=1; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- }
- }
- else if(mute_key2==0) //消音鍵
- {
- Delay1ms(100);
- if(mute_key2==0)
- {
- NO2_sta=0; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- }
- }
- else if(stop_key2==0) //暫停鍵
- {
- Delay1ms(100);
- if(stop_key2==0)
- {
- NO2_sta=0; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- NO2_number=0;
- LCD1602_Print(6,1,"---");
- }
- }
- //三號(hào)窗
- if(call_key3==0) //呼叫鍵
- {
- Delay1ms(80);
- if(call_key3==0)
- {
- send_buf[1]=3; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 呼叫號(hào)碼(1~255) 0x5a(結(jié)束位)
- uart_T_flag=1; //串口數(shù)據(jù)發(fā)送標(biāo)志
- while(!call_key3); //等待按鍵釋放
- }
- }
- else if(recall_key3==0) //重復(fù)呼叫鍵
- {
- Delay1ms(100);
- if(recall_key3==0)
- {
- if(NO3_number!=0)
- NO3_sta=1; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- }
- }
- else if(mute_key3==0) //消音鍵
- {
- Delay1ms(100);
- if(mute_key3==0)
- {
- NO3_sta=0; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- }
- }
- else if(stop_key3==0) //暫停鍵
- {
- Delay1ms(100);
- if(stop_key3==0)
- {
- NO3_sta=0; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- NO3_number=0;
- LCD1602_Print(12,1,"---");
- }
- }
- }
- /**********************************************************/
- /**************主程序**************************************/
- void main(void)
- {
- LCD1602_init(); //初始化液晶
- LCD1602_Print(0,0,"NO.1 NO.2 NO.3");
- LCD1602_Print(0,1,"--- --- --- ");
- serial_init(); //串口初始化程序
- TMOD=0x21; //設(shè)置定時(shí)器0為16位模式
- TL0 = 0x00; //設(shè)置定時(shí)初值 20ms 11.0592MHz
- TH0 = 0xB8; //設(shè)置定時(shí)初值
- TR0=1;
- ET0=1;
- EA=1;
- while(1)
- {
- key_check(); //按鍵掃描程序
- if(uart_R_flag==1)//串口數(shù)據(jù)接收完畢標(biāo)志
- {
- switch(receive[1]) //判斷機(jī)器號(hào)
- {
- case 1:
- NO1_number=receive[2]; //窗口一號(hào)碼
- if(receive[2]!=0)
- {
- GotoXY(0,1);
- dis_3byte(NO1_number);
- NO1_sta=1; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- //語(yǔ)音數(shù)據(jù)轉(zhuǎn)換
- sound_dat_cov(1,NO1_number,sound_buf1); //窗口號(hào),窗口數(shù)值 播放緩存
- }
- break;
- case 2:
- NO2_number=receive[2]; //窗口二號(hào)碼
- if(receive[2]!=0)
- {
- GotoXY(6,1);
- dis_3byte(NO2_number);
- NO2_sta=1; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- //語(yǔ)音數(shù)據(jù)轉(zhuǎn)換
- sound_dat_cov(2,NO2_number,sound_buf2); //窗口號(hào),窗口數(shù)值 播放緩存
- }
- break;
- case 3:
- NO3_number=receive[2]; //窗口三號(hào)碼
- if(receive[2]!=0)
- {
- GotoXY(12,1);
- dis_3byte(NO3_number);
- NO3_sta=1; //一號(hào)窗狀態(tài) 0暫停呼叫,1開始呼叫
- //語(yǔ)音數(shù)據(jù)轉(zhuǎn)換
- sound_dat_cov(3,NO3_number,sound_buf3); //窗口號(hào),窗口數(shù)值 播放緩存
- }
- break;
- }
- uart_R_flag=0; //串口數(shù)據(jù)接收完畢標(biāo)志
- }
- if(uart_T_flag==1) //串口數(shù)據(jù)發(fā)送標(biāo)志
- {
- send_buf[0]=0xa5; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 指令(0x01取號(hào)) 0x5a(結(jié)束位)
- send_buf[2]=0x01; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 指令(0x01取號(hào)) 0x5a(結(jié)束位)
- send_buf[3]=0x5a;
- send_uart_dat(send_buf[0]); //發(fā)送數(shù)據(jù)
- send_uart_dat(send_buf[1]); //發(fā)送數(shù)據(jù)
- send_uart_dat(send_buf[2]); //發(fā)送數(shù)據(jù)
- send_uart_dat(send_buf[3]); //發(fā)送數(shù)據(jù)
- uart_T_flag=0; //串口數(shù)據(jù)發(fā)送標(biāo)志
- }
- //語(yǔ)音播報(bào)
- play_data(); //語(yǔ)音播報(bào)數(shù)據(jù)
- }
- }
- /*************************************************************************
- *工程名稱: 排隊(duì)叫號(hào)系統(tǒng)----取號(hào)模塊程序 *
- *單片機(jī)型號(hào):STC89C52RC *
- *晶振頻率:11.0592MHz *
- *功能描述:按下取號(hào)鍵,開始取號(hào) *
- *作者:新興光電 *
- *日期:2016-03-01 *
- *************************************************************************/
- #include<reg51.h>
- #include <intrins.h>
- #include "LCD1602.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define FOSC 11059200L //系統(tǒng)晶振頻率
- #define BAUD 9600 //串口波特率
- #define SMOD 1 //為1,加倍波特率計(jì)算
- #if SMOD
- #define TC_VAL (256-FOSC/16/12/BAUD)
- //#else #define TC_VAL (256-FOSC/32/12/BAUD)
- #endif
- /**********端口定義********************************/
- sbit get_key=P2^0; //取號(hào)鍵
- sbit clear_key=P2^1; //清0鍵
- /**************************************************/
- /***********寄存器定義*****************************/
- uchar dis_buf[4];
- //以下為串口用到的寄存器
- bit uart_R_flag=0; //串口接收完畢標(biāo)志
- bit busy=0; //串口忙檢測(cè)
- uchar receive[4]; //數(shù)據(jù)接收格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 指令(0x01取號(hào)) 0x5a(結(jié)束位)
- uchar send_buf[4]; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 呼叫號(hào)碼(1~255) 0x5a(結(jié)束位)
- uchar rec_cnt=0;
- //呼叫取號(hào)相關(guān)寄存器
- uchar get_cnt=0; //取號(hào)計(jì)數(shù)
- uchar call_cnt=0; //呼叫計(jì)數(shù)
- /**************************************************/
- /***************延時(shí)程序***************************/
- void Delay1ms(uint t) //1ms延時(shí)程序
- {
- uchar j;
- while(t--)
- {
- for(j=0;j<125;j++)
- { ; }
- }
- }
- /**************************************************/
- /**********轉(zhuǎn)換顯示*********************************/
- void cov_dis(uchar dis_dat)
- {
- dis_buf[0]=dis_dat/100+0x30;
- dis_buf[1]=dis_dat%100/10+0x30;
- dis_buf[2]=dis_dat%100%10+0x30;
- dis_buf[3]='\0';
- }
- /***************************************************/
- /*************串口初始化程序***********************/
- void serial_init(void)
- {
- TMOD=0x21; //定時(shí)器1設(shè)為8位自動(dòng)重裝
- SCON=0x50; //8位數(shù)據(jù)串口,波特率可變 無(wú)校驗(yàn)位
- TH1=TC_VAL; //定時(shí)初始值
- TL1=TH1;
- PCON=0x80;
- ES = 1; //串口中斷充許
- EA = 1; //總中斷允許
- TR1=1;
- }
- /**************************************************/
- /***********串口中斷服務(wù)程序*********************/
- void serial() interrupt 4
- {
- if (RI)
- {
- RI = 0; //串口接收中斷完畢標(biāo)志清0
- //uart_buf=SBUF; //接收數(shù)據(jù)
- // call_cnt=SBUF; //接收數(shù)據(jù) 獲得叫號(hào)數(shù)
- receive[rec_cnt]=SBUF; //接收數(shù)據(jù)
- rec_cnt++;
- if(receive[0]==0xa5) //判斷起始位
- {
- if(receive[rec_cnt-1]==0x5a&&rec_cnt==4) //數(shù)據(jù)接收完畢
- {
- uart_R_flag=1; //串口接收完畢標(biāo)志
- send_buf[1]=receive[1]; //獲取機(jī)器號(hào)
- }
- }
- else rec_cnt=0;
- if(rec_cnt>=4)
- rec_cnt=0;
- }
- if (TI)
- {
- TI = 0; //串口發(fā)送中斷完畢標(biāo)志清0
- busy = 0; //串口忙標(biāo)志清0
- }
- }
- /***************************************************/
- /*************串口發(fā)送一字節(jié)數(shù)據(jù)程序****************/
- void send_uart_dat(uchar dat)
- {
- while (busy); //忙檢測(cè)標(biāo)志 等后上一字節(jié)數(shù)據(jù)發(fā)送完畢
- ACC = dat; //Calculate the even parity bit P (PSW.0)
- busy = 1;
- SBUF = ACC; //發(fā)送數(shù)據(jù)至串口發(fā)送緩沖寄存器
- }
- /***************************************************/
- /*************串口發(fā)送字符串?dāng)?shù)據(jù)程序****************
- void send_uart_stringdat(uchar *s)
- {
- while (*s) //檢查數(shù)據(jù)是否結(jié)束
- {
- send_uart_dat(*s++); //發(fā)送字符串
- }
- }
- /***************************************************/
- /********串口發(fā)送字符串?dāng)?shù)據(jù)程序*********************
- void send_uart_stringdat(uchar *send_dat)
- {
- do
- {
- send_uart_dat(*send_dat); //發(fā)送字符
- send_dat++;
- }while(*send_dat!='\0'); //檢查數(shù)據(jù)是否結(jié)束
- }
- /***************************************************/
- /**************主程序*******************************/
- void main(void)
- {
- serial_init(); //串口初始化程序
- LCD1602_init(); //LCD1602初始化程序
- GotoXY(0,0);
- Print(" number: "); //顯示英文”排號(hào)系統(tǒng)“
- GotoXY(0,1);
- Print(" Waiting: ");
- get_cnt=0; //號(hào)碼計(jì)數(shù)
- call_cnt=0; //排隊(duì)號(hào)
- while(1)
- {
- if(get_key==0) //取號(hào)鍵
- {
- Delay1ms(100);
- if(get_key==0)
- {
- if(get_cnt<255)
- {
- get_cnt++; //取號(hào)計(jì)數(shù)
- }
- else
- {
- get_cnt=255;
- }
- }
- }
- if(clear_key==0) //清0鍵
- {
- Delay1ms(100);
- if(clear_key==0)
- {
- get_cnt=0;
- call_cnt=0;
- while(!clear_key); //等待按鍵釋放
- }
- }
- if(uart_R_flag==1) //串口接收完畢標(biāo)志
- {
- if(receive[2]==0x01) //取號(hào)指令
- {
- send_buf[0]=0xa5; //發(fā)送緩存 格式 0xa5(起始位) 機(jī)器號(hào)(1~3) 呼叫號(hào)碼(1~255) 0x5a(結(jié)束位)
- send_buf[3]=0x5a;
- call_cnt++;
- if(get_cnt!=0)
- {
- if(call_cnt<=get_cnt)
- send_buf[2]=call_cnt; //排隊(duì)號(hào) 有人等候
- else
- {
- call_cnt=call_cnt-1;
- send_buf[2]=0; //排隊(duì)號(hào) 無(wú)人等候,
- }
- }
- else
- {
- send_buf[2]=0;
- call_cnt=0;
- }
- send_uart_dat(send_buf[0]); //發(fā)送數(shù)據(jù)
- send_uart_dat(send_buf[1]); //發(fā)送數(shù)據(jù)
- send_uart_dat(send_buf[2]); //發(fā)送數(shù)據(jù)
- send_uart_dat(send_buf[3]); //發(fā)送數(shù)據(jù)
- }
- uart_R_flag=0;
- }
- cov_dis(get_cnt);
- LCD1602_Print(10,0,dis_buf); //顯示取號(hào)數(shù)
- if(get_cnt!=call_cnt)
- {
- cov_dis(get_cnt-call_cnt);
- LCD1602_Print(11,1,dis_buf); //顯示等候人數(shù)
- }
- else LCD1602_Print(11,1,"000"); //顯示等候人數(shù)
-
-
- }
- }
- /***************************************************/
復(fù)制代碼
|
-
-
源程序.rar
2018-6-29 13:30 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
427.69 KB, 下載次數(shù): 115, 下載積分: 黑幣 -5
評(píng)分
-
查看全部評(píng)分
|