打印
[文档下载]

单片机模拟公交车门控实验

[复制链接]
1136|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Rooney30|  楼主 | 2016-3-27 20:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
模拟公交车门控制的,当时做这个作品的时候是去坐公交的时候,看见有人要下车按了按键没有反应,然后大声地在车厢上喊司机下车,司机顾着开车也没有怎么回答,自己感觉如果公交车上有一个液晶屏可以提示多好呀,回来后在没事之余就做了这套东西出来
具体的功能是达到乘客与司机通过按键沟通,控制乘客上下车的功能。也没有什么难的,这里面用到的单片机与单片机的通信,以及液晶显示,基本上就这样。
#include <reg52.h>
#include "lcd12864.h"
#include "delay.h"
unsigned char utrFlag=0,Flag=0,count;
sbit Buzzer = P3^4;
sbit key = P3^3;
uchar keyflag;
unsigned char SerFlag[1];
void init(void)
{
init_12864HZ();
display_HZ();
EA = 1;
ES = 1;
REN = 1;
SM1 = 1;
SM0 = 0;
TMOD = 0x20;
TH1 = 0xfd;
TL1 = 0xfd;
TR1 = 1;
}
void main()
{
char i;
init();
while(1)
{     
  if(Flag == 1)
  {
   Flag = 0;
   ES = 0;
   SBUF = 0x01;
   while(!TI);
   TI = 0;   
   ES = 1;
   for(i=0;i<3;i++)
   {
   Buzzer = 0;
   delay_50ms(500);
   Buzzer = 1;
   delay_50ms(500);
   }
   write_12864com(0x01);
   display_HZ1();
  }
  
  if(key==0)
  {
   delay_50ms(1);
   while(key == 0)
   {
    while(!key);
    ES = 0;   //关闭串口通信中断程序
    utrFlag++; //判断司机按键情况。
    if(utrFlag==1)
    {
     init_12864HZ();
    // write_12864com(0x01);
     display_HZ2();
     delay_50us(10);
      SBUF = 0x02;
     while(!TI);
     TI = 0;
    }
    if(utrFlag==2)
    {
     utrFlag = 0;
     display_HZ();
     delay_50ms(1);
     SBUF = 0x03;
     while(!TI);
     TI = 0;
     ES = 1;
    }
   }
  }
}
}


沙发
Rooney30|  楼主 | 2016-3-27 20:44 | 只看该作者
void UTR() interrupt 4
{
RI = 0;
SerFlag[0]=SBUF;
if(SerFlag[0]==0x01)
{
  Flag++;
}
}

