标题:
单片机车载智能设备程序源码
[打印本页]
作者:
樊锋
时间:
2020-11-20 13:09
标题:
单片机车载智能设备程序源码
这个程序是实现泥头车远程智能管理,远程平台可以实时对车辆进行监控。车载智能设备每隔3秒钟就给平台发送车辆位置,油剩余量,车速,扬尘量数据发送到平台。
单片机源程序如下:
#include "eeprom.h"
#include "bianma.h"
#include <reg52.h>
#include <intrins.h>
sbit AM=P3^2;
sbit BM=P3^3;
sbit k=P3^7;
sbit s=P3^6;
extern uint temp,temp2;
extern uint AR,BR;
extern uint date;
extern uchar kc;
extern uint AT,BT;
uchar num_a=0;
uchar num_b=0;
uint dateA, dateB,numB;
uchar cofig,key,a=0;
uchar ok,u;
uchar i,r;
uint Compare[5]={0,0,0,0,0};
uint Compare1[5]={0,0,0,0,0};
void waiint()
{
EX0=1;
IT0=0;
EA=1;
}
void delayss(UINT16 z)
{
UINT16 x,y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
void main()
{
waiint();
intt();
num_a=EEPROMReadByte(1);delayss(60);
num_b=EEPROMReadByte(2);delayss(60);
//date=num_a+(254*num_b);
SBUF=num_a;while(TI==0);TI=0;
TR1=1;
SBUF=num_b;while(TI==0);TI=0;
delay(100);
date=num_a;
date=(date<<8)&0xff00;
date=date|num_b;
key=2;
kc=0;
dateA=0;
while(1)
{
if(s==0)
{
delay(10);
if(s==0)
{ AR=0;}}
while(k==0)
{ TR0=1;
while(k==0)
{
ok=1;
if(Compare1[0]==0xff&&Compare1[1]==0xff&&Compare1
[2]==0xff&&Compare1[3]==0xff&&Compare1[4]==0xff)
{r++;}
else
if(Compare1[0]==0x00&&Compare1[1]==0x00&&Compare1
[2]==0x00&&Compare1[3]==0x00&&Compare1[4]==0x00)
{r++;}
else
{ Compare[4]=0x00;}
if(r==5&&Compare[0]<Compare[4])
{dateA=Compare[4];r=0;}
// dateA=Compare[9];
TR1=1;
if(dateA!=0)
{
SBUF=num_a=dateA>>8;
while(TI==0);TI=0;TR1=1;
SBUF=num_b=dateA&0XFF;
while(TI==0);TI=0; }}
TR0=0;
delay(1);
EA=0;
EEPROMSectorErase(1);
EEPROMWriteByte(1,num_a);
EEPROMWriteByte(2,num_b);
delay(1000); EA=1; }
// mm: dateA=caiji();
// if(dateA==0xff)
// {goto mm;}
if(Compare1[0]==0xff&&Compare1[1]==0xff&&Compare1
[2]==0xff&&Compare1[3]==0xff&&Compare1[4]==0xff)
{r++;}
else
if(Compare1[0]==0x00&&Compare1[1]==0x00&&Compare1
[2]==0x00&&Compare1[3]==0x00&&Compare1[4]==0x00)
{r++;}
else
{ Compare[4]=0x00;}
if(r==5&&Compare[0]<Compare[4])
{dateA=Compare[4];r=0;}
if(key==10)//顺时针转cofig=1;(关闭 )
{
if(dateA>20)
{ TR2=1;
if(temp>=1000)
{
temp=0;
if(date<=(dateA+5))// 车蓬闭合良好
{ SBUF=0xd2;while(TI==0);TI=0;dateA=0;
key=2;AT=BT=0;TF2=0;TR2=0;delay(1000);}
else
{SBUF=0xd1;while(TI==0);TI=0;TF2=0; delay(100);}
}}
}
if(key==2) //逆时针转cofig=0;( 打开 )
{
if((dateA>=30)&&(dateA<=300))//车蓬没关好
{
TR2=1;
if(temp>1000)
{SBUF=0xd1;while(TI==0);TI=0;temp=0;}
}
if(dateA>350)
{temp=0;TR2=0;}
if(date<=(dateA+30)) //车篷全开
{
temp=0;
TR2=0;SBUF=0xd3;while(TI==0);
TI=0;dateA=0;key=1;AT=BT=0;TF2=0;delay(10);}
}
}}
void teim(void) interrupt 0
{ uchar h,l;
while(AM==0);
if(ok==1)
{
if(BM==1)
{h++;if(h==5){dateA++;cofig=0xff;h=0;u++;}}//顺时针
else
if(BM==0)
{l++;if(l==5){dateA++;cofig=0x00;l=0;u++;}}//逆时针
Compare[u]=dateA;
Compare1[u]=cofig;
if(u==5){u=0;}
ok=0; }TR0=0;TR1=1;}
void time4(void) interrupt 4
{TR1=0;}
void time0(void) interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
temp++; temp2++;
if (temp2>5000)
{temp2=0;}
if(temp>2000)
{temp=0;}
}
复制代码
作者:
admin
时间:
2020-11-21 22:04
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
作者:
樊锋
时间:
2020-11-30 14:22
车载智能管理设备电路原理图现在上传
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1