基于51单片机的公交车报站系统程序Word文档格式.docx
- 文档编号:4167745
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:36
- 大小:21.06KB
基于51单片机的公交车报站系统程序Word文档格式.docx
《基于51单片机的公交车报站系统程序Word文档格式.docx》由会员分享,可在线阅读,更多相关《基于51单片机的公交车报站系统程序Word文档格式.docx(36页珍藏版)》请在冰点文库上搜索。
//上一次显示指针偏移量
unsignedcharzm_last=0;
unsignedchark=0;
unsignedchar*q2;
unsignedintsecret=0;
//录音密码
unsignedintymcode=255;
//红外线编码
bitflag0=1;
//译码标志位
bits;
bithw=0;
//解码成功失败标志位
bitmode=0;
//模式选择,0:
报站模式,1录音模式(录音需要输入密码)。
bitxs=0;
//显示输入密码标志位
bitly=0;
//录音允许位
sbitP1_0=P3^7;
//红外线信号输入断口
sbitPLAY=P3^3;
//放音
sbitREC=P3^2;
//录音
sbitLCD_RS=P3^4;
//数据、命令选择信号
sbitLCD_WR=P3^5;
//读写信号
sbitLCD_E=P3^6;
//使能信号
unsignedinttm=0;
unsignedcharcodegImage_word0[1024];
unsignedcharcodegImage_word2[1024];
unsignedcharcodetable0[]={"
虎泉桌刀泉广阜屯街道口洪山丁字桥傅家坡大东门阅马场下一站:
"
};
unsignedcharcodetable1[]={"
深圳市勤正达电子有限公司成立于2002年,是专业研发及生产液晶显示器"
"
和液晶模块的高新技术企业。
LCD显示器覆盖了多种系列多年来公司秉承"
全力面向客户,技术专攻的经营理念,一直致力于为广大电子成品制造商"
提供质量精良,性能稳定,品种齐全的LCD显示屏及LCM显示模块系列产"
品。
望成为您的首选合作伙伴。
"
unsignedcharcodetable2[]={"
请输入密码:
录音模式"
密码错误!
voidmain()
{
unsignedcharnum=0;
unsignedinti=0;
unsignedchar*q;
TMOD=0x11;
TH1=0xF0;
TL1=0x60;
EA=1;
ET1=1;
REC=1;
PLAY=1;
Delay(100);
Lcd_system();
//系统初始化
q=gImage_word2;
Disp_pucture(q);
delay0(30000);
q=gImage_word0;
delay0(40000);
Clear();
while
(1)
{
q=table1;
for(num=0;
num<
5;
num++)
{
if(0==mode)
{
Disp_word0(0,q,32);
q=q+64;
}
for(i=0;
i<
60000;
i++)
bus_contorl();
}
}
}
/***************************************
*名称:
Clear()
*说明:
*功能:
清除全屏显示
*参数:
无
*返回值:
****************************************/
voidClear()
Write_com(0x01);
Write_com(0x34);
Write_com(0x30);
Lcd_system()
系统初始化
voidLcd_system(void)
Delay(600);
LCD_E=0;
Delay(10000);
Write_com(0x06);
Write_com(0x0c);
Delay(unsignedintt)
延时
t:
延时长度
voidDelay(unsignedintt)
unsignedinti;
for(i=0;
t;
{;
;
Write_com(unsignedchard)
写命令字
d:
命令代码
voidWrite_com(unsignedchard)
LCD_RS=0;
LCD_WR=0;
P1=d;
LCD_E=1;
Delay(40);
LCD_WR=1;
Write_data(unsignedchard)
写数据
d:
需要写入的数据
voidWrite_data(unsignedchard)
LCD_RS=1;
unsignedcharRead_data(void)
读数据
读出数据
unsignedcharRead_data(void)
unsignedchard=0;
Delay(50);
d=P1;
return(d);
Disp_word0(unsignedcharposx,unsignedchar*p,unsignedcharn)
显示一串汉字
pos:
显示位置(第一行:
0-6,第二行:
7-13),
p:
汉字码的地址指针,
n:
显示字的个数,
voidDisp_word0(unsignedcharposx,unsignedchar*p,unsignedcharn)
unsignedchari=0;
unsignedcharpos;
n;
pos=posx;
if((pos<
8)||((pos>
15)&
&
(pos<
24)))
if(pos>
15)pos=pos-8;
Write_com(0x80|pos);
Write_data(p[0]);
Write_data(p[1]);
else
if(pos<
16)
pos=pos-8;
else
pos=pos-16;
}
Write_com(0x90|pos);
posx++;
p=p+2;
Disp_row(unsignedcharrow,unsignedcharpos,unsignedchardat)
显示一个字母或数字
row:
行选择,pos:
显示位置(0-15),dat:
数字码
voidDisp_row(unsignedcharrow,unsignedcharpos,unsignedchardat)
unsignedchardat0;
unsignedcharpos0;
row=row%2;
row=row<
<
4;
pos0=pos/2;
if((pos+1)/2==pos0)
Write_com((0x80+row)|pos0);
Write_data(dat);
else
dat0=Read_data();
Disp_char(unsignedcharpos,unsignedchardat)
0-15,第二行:
16-31,第一行:
32-47,第二行:
48-63),dat:
voidDisp_char(unsignedcharpos,unsignedchardat)
if(pos<
Disp_row(0,pos,dat);
if((pos<
32)&
(pos>
15))
Disp_row(1,pos-16,dat);
48)&
31))
Disp_row(2,pos-16,dat);
64)&
47))
Disp_row(3,pos-32,dat);
voidDisp_number(unsignedcharpos,unsignedlongdat)
显示一个数(0-65536)
显示位置,dat:
显示数据
voidDisp_number(unsignedcharpos,unsignedintdat)
unsignedintd;
unsignedcharaddr;
unsignedchartab[5]={0};
//
d=dat;
while(d)
tab[i]=d%10;
d=d/10;
i++;
if(i<
p_last)
for(addr=0;
addr<
p_last-i;
addr++)
Disp_char(addr+pos+i,0x20);
i;
Disp_char(addr+pos,tab[i-addr-1]+48);
Disp_char(addr+pos,tab[i-addr-1]+48);
if(0==i)Disp_char(pos,48);
p_last=i;
/**********************
*
delay0()
晶振采用24.0MHz
*延时(t*0.1)ms
*输入:
t(时间参数)
***********************/
voiddelay0(unsignedintt)
tm=t;
do
TH0=0xFF;
TL0=0x38;
TR0=1;
while(!
TF0);
TF0=0;
TR0=0;
}while(--tm);
time1()
监视红外线信号是否结束
*如果2ms内输入信号没有沿跳变,就结束译码
flag0
voidtime1()interrupt3using2
flag0=0;
bithw_yima()
红外线译码
ym:
解码成功
(1),失败(0)。
bithw_yima()
unsignedintymdata=0;
unsignedcharn=0;
bitym=0;
ymcode=0xffff;
s=P1_0;
if(0==P1_0)
while(flag0)
while(P1_0==s);
if(1==flag0)
TR1=0;
TH1=0xF0;
TL1=0x60;
TR1=1;
delay0(12);
ymdata=ymdata<
1;
if(0==P1_0)
{
ymdata|=0x01;
}
n++;
s=P1_0;
if(n>
9)//此参数直接影响接受的灵敏度
ymcode=ymdata>
>
ymcode=~ymcode;
ym=1;
//解码成功
delay0(400);
//减少连码
ym=0;
//解码失败
ym=0;
//解码失败
flag0=1;
return(ym);
voidReport(unsignedcharsl)
根据参数报公车站名
sl:
车站序号
voidReport(unsignedcharsl)
unsignedchar*q0;
switch(sl)
case0:
P0=0x00;
PLAY=0;
break;
case1:
P0=0x28;
case2:
P0=0x30;
case3:
P0=0x38;
case4:
P0=0x40;
case5:
P0=0x48;
case6:
P0=0x50;
case7:
P0=0x58;
case8:
P0=0x78;
default:
break;
PLAY=1;
if(sl<
9)
Clear();
q0=table0+6*sl;
Disp_word0(9,q0,3);
if(sl==8)
P0=0x60;
delay0(10000);
PLAY=0;
delay0(1000);
PLAY=1;
P0=0x68;
delay0(10000);
PLAY=0;
delay0(1000);
PLAY=1;
P0=0x80;
delay0(40000);
if(sl<
8)
q0=table0+54;
Disp_word0(9,q0,4);
q0=table0+6*sl+6;
Disp_word0(13,q0,3);
P0=0x70;
P0=0x28+sl*8;
voidRec_bus(unsignedcharrec)
录入公车站名
rec:
录音键的键值
voidRec_bus(unsignedcharrec)
unsignedcharsi=0;
unsignedcharsi_last=0;
si=rec;
if(si!
=si_last)
P0=0x00;
if(si==56)
P0=0x00;
REC=0;
delay0(48000);
//欢迎您乘坐803路公交车,这里是起点站虎泉
REC=1;
P0=0x28;
delay0(8500);
//卓刀泉
P0=0x30;
//广阜屯
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 51 单片机 公交车 报站 系统 程序