lcd.h文件
#ifndef _LCD12864_H_
#define _LCD12864_H_
#define uint unsigned int
#define uchar unsigned char
sbit rs = P2^0;
sbit rw = P2^1;
sbit e = P2^2;
sbit psb = P2^3;
sbit res = P2^5;
void write_12864com(uchar com);//写命令到lcd12864
void write_12864dat(uchar dat);//写数据到lcd12864
void init_12864HZ(void);//液晶显示汉字初始化
void init_12864PIC(void);//液晶显示汉字初始化
void display_HZ(void);
void display_HZ1(void);
void display_HZ2(void);
void display_FH(void);
void display_PIC(void);
#endif
lcd.c文件
#include <reg52.h>
#include "delay.h"
#include "lcd12864.h"
uchar code pic2[]={
"  车门已经关闭  "//
"  请注意车速    "//
"  请勿疲劳驾驶  "
"  祝您工作顺利  "//
};
uchar code pic4[] = {
"  您好!有乘客需"
"开车门,谢谢!当"
"要下车,到站时请"
"前您还未开门!  "
};
uchar code pic5[] = {
"  您好!车门已经"
"安全下车,当前车"
"打开,请等候乘客"
"门处理打开状态!"
};
unsigned char code pic3[]=
{
0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,
0x00,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x00,0x03,0x00,0x07,0xEC,0xC0,0x00,0x00,
0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x37,0x80,0x03,0x00,
0x00,0xEC,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,
0x18,0x3F,0xC0,0x03,0x00,0x0F,0x6E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x00,0x18,0x79,0x80,0x03,0x00,0x0F,
0x6B,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x18,
0x7F,0x00,0x1F,0xF4,0x01,0xE9,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xE0,0x18,0xFF,0x80,0x1F,0xFC,0x00,0xFB,
0x30,0x00,0x00,0x00,0x00,0x00,0x01,0xC6,0x70,0x1B,0x1E,
0xC0,0x03,0x38,0x01,0xB3,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x86,0x38,0xDB,0xFF,0xE0,0x03,0x70,0x07,0x9E,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x26,0x18,0xDB,0x8C,0x70,
0x7F,0xFF,0x87,0x27,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
0x3E,0x01,0xFF,0xFF,0xB8,0x7F,0xFF,0x80,0x3F,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x0C,0x18,0x07,
0x80,0x00,0x39,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
0x00,0x00,0xFF,0xE0,0x0F,0x00,0x00,0xFB,0x1F,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0xF0,0xFF,0xE0,0x1F,0x30,
0x01,0xCF,0xFF,0xFF,0x09,0x00,0x00,0x00,0x00,0x03,0xFF,
0xFF,0x0C,0x00,0x3B,0x36,0x03,0x07,0xFF,0xFF,0xE0,0x00,
0x00,0x00,0x00,0x0F,0xFF,0xFF,0xCC,0x00,0x73,0x76,0x03,
0x3F,0xFF,0xFF,0xF7,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,
0xFC,0x00,0x63,0xE6,0x00,0x3F,0xFF,0xFF,0xDC,0x80,0x00,
0x00,0x00,0x7F,0xFF,0xFF,0xFC,0x00,0x03,0xFE,0x00,0x7F,
0xFF,0xFF,0xAF,0x60,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFC,
0x00,0x03,0xFE,0x00,0xFF,0xFF,0xFF,0xF5,0xC0,0x00,0x00,
0x01,0xFF,0xFF,0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F,
0xF0,0x00,0x00,0x00,0x00,0x3F,0xC0,0x3F,0xE0,0x00,0x00,
0x00,0x00,0x7F,0x00,0x3F,0xF0,0x00,0x00,0x00,0x00,0x3F,
0xC0,0x7F,0xE0,0x00,0x00,0x00,0x00,0x7F,0x00,0x3F,0xE0,
0x00,0x00,0x00,0x00,0x1F,0xE0,0x7F,0xC0,0x00,0x00,0x00,
0x00,0x3F,0x00,0x3F,0xE0,0x00,0x00,0x00,0x00,0x1F,0xE0,
0x7F,0xC0,0x00,0x00,0x00,0x00,0x3F,0x00,0x7F,0xE0,0x01,
0xC0,0xE0,0x00,0x1F,0xE0,0xFF,0xC0,0x00,0x70,0xE0,0x00,
0x3F,0x00,0x7F,0xE0,0x03,0xF3,0xF0,0x00,0x1F,0xE0,0xFF,
0xC0,0x00,0xF9,0xF0,0x00,0x3F,0x00,0x7F,0xE0,0x07,0xFF,
0xF8,0x00,0x1F,0xE0,0xFF,0xC0,0x01,0xFF,0xF8,0x00,0x3F,
0x00,0x7F,0xE0,0x07,0xFF,0xF8,0x00,0x1F,0xE0,0xFF,0xC0,
0x01,0xFF,0xF8,0x00,0x3F,0x00,0x7C,0xE0,0x07,0xFF,0xF8,
0x00,0x1B,0xE0,0xF9,0xC0,0x01,0xFF,0xF8,0x00,0x37,0x00,
0x38,0xF0,0x03,0xFF,0xF0,0x00,0x39,0xE0,0xF1,0xE0,0x00,
0xFF,0xF0,0x00,0x73,0x00,0x30,0x70,0x01,0xFF,0xE0,0x00,
0x30,0xC0,0x60,0xE0,0x00,0x7F,0xE0,0x00,0x61,0x00,0x00,
0x78,0x00,0xFF,0xC0,0x00,0x30,0x00,0x00,0xF0,0x00,0x3F,
0xC0,0x00,0x60,0x00,0x00,0x38,0x00,0x7F,0x80,0x00,0x60,
0x00,0x00,0x70,0x00,0x1F,0x80,0x00,0xC0,0x00,0x00,0x1C,
0x00,0x3F,0x00,0x00,0xC0,0x00,0x00,0x38,0x00,0x0F,0x00,
0x01,0x80,0x00,0x00,0x0E,0x00,0x1E,0x00,0x00,0x80,0x00,
0x00,0x1C,0x00,0x06,0x00,0x01,0x00,0x00,0x00,0x07,0x00,
0x0C,0x00,0x01,0x80,0x00,0x00,0x0E,0x00,0x06,0x00,0x03,
0x00 };
void write_12864com(uchar com)
{
rw = 0;
rs = 0;
delay_50us(1);
P0 = com;
e = 1;
delay_50us(10);
e = 0;
delay_50us(2);
}

