找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1991|回复: 3
收起左侧

keil 4编译没问题,但是protues无法仿真,想请教一下!题目是汽车超速报警系统设计

[复制链接]
ID:316737 发表于 2018-5-10 12:19 | 显示全部楼层 |阅读模式
#include<reg52.h>
sbit LCD_RS=P1^0;
sbit LCD_RW=P1^1;
sbit LCD_E=P1^2;
#define LCD_DATA P2
#define LCD_BUSY 0x80
#define uchar unsigned char
#define uint unsigned int
uint speed;
uchar test=1;
uchar normal=0;
uchar nor_speed;
uchar exc_speed;
uchar cnt_ovtime;
uint data dis[5]={0x00,0x00,0x00,0x00,0x00};
void lcd_init(void);
void display_string(uchar x,uchar y,uchar *s);
void disp_selec(uchar bit_selec,uchar seg);
void init_timer0();
void init_timer1();
void delay_ms(uint i)
{
uint j;
while(i--)
{
for(j=0;j<125;j++);
}
}
void dellay(uint h)
{
while(h--);
}
void init_timer0()
{
TMOD=0x51;
TH0=0xD8;
TL0=0xF0;
ET0=1;
EA=1;
TR0=1;
}
void init_timer1()
{
TMOD=0x51;
TH1=0x00;
TL1=0x00;
ET1=1;
EA=1;
TR1=1;
}
void it_timer0() interrupt 1
{
uchar counter;
TF0=0;
TH0=0xD8;
TL0=0xF0;
counter++;
if(counter==100)
{
speed=(TH1*256+TL1+65536*cnt_ovtime)/100;
if(speed>=1200)
{
exc_speed=1;
nor_speed=0;
}
else
{
nor_speed=1;
exc_speed=0;
}
TH1=TL1=0x00;
counter=0;
cnt_ovtime=0;
}
}
void it_timer1()interrupt 3
{
TF1=0;
cnt_ovtime++;
}
void WriteDataLcd(uchar wdata)
{
LCD_DATA=wdata;
LCD_RS=1;
LCD_RW=0;
LCD_E=0;
dellay(100);
LCD_E=1;
}
void WriteCommandLcd(uchar wdata)
{
LCD_DATA=wdata;
LCD_RS=0;
LCD_RW=0;
LCD_E=0;
dellay(100);
LCD_E=1;
}
void lcd_init(void)
{
LCD_DATA=0;
WriteCommandLcd(0x38);
dellay(1000);
WriteCommandLcd(0x38);
WriteCommandLcd(0x08);
WriteCommandLcd(0x01);
WriteCommandLcd(0x06);
WriteCommandLcd(0x0c);
}
void display_xy(uchar x,uchar y)
{
if(y==1)
x+=0x40;
x+=0x80;
WriteCommandLcd(x);
}
void display_char(uchar x,uchar y,uchar dat)
{
display_xy(x,y);
WriteDataLcd(dat);
}
void display_string(uchar x,uchar y,uchar *s)
{
display_xy(x,y);
while(*s)
{
WriteDataLcd(*s);
s++;
}
}
void main()
{
lcd_init();
init_timer0();
init_timer1();
if(test)
{
P3 |=0x07;
display_string(0,0,"Life is precious!");
display_string(0,1,"Safe Driving!");
delay_ms(2000);
P3 &=~0x07;
lcd_init();
test=0;
normal=1;
delay_ms(2000);
}
if(normal)
{
while(1)
{
if(nor_speed)
{
P3 |=0x01;
P3 &=~0x06;
display_string(0,0,"Speed:");
dis[3]=speed/1000;
dis[4]=speed%1000;
dis[2]=dis[4]/100;
dis[4]=dis[4]%100;
dis[1]=dis[4]/10;
dis[0]=dis[4]%10;
if(dis[3]!=0)
{
display_char(6,0,dis[3]+0x30);
}
else
{
display_char(6,0,0xA0);
}
display_char(7,0,dis[2]+0x30);
display_char(8,0,dis[1]+0x30);
display_char(10,0,dis[0]+0x30);
display_string(9,0,".");
display_string(11,0,"km/h");
display_string(0,1,"Status:Normal");
}
if(exc_speed)
{
display_string(0,0,"Speed:");
dis[3]=speed/1000;
dis[4]=speed%1000;
dis[2]=dis[4]/100;
dis[4]=dis[4]%100;
dis[1]=dis[4]/10;
dis[0]=dis[4]%10;
if(dis[3]!=0)
{
display_char(6,0,dis[3]+0x30);
}
else
{
display_char(6,0,0xA0);
}
display_char(7,0,dis[2]+0x30);
display_char(8,0,dis[1]+0x30);
display_char(10,0,dis[0]+0x30);
display_string(9,0,".");
display_string(11,0,"km/h");
display_string(0,1,"Status:Speeding!");
P3 &=~0x01;
P3 |=0x06;
delay_ms(500);
display_string(0,1,"Warning!");
P3 &=~0x06;
delay_ms(500);
}
}
}
}
fang.png


回复

使用道具 举报

ID:327088 发表于 2018-5-11 21:38 | 显示全部楼层
生成hex文件了吗?生成hex文件后需要将程序添加到单片机中运行
回复

使用道具 举报

ID:308479 发表于 2018-5-12 00:32 | 显示全部楼层
lcd接线接完了吗?
回复

使用道具 举报

ID:327962 发表于 2018-5-12 12:50 来自手机 | 显示全部楼层
防真软件一点都不靠谱
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表