概述: 智能红外语音警示柱采用C8051单片机作为处理单元,集成了 MP3、WAV 的硬解码数字语音功放,配合广角度红外传感器,驱动红绿数码管作为爆闪提醒。能联动信号控制系统,实现一种与交通行人信号红绿灯配套使用的声响提示装置,使行人横穿马路时更加注意安全,本产品红外检测灵敏,声音指向性明确,外型美观大方,安装简单。
特点: 1、采用高增益大功率的音频放大; 2、采用红外数字脉冲探测,感应速度为50-700ms,警戒距离达30米,两光束水平光轴范围180度,上下光轴范围20度。 3、采用不锈钢材料通过特殊工艺处理,具有耐腐蚀、防水和防撞等功能; 4、同步红绿灯信号显示,强化行人过街视觉与听觉双重辅助提醒; 5、语音简洁、动听,且音量大小可调,夜间不会产生噪声; 6、外形设计精致、时尚、美观,提升城市交通品质与档次。
制作出来的实物图如下:
单片机源程序如下:
- #include "include.h"
- #include "sw_uart.h"
- #include "hw_uart.h"
- #include "timer2.h"
- #include "api.h"
- pt pt_comm;
- void init_gpio()
- {
- // P0.0 - Skipped, Open-Drain, Digital
- // P0.1 - Skipped, Open-Drain, Digital
- // P0.2 - Skipped, Open-Drain, Digital
- // P0.3 - Skipped, Open-Drain, Digital
- // P0.4 - TX0 (UART0), Push-Pull, Digital
- // P0.5 - RX0 (UART0), Open-Drain, Digital
- // P0.6 - Skipped, Open-Drain, Digital
- // P0.7 - Skipped, Open-Drain, Digital
- // P1.0 - Skipped, Open-Drain, Digital
- // P1.1 - CEX0 (PCA), Open-Drain, Digital
- // P1.2 - Unassigned, Open-Drain, Digital
- // P1.3 - Unassigned, Open-Drain, Digital
- // P1.4 - Unassigned, Open-Drain, Digital
- // P1.5 - Unassigned, Open-Drain, Digital
- // P1.6 - Unassigned, Push-Pull, Digital
- // P1.7 - Unassigned, Push-Pull, Digital
- // P2.0 - Unassigned, Open-Drain, Digital
- // P2.1 - Unassigned, Open-Drain, Digital
- // P2.2 - Unassigned, Open-Drain, Digital
- // P2.3 - Unassigned, Open-Drain, Digital
- P0MDOUT = 0x10;
- P1MDOUT = 0xC0;
- P0SKIP = 0xCF;
- P1SKIP = 0x01;
- XBR0 = 0x01;
- XBR1 = 0x41;
- }
- void init_sysclock()
- {
- OSCICN = 0x83;
- }
- void init_wtd(void)
- {
- // PCA0MD &= ~0x40; // 向WDTE写‘0’,禁止WDT
- // PCA0MD = 0x00; // PCA时钟源选择系统时钟的12分频
- // PCA0CPL2 = 0xFF; // 装入WDT更新偏移值为64.2ms
- // PCA0MD |= 0x40; // 向WDTE写‘1’,使能WDT
- // Calculate Watchdog Timer Timeout
- // Offset calculated in PCA clocks
- // Offset = ( 256 x PCA0CPL4 ) + 256 - PCA0L
- // = ( 256 x 255(0xFF)) + 256 - 0
- // Time = Offset * (12/SYSCLK)
- // = 255 ms ( PCA uses SYSCLK/12 as its clock source)
- PCA0MD &= 0xBF; // WDTE = 0 (clear watchdog timer enable)
- // PCA0L = 0x00; // Set lower byte of PCA counter to 0
- // PCA0H = 0x00; // Set higher byte of PCA counter to 0
- PCA0CPL4 = 0xFF; // Write offset for the WDT
- PCA0MD |= 0x40; // Enable the WDT
- }
- void feed_wtd(void)
- {
- //CCF2 = 0x00; // Write a 'dummy' value to the PCA0CPH4
- // register to reset the watchdog timer
- // timeout. If a delay longer than the
- // watchdog timer delay occurs between
- // successive writes to this register,
- // the device will be reset by the watch
- // dog timer.
- PCA0CPH4 =0x00;
- }
- unsigned char get_lamp_status(void)
- {
- if(PIN_RED_LAMP==0) return 1;
- else return 0;
- }
- u8 xdata gRxdBuffer[MAX_HDLC_BUF+2]={0};
- u8 xdata gTxdBuffer[MAX_HDLC_BUF+2]={0};
- u8 xdata cmd_buffer[MAX_HDLC_BUF]={0};
- u8 xdata ack_buffer[MAX_HDLC_BUF]={0};
- u8 xdata com_status=RE_SYNC;
- u16 xdata framesize=0;
- //查询红灯状态: 7E FF A0 C0 9F 7E
- //播放第1首01音量: 7E FF A0 C1 01 01 9E 7E
- //播放第1首30音量: 7E FF A0 C1 1E 01 81 7E
- //播放第2首30音量: 7E FF A0 C1 1E 02 82 7E
- //播放第3首30音量: 7E FF A0 C1 1E 03 83 7E
- void delay(unsigned short dly)
- {
- timer timer_delay;
- timer_set(&timer_delay,dly);
- for(;;)
- {
- feed_wtd();
- if(timer_expired(&timer_delay))
- {
- break;
- }
- }
- }
- unsigned short thread_comm(pt *pt)
- {
- u8 ch=0;
- u8 vol=0;
- u8 index=0;
- static u8 red_lamp_status=0;
- static u8 radar_status=0;
- static u8 run=0;
- run=PIN_COM=0;
- PT_BEGIN(pt);
- for(;;)
- {
- PT_YIELD(pt);
- if(PIN_RED_LAMP!=red_lamp_status || PIN_RADAR!=radar_status)
- {
- radar_status = PIN_RADAR;
- red_lamp_status = PIN_RED_LAMP;
-
- //设置音量
- cmd_buffer[0]=0x7E;
- cmd_buffer[1]=0x03;
- cmd_buffer[2]=0x31;
- cmd_buffer[3]=30; //音量
- cmd_buffer[4]=0xEF;
- sw_uart_send_bytes(cmd_buffer,5);
-
- if(red_lamp_status==0) //检查 led signal
- {
- if(radar_status!=0) //检查radar
- {
-
- index=0x03; //闯红灯
-
- }
- else
- {
- delay(500); //延时500毫秒
- index=0x01; //红灯
- delay(4000);
- }
- }
- else
- {
- delay(2500);
- index = 0x02 ; //绿灯
-
- }
- //组织语音播放数据
- cmd_buffer[0]=0x7E;
- cmd_buffer[1]=0x04;
- cmd_buffer[2]=0x41;
- cmd_buffer[3]=0x00;
- cmd_buffer[4]=index; //编号
- cmd_buffer[5]=0xEF;
- sw_uart_send_bytes(cmd_buffer,6);
- }
- }
- PT_END(pt);
- }
- void main(void)
- {
- init_sysclock();
- init_gpio();
- init_timer0();
- init_hw_uart();
- init_sw_uart();
- init_wtd();
-
- PT_INIT(&pt_comm);
- EA=1;
- for(;;)
- {
- thread_comm(&pt_comm);
- feed_wtd();
- }
- }
复制代码
所有程序51hei提供下载:
红外语音系统程序源码.zip
(106.79 KB, 下载次数: 30)
|