使用特权

评论回复
板凳
Rooney30|  楼主 | 2016-3-27 20:45 | 只看该作者
void write_12864dat(uchar dat)
{
rw = 0;
rs = 1;
delay_50us(1);
P0 = dat;
e = 1;
delay_50us(10);
e = 0;
delay_50us(2);
}
void init_12864HZ(void)
{
delay_50ms(1);
psb = 1;
delay_50us(20);
res = 0;
delay_50us(20);
res = 1;
delay_50us(2);
write_12864com(0x30);
delay_50ms(2);
write_12864com(0x30);
delay_50us(1);
write_12864com(0x08);
delay_50us(2);
write_12864com(0x10);
delay_50us(2);
write_12864com(0x0c);
delay_50us(2);
write_12864com(0x01);
delay_50ms(1);
write_12864com(0x06);
delay_50us(4);
}
void init_12864PIC(void)
{
delay_50ms(1);
psb = 1;
delay_50us(10);
res = 0;
delay_50us(10);
res = 1;
delay_50us(20);
write_12864com(0x36); //Extended Function Set RE=1: extended instruction
delay_50ms(4);
write_12864com(0x36);
delay_50ms(2);
write_12864com(0x3e);//EXFUNCTION(DL=8BITS,RE=1,G=1)//设置为并口
delay_50ms(4);
write_12864com(0x01);//CLEAR SCREEN清屏
delay_50ms(4);
}
void display_HZ(void)
{
uchar i;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<64;i++)
{
  write_12864dat(pic2[i]);
  delay_50us(1);
}
}
void display_HZ1(void)
{
uchar i;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<64;i++)
{
  write_12864dat(pic4[i]);
  delay_50us(1);
}
}
void display_HZ2(void)
{
uchar i;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<64;i++)
{
  write_12864dat(pic5[i]);
  delay_50us(1);
}
}
void display_FH(void)
{
uchar i,a=0x10;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<16;i++)
{
     write_12864dat(a);
   delay_50us(1);
   a++;
}
}
void display_PIC(void)
{
int i,j;
uint a;
for(i=0;i<32;i++)
{
  write_12864com((0x80+i));
  write_12864com(0x80);
  for(j=0;j<16;j++)
   {
   write_12864dat(pic3[a]);
   a++;
   }
}
for(i=0;i<32;i++)
{
  write_12864com((0x80+i));
  write_12864com(0x88);
  for(j=0;j<16;j++)
   {
   write_12864dat(pic3[a]);
   a++;
   }
}
}

使用特权

评论回复
地板
Rooney30|  楼主 | 2016-3-27 20:46 | 只看该作者
delay.h文件
#ifndef _DELAY_H_
#define _DELAY_H_
#define uint unsigned int
#define uchar unsigned char
void delay_50us(uint t);
void delay_50ms(uint t);
void delays(uint j);
#endif
delay.c文件
#include "delay.h"
void delay_50us(uint t)
{
uchar j;
for(;t>0;t--);
for(j=19;j>0;j--);
}
void delay_50ms(uint t)
{
uint j;
for(;t>0;t--);
for(j=6245;j>0;j--);
}
void delays(uint j)
{
while(j--);
}
   


