|
随着智慧公交的到来,智能报站器开始遍布到每一辆公交车上。本设计是基于51的低成本多功能自动定位远程控制的报站器。
单片机源程序如下:
- #include "reg52.h"
- #include "flash.h"
- #include "sta013.h"
- #include "ds1302.h"
- #include "watchdog.h"
- #include "global.h"
- #include "communication.h"
- #include "voicefunction.h"
- #include "operate.h"
- #include "keydisp.h"
- #include "define.h"
- #include "turnbrakecheck.h"
- unsigned char xdata rs232_or_rs485 = 0; //2016-05-17 10:28:02
- extern void SendGuidepostInit(void); //2015-12-21 CJJ
- void main(void)
- {
- //2015-12-22 CJJ
- unsigned char xdata line_name_tmp[4] , i, j, k;
- unsigned long xdata flashadd_tmp;
- sys_init(); //系统初始化
- DS_RAM_RD(RS232_OR_RS485, &rs232_or_rs485);//获取后串口定义为232还是485
- if (rs232_or_rs485) //使能后485
- {
- RS485EN = 1;
- RS232EN = 0;
- }
- else //使能后232
- {
- RS485EN = 0;
- RS232EN = 1;
- }
- while(1)
- {
- FeedWatchDog();
- TurnVoicePrompt(); //2017.02.26 汤 博
- if(keynumber!=0xffff)
- {
- ClrTimmer(); //清除定时器数据2003.05.20
- switch(keynumber)
- {
- case KEY00:
- CloseTimmer(); //close timmer when playying2003.05.20
- PlayServeVoice(0);
- break;
- case KEY01:
- CloseTimmer(); //close timmer when playying2003.05.20
- PlayServeVoice(1);
- break;
- case KEY02:
- CloseTimmer(); //close timmer when playying2003.05.20
- if(S_Xuan6_8==0)
- PlayServeVoice(2);
- else
- PlayServeVoice(5);
- break;
- case KEY03:
- CloseTimmer(); //close timmer when playying2003.05.20
- if(S_Xuan6_8==0)
- PlayServeVoice(3);
- else
- PlayServeVoice(6);
- break;
- case KEY04:
- CloseTimmer(); //close timmer when playying2003.05.20
- if(S_Xuan6_8==0)
- PlayServeVoice(4);
- else
- PlayServeVoice(7);
- break;
- case KEY06:
- if(S_Xuan6_8==0)
- {
- S_Xuan6_8=1;
- //显示"扩展"
- Disp_Symbol(FLAG_EXTEND,ON,OFF);
- }
- else
- {
- S_Xuan6_8=0;
- //"扩展"消失
- Disp_Symbol(FLAG_EXTEND,OFF,OFF);
- }
- break;
- case KEY05:
- CloseTimmer(); //close timmer when playying2003.05.20
- PlayBaoZhan(PLAY_REPEAT);
- break;
- case KEY09:
- ChangBusStop(1); //=1增站
- CloseTimmer(); //close timmer when playying2003.05.20
- break;
- case KEY0A:
- ChangBusStop(0); //=1增站
- CloseTimmer(); //close timmer when playying2003.05.20
- break;
- case KEY07: //报进站 2017.02.22
- CloseTimmer(); //close timmer when playying2003.05.20
- // 2006.11.25add
- if(GB_StudyAuto)
- GB_IsPressKeyPlay = 1;
- PlayIn_Flag = 1; //2017.02.26 汤博
- PlayBaoZhan(PLAY_IN);
- break;
- case KEY08: //报出站 2017.02.22
- CloseTimmer(); //close timmer when playying2003.05.20
- // 2006.11.25add
- if(GB_StudyAuto)
- GB_IsPressKeyPlay = 1;
- PlayBaoZhan(PLAY_OUT);
- break;
- case KEY10:
- //StartTimmer();
- CloseTimmer();
- if(ChangeState(SPK_BIT_IN_CFG)) //改变外喇叭状态
- Disp_Symbol(FLAG_SPEAKER_F,ON,OFF); //显示改变
- else
- Disp_Symbol(FLAG_SPEAKER_F,OFF,OFF);
- SltSpkOFF(); //2012.4.14
- break;
- case KEY11:
- //StartTimmer();
- CloseTimmer();
- if(ChangeState(AUTO_BIT_IN_CFG)) //改变自动报站状态
- Disp_Symbol(FLAG_AUTO_F,ON,OFF); //显示改变
- else
- Disp_Symbol(FLAG_AUTO_F,OFF,OFF);
- break;
- case KEY12:
- //StartTimmer();
- CloseTimmer();
- if(ChangeState(TMV_BIT_IN_CFG)) //改变时段音量状态
- Disp_Symbol(FLAG_TIME_F,ON,OFF); //显示改变
- else
- Disp_Symbol(FLAG_TIME_F,OFF,OFF);
- break;
- case KEY13:
- //StartTimmer();
- CloseTimmer();
- ChangeDirection();
- break;
- case KEY14:
- //StartTimmer();
- CloseTimmer();
- if(ChangeState(MUSIC_BIT_IN_CFG)) //改变背景音乐状态
- Disp_Symbol(FLAG_MUSIC,ON,OFF); //显示改变
- else
- Disp_Symbol(FLAG_MUSIC,OFF,OFF);
- break;
- case KEY16:
- //StartTimmer();
- CloseTimmer();
- if(ChangeState(OV_BIT_IN_CFG)) //改变区间状态
- Disp_Symbol(FLAG_OVER_F,ON,OFF); //显示改变
- else
- Disp_Symbol(FLAG_OVER_F,OFF,OFF);
- break;
- case KEY15:
- //显示"线路"并闪烁
- StartTimmer(); //启动定时2003.05.20
- SetMenu(); //菜单设置2017.02.22
- break;
- case KEY_UP_L: //↑ 长按
- CloseTimmer();
- Disp_Clear();
- Disp_Num(0 , BLACK, OFF); //显示" 485"
- Disp_Num(1 , 5 , OFF);
- Disp_Num(2 , 8 , OFF);
- Disp_Num(3 , 4 , OFF);
- rs232_or_rs485 = 1;
- DS_RAM_WR(RS232_OR_RS485, rs232_or_rs485);
- RS485EN = 1;
- RS232EN = 0; //后485
- Delay_350ms(6);
- revertdisp(); //恢复默认显示!!!!!
- break;
- case KEY_DOWN_L://↓ 长按
- CloseTimmer();
- Disp_Clear();
- Disp_Num(0 , BLACK , OFF); //显示" 232"
- Disp_Num(1 , 2 , OFF);
- Disp_Num(2 , 3 , OFF);
- Disp_Num(3 , 2 , OFF);
- rs232_or_rs485 = 0;
- DS_RAM_WR(RS232_OR_RS485, rs232_or_rs485);
- RS485EN = 0;
- RS232EN = 1; //后232
- Delay_350ms(6);
- revertdisp(); //恢复默认显示!!!!!
- break;
- default:
- break;
- }
- keynumber=0xffff;
- }//end if(keynumber!=0xffff)
- if(RevertDisp_Flag==1) //恢复初始显示2017.02.22
- {
- RevertDisp_Flag=0;
- revertdisp();
- }
-
- if(GB_Config & AUTO_BIT_IN_CFG) //如果启动自动报站则进入自动报站处理程序
- {
- // 下面代码2007.7.6add 2007.7.13 move here 防止影响其他的闪烁显示
- if(GpsDataReceive_Flag) //如果接收到完整的GPS数据包 2017.02.24 汤博 注
- {
- if(GB_IsInceptGPSdata) //如果接收到GPS数据包 2017.02.24 汤博 注
- {
- GB_IsInceptGPSdata = 0; //接收到GPS数据包标志置零
- Disp_Symbol(FLAG_AUTO_F , ON , OFF); //显示改变
- }
- else
- {
- GB_IsInceptGPSdata = 1;
- Disp_Symbol(FLAG_AUTO_F , OFF , OFF);
- }
- }
- AutoPlayBaoZhan();
- }
-
-
- #if TURN_BRAKE_CHECK_EN > 0
- turn_brake_check();
- #endif
- //以下为线路变更处理--------------------------------------------------------------------------------------
- EA = 0;//关总中断避免干扰
- if (0 != (road_line[0] || road_line[1] || road_line[2] || road_line[3]))//若非全0则表明成功收到线路变更命令
- {
- // SerialSendByte('Y');//_DBG_
- //获取线路总条数
- flashadd_tmp = 11;//LINE_NUM_OFSET_OF_FILE_HEADER;//线路总数目偏移地址
- FlashRandomRead(flashadd_tmp , &j , 1);
- // SerialSendByte(j);//_DBG_
- //将'1''9''2'逐个搜索比较"线路名称",再转换为线路编号(从1开始编号的)作为SetCurrentLine的参数
- for (i = 0; i < j; i++)
- {
- flashadd_tmp = 12/*LINE_OFSET_OF_FILE_HEADER*/ + i * sizeof(unsigned long);
- FlashRandomRead(flashadd_tmp , (unsigned char *)(&flashadd_tmp) , sizeof(unsigned long));//编号i的线路的属性偏移地址
- FlashRandomRead(flashadd_tmp , line_name_tmp , sizeof(line_name_tmp));//语音文件支持8Byte,实际使用4Byte
- for (k = 0; k < 4; k++)//逐字比较
- {
- if (road_line[k] != line_name_tmp[k])//不匹配//192存储为[0X31 0X39 0X32 0X00]
- {
- break;//失败,搜索下条线路
- }
- }
- // SerialSendByte(line_name_tmp[0]);//_DBG_
- // SerialSendByte(line_name_tmp[1]);//_DBG_
- // SerialSendByte(line_name_tmp[2]);//_DBG_
- // SerialSendByte(line_name_tmp[3]);//_DBG_
- if (4 == k)//匹配成功
- {
- SetCurrentLine(i);//设置当前线路 2015-12-22 CJJ
- ES = 0;
- SendGuidepostInit();//向站牌发送线路切换信息 2015-12-22 CJJ
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
|
|