乘客接收部分的程序:
main.c文件
#include <reg52.h>
#include "lcd12864.h"
#include "initfile.h"
#include "delay.h"
uchar keyFlag,serBuff,SerFlag;
void main()
{
uchar i;
init_all();
while(1)
{
  if(key == 0)
  {
   delay_50us(1);
   if(key == 0)
   {
    while(!key);
    if(keyFlag == 0)   
    SBUF = 0x01;
    keyFlag ++;
    if(keyFlag>1)
    {
     display_HZ3();//有乘客已经按铃
     delay_50ms(1000);
     display_HZ1();
    }
   }
  }
  if((SerFlag == 2)||(SerFlag == 3))
  if(SerFlag == 1)
   {
    display_HZ1();//司机已经收到您的信息
    LEDY = 0;
    LEDG = 1;
   }
  if(SerFlag == 2)
   {
    display_HZ2();//司机已经收到您的信息
    LEDY = 1; //黄灯灭
    LEDG = 0; //绿灯亮
    Relay = 0;//打开车门
   }
  if(SerFlag == 3)
   {
    display_HZ();//
    keyFlag = 0;
    LEDY = 1;//关闭黄灯
    LEDG = 1;//关闭绿灯
    Relay = 1;//关闭车门
   // SerFlag = 0;
   }
}
}


使用特权

评论回复
5
Rooney30|  楼主 | 2016-3-27 20:47 | 只看该作者
void SER() interrupt 4
{
RI = 0;
serBuff = SBUF;
if(serBuff == 0x01)
{
  SerFlag = 1;
}
if(serBuff == 0x02)
{
  SerFlag = 2;
}
if(serBuff == 0x03)
{
    SerFlag = 3;
}
}
delay.c文件
#include "delay.h"
void delay_50us(uint t)
{
uchar j;
for(;t>0;t--);
for(j=19;j>0;j--);
}
void delay_50ms(uint t)
{
uint j;
for(;t>0;t--);
for(j=6245;j>0;j--);
}
void delays(uint j)
{
while(j--);
}
lcd.c文件
#include <reg52.h>
#include "delay.h"
#include "lcd12864.h"
uchar code pic2[]={
"欢迎乘坐本次列车"//
"请您在快到站时提"
"如果您需要下车,"//
"前按铃,谢谢!  "//
};
uchar code pic4[] = {
"司机已经收到您的"
"会在列车到站时为"
"下车信息,我们将"
"您打开车门!    "
};
uchar code pic5[] = {
"尊敬的乘客,您已"
"您的行里准备下车"
"经到站了,请带好"
"欢迎再次乘坐本车"
};
uchar code pic[] = {
"已经有乘客按铃了"
"请不要重复按铃  "
"请您耐心等候    "
"祝您乘车愉快    "
};
unsigned char code pic3[]=
{
0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,
0x00,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x00,0x03,0x00,0x07,0xEC,0xC0,0x00,0x00,
0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x37,0x80,0x03,0x00,
0x00,0xEC,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,
0x18,0x3F,0xC0,0x03,0x00,0x0F,0x6E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x00,0x18,0x79,0x80,0x03,0x00,0x0F,
0x6B,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x18,
0x7F,0x00,0x1F,0xF4,0x01,0xE9,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xE0,0x18,0xFF,0x80,0x1F,0xFC,0x00,0xFB,
0x30,0x00,0x00,0x00,0x00,0x00,0x01,0xC6,0x70,0x1B,0x1E,
0xC0,0x03,0x38,0x01,0xB3,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x86,0x38,0xDB,0xFF,0xE0,0x03,0x70,0x07,0x9E,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x26,0x18,0xDB,0x8C,0x70,
0x7F,0xFF,0x87,0x27,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
0x3E,0x01,0xFF,0xFF,0xB8,0x7F,0xFF,0x80,0x3F,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x0C,0x18,0x07,
0x80,0x00,0x39,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
0x00,0x00,0xFF,0xE0,0x0F,0x00,0x00,0xFB,0x1F,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0xF0,0xFF,0xE0,0x1F,0x30,
0x01,0xCF,0xFF,0xFF,0x09,0x00,0x00,0x00,0x00,0x03,0xFF,
0xFF,0x0C,0x00,0x3B,0x36,0x03,0x07,0xFF,0xFF,0xE0,0x00,
0x00,0x00,0x00,0x0F,0xFF,0xFF,0xCC,0x00,0x73,0x76,0x03,
0x3F,0xFF,0xFF,0xF7,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,
0xFC,0x00,0x63,0xE6,0x00,0x3F,0xFF,0xFF,0xDC,0x80,0x00,
0x00,0x00,0x7F,0xFF,0xFF,0xFC,0x00,0x03,0xFE,0x00,0x7F,
0xFF,0xFF,0xAF,0x60,0x00,0x00,0x00,0xFF,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xFF,0x00,0x1F,0xF0,0x00,0x02,0x00,0x00,
0x7F,0x80,0x3F,0xE0,0x00,0x00,0x00,0x00,0x7F,0x00,0x1F,
0xF0,0x00,0x00,0x00,0x00,0x3F,0xC0,0x3F,0xE0,0x00,0x00,
0x00,0x00,0x7F,0x00,0x3F,0xF0,0x00,0x00,0x00,0x00,0x3F,
0xC0,0x7F,0xE0,0x00,0x00,0x00,0x00,0x7F,0x00,0x3F,0xE0,
0x00,0x00,0x00,0x00,0x1F,0xE0,0x7F,0xC0,0x00,0x00,0x00,
0x00,0x3F,0x00,0x3F,0xE0,0x00,0x00,0x00,0x00,0x1F,0xE0,
0x7F,0xC0,0x00,0x00,0x00,0x00,0x3F,0x00,0x7F,0xE0,0x01,
0xC0,0xE0,0x00,0x1F,0xE0,0xFF,0xC0,0x00,0x70,0xE0,0x00,
0x3F,0x00,0x7F,0xE0,0x03,0xF3,0xF0,0x00,0x1F,0xE0,0xFF,
0xC0,0x00,0xF9,0xF0,0x00,0x3F,0x00,0x7F,0xE0,0x07,0xFF,
0xF8,0x00,0x1F,0xE0,0xFF,0xC0,0x01,0xFF,0xF8,0x00,0x3F,
0x00,0x7F,0xE0,0x07,0xFF,0xF8,0x00,0x1F,0xE0,0xFF,0xC0,
0x01,0xFF,0xF8,0x00,0x3F,0x00,0x7C,0xE0,0x07,0xFF,0xF8,
0x00,0x1B,0xE0,0xF9,0xC0,0x01,0xFF,0xF8,0x00,0x37,0x00,
0x38,0xF0,0x03,0xFF,0xF0,0x00,0x39,0xE0,0xF1,0xE0,0x00,
0xFF,0xF0,0x00,0x73,0x00,0x30,0x70,0x01,0xFF,0xE0,0x00,
0x30,0xC0,0x60,0xE0,0x00,0x7F,0xE0,0x00,0x61,0x00,0x00,
0x78,0x00,0xFF,0xC0,0x00,0x30,0x00,0x00,0xF0,0x00,0x3F,
0xC0,0x00,0x60,0x00,0x00,0x38,0x00,0x7F,0x80,0x00,0x60,
0x00,0x00,0x70,0x00,0x1F,0x80,0x00,0xC0,0x00,0x00,0x1C,
0x00,0x3F,0x00,0x00,0xC0,0x00,0x00,0x38,0x00,0x0F,0x00,
0x01,0x80,0x00,0x00,0x0E,0x00,0x1E,0x00,0x00,0x80,0x00,
0x00,0x1C,0x00,0x06,0x00,0x01,0x00,0x00,0x00,0x07,0x00,
0x0C,0x00,0x01,0x80,0x00,0x00,0x0E,0x00,0x06,0x00,0x03,
0x00 };
void write_12864com(uchar com)
{
rw = 0;
rs = 0;
delay_50us(1);
P0 = com;
e = 1;
delay_50us(10);
e = 0;
delay_50us(2);
}
void write_12864dat(uchar dat)
{
rw = 0;
rs = 1;
delay_50us(1);
P0 = dat;
e = 1;
delay_50us(10);
e = 0;
delay_50us(2);
}

使用特权

评论回复
6
Rooney30|  楼主 | 2016-3-27 20:47 | 只看该作者
void init_12864HZ(void)
{
delay_50ms(1);
psb = 1;
delay_50us(20);
res = 0;
delay_50us(20);
res = 1;
delay_50us(2);
write_12864com(0x30);
delay_50ms(2);
write_12864com(0x30);
delay_50us(1);
write_12864com(0x08);
delay_50us(2);
write_12864com(0x10);
delay_50us(2);
write_12864com(0x0c);
delay_50us(2);
write_12864com(0x01);
delay_50ms(1);
write_12864com(0x06);
delay_50us(4);
}
void init_12864PIC(void)
{
delay_50ms(1);
psb = 1;
delay_50us(10);
res = 0;
delay_50us(10);
res = 1;
delay_50us(20);
write_12864com(0x36); //Extended Function Set RE=1: extended instruction
delay_50ms(4);
write_12864com(0x36);
delay_50ms(2);
write_12864com(0x3e);//EXFUNCTION(DL=8BITS,RE=1,G=1)//设置为并口
delay_50ms(4);
write_12864com(0x01);//CLEAR SCREEN清屏
delay_50ms(4);
}
void display_HZ(void)
{
uchar i;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<64;i++)
{
  write_12864dat(pic2[i]);
  delay_50us(1);
}
}
void display_HZ1(void)
{
uchar i;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<64;i++)
{
  write_12864dat(pic4[i]);
  delay_50us(1);
}
}
void display_HZ2(void)
{
uchar i;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<64;i++)
{
  write_12864dat(pic5[i]);
  delay_50us(1);
}
}
void display_HZ3(void)
{
uchar i;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<64;i++)
{
  write_12864dat(pic[i]);
  delay_50us(1);
}
}
void display_FH(void)
{
uchar i,a=0x10;
write_12864com(0x80);
delay_50us(1);
for(i=0;i<16;i++)
{
     write_12864dat(a);
   delay_50us(1);
   a++;
}
}
void display_PIC(void)
{
int i,j;
uint a;
for(i=0;i<32;i++)
{
  write_12864com((0x80+i));
  write_12864com(0x80);
  for(j=0;j<16;j++)
   {
   write_12864dat(pic3[a]);
   a++;
   }
}
for(i=0;i<32;i++)
{
  write_12864com((0x80+i));
  write_12864com(0x88);
  for(j=0;j<16;j++)
   {
   write_12864dat(pic3[a]);
   a++;
   }
}
}
initfile.c
#include <reg52.h>
#include "initfile.h"
#include "lcd12864.h"
void init_all()
{
EA = 1;
ES = 1;
TMOD = 0X20;
TH1 = 0XFD;
TL1 = 0XFD;
TR1 = 1;
REN = 1;
SM1 = 1;
SM0 = 0;
init_12864HZ();//提示下车乘客提前按铃
display_HZ();
}
lcd.h
#ifndef _LCD12864_H_
#define _LCD12864_H_
#define uint unsigned int
#define uchar unsigned char
sbit rs = P2^0;
sbit rw = P2^1;
sbit e = P2^2;
sbit psb = P2^3;
sbit res = P2^5;
void write_12864com(uchar com);//写命令到lcd12864
void write_12864dat(uchar dat);//写数据到lcd12864
void init_12864HZ(void);//液晶显示汉字初始化
void init_12864PIC(void);//液晶显示汉字初始化
void display_HZ(void);
void display_HZ1(void);
void display_HZ2(void);
void display_FH(void);
void display_PIC(void);
#endif

delay.h
#ifndef _DELAY_H_
#define _DELAY_H_
#define uint unsigned int
#define uchar unsigned char
void delay_50us(uint t);
void delay_50ms(uint t);
void delays(uint j);
#endif

initfile.h

#ifndef _INITFILE_H
#define _INITFILE_H
#define uint unsigned int
#define uchar unsigned char
sbit key = P3^3;
sbit buzzer = P3^4;
sbit LEDY = P1^0;
sbit LEDG = P1^1;
sbit Relay = P3^5;
void init_all();
#endif

使用特权

评论回复
7
奥卡姆剃刀| | 2016-3-28 10:12 | 只看该作者
学习一下,顶一个!

使用特权

评论回复
8
user12have| | 2016-3-28 13:45 | 只看该作者

使用特权

评论回复
9
slotg| | 2016-3-28 13:50 | 只看该作者
感谢楼主分享。

使用特权

评论回复
10
bitofnoone| | 2016-3-28 20:45 | 只看该作者
这个很有创意啊,用到公交车上是不是换个电机就可以了啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

17

主题

117

帖子

3

粉丝