📄 main.c
字号:
#include "REG51F.H"
#include "absacc.h"
#include "string.h"
#include "stdio.h"
#include "intrins.h"
#include "flash.h"
#include<rc500.h>
//#include "7219.H"
#include "comm.h"
#include "595.H"
#include <rc500.h>
#include "ds1307.H"
#include "intrins.h"
#define CAR 14
#define BAN 13
#define ESC 10
#define ENTER 12
#define SERCH 11
bit rc500_ok;
sbit dog=P1^7;
sbit row0=P1^0;
sbit row1=P1^1;
sbit row2=P1^2;
sbit r485_en=P4^3;
//sbit in1=P2^4;
//sbit in2=P2^6;
//sbit in3=P2^5;
sbit spk=P3^2;
bit num_suss,sta=0,time_set=0;
void beep(unsigned char times);
#define watch_dog() WTDC=WTDC|0X20;//dog=!dog
static unsigned char xdata RemainRec[100];//RemainRec[10][11] _at_ 0x000;//Page1,2,3,4,5,6,7
extern unsigned char idata outbyte;
extern bit tflag;
unsigned char data ADDR;
bit Keyinput_ok=0,link=0;
bit ban=0;
unsigned char idata input_pc[5],mainstate=0,ledtem[10],ms[16],psnr[4],keyin=0;
unsigned int idata lage_car=0,small_car=0;
bit in_outFlg;
//************************程序用的变量********************
//********************************************************************
union charint{
unsigned char chrX[2];
unsigned int intX;
};
struct _time
{
unsigned long l;
unsigned int i;
unsigned char sec;
};
union __time
{
struct _time tt;
unsigned char a[7];
};
static union __time data time ;
/****************************************************************************/
void Delay100ms(unsigned char x)
{
unsigned char i,j;
while(x-- != 0)
{watch_dog();
if (Cmdok) //通讯
{
Cmdok = FALSE;
RecvReady = FALSE;
SendReady = FALSE;
cmd_execution();
SendReady = TRUE ; //发起始字
TI = 1;
}
for (j = 0;j < 114; j++)for (i = 0;i < 88; i++){_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;
_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;
_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;
_nop_() ;_nop_() ;_nop_() ;};
}
}
/****************************************************************************/
void Delay1ms(unsigned char x)
{
unsigned char i;
while(x-- != 0)
{ if (Cmdok) //通讯
{
Cmdok = FALSE;
RecvReady = FALSE;
SendReady = FALSE;
cmd_execution();
SendReady = TRUE ; //发起始字
TI = 1;
}
for (i = 0;i < 89; i++){_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;
_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;
_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;
_nop_() ;_nop_() ;_nop_() ;};
}
}
//************************************************************************
//**********************************************************************
unsigned int Get_key(void)
{
unsigned char data x;
//inttem.intX=0xffff;
//unsigned int y;
row0=0;
row1=1;
row2=1;
P2=0XfF;
x=P2;
x=x&0x1f;
if(x!=0x1f)
{
// beep(1);
Delay1ms(120);
if(x==0x17)
return 7;
if(x==0x1b)
return 8;
if(x==0x1d)
return 9;
if(x==0x1e)
return 10;
if(x==0x0f)
return 12;
}
row0=1;
row1=0;
row2=1;
P2=0X1F;
x=P2;
x=x&0x1f;
if(x!=0x1f)
{
// beep(1);
Delay1ms(150);
if(x==0x17)
return 4;
if(x==0x1b)
return 5;
if(x==0x1d)
return 6;
if(x==0x1e)
return 11; //菜单
if(x==0x0f)
return 13; //小车
}
row0=1;
row1=1;
row2=0;
P2=0X1F;
x=P2;
x=x&0x1f;
if(x!=0x1f)
{
// beep(1);
Delay1ms(150);
if(x==0x17)
return 1;
if(x==0x1b)
return 2;
if(x==0x1d)
return 3;
if(x==0x1e)
return 0;
if(x==0x0f)
return 14; //大车
}
return( 0xff);// y;
}
/****************************************************************************
* *
* Function: init_com *
* *
* Input: - *
* Output: - *
* *
* Description: *
****************************************************************************/
void init_com(void)
{
PCON = 0x80; // SMOD = 1; bps = Time1/16
SCON = 0x50; // Mode 1, 1 star bit, 8 data bit, 1,stop bit UART, enable receive
TMOD = 0x21; // Timer 1, mode 2, 8-bit auto reload,
// Timer 0, mode 1, 16-bit counter
TH1 = BAUD_9600; //BAUD_115200;
TL1 = TH1;
TR1 = 1; // Timer 1 run
/*
TCLK = 1;
RCLK = 1;
RCAP2H = 0xff ;//65536L - ( 22118400L / 32 / 57600L);
RCAP2L = 0xf4 ;// 0xF4--57600 , 0xFA--115200
TR2 = 1; // Timer 2 run
*/
ES = 1; // Enable serail interrupts
ET0 = 1; // Enable t0 interrupts
RecvState = RECV_STX;
RecvReady = TRUE;
SendReady = FALSE;
SendOk = FALSE;
Cmdok = FALSE;
En485 = RECV;
EA=1;
}
/**********************************************************************8
void Wdtinit(void)
{
SCONF=SCONF&0X7F;
WTDC=0X87;
}
/*****************************************************************************
* 初始化RC500
*注意:RC500上电后应延时500ms才能可靠初始化
*****************************************************************************/
void Rc500Ready()
{
char status;
DelayMs(100);
DelayMs(100);
DelayMs(100);
DelayMs(100);
DelayMs(100);
status=PcdReset();
if(status!=MI_OK)
{
DelayMs(100);
status=PcdReset();
}
if(status==MI_OK)
rc500_ok=1;
else
rc500_ok=0;
}
/****************************************************************************
* *
* Function: START_T0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void START_T0(unsigned char x)
{
ET0 = 0 ;
TR0 = 0;
Timer0Cnt = x ;
TL0 = 0;
TH0 = 0;
TR0 = 1;
ET0 = 1 ;
}
/****************************************************************************
* *
* Function: CALL_isr_T0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void CALL_isr_T0(void)
{
TR0 = 0;
Timer0Cnt = 0;
TF0 = 1;
}
/****************************************************************************
* *
* Function: isr_timer0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
****************************************************************************/
void isr_timer0(void) interrupt 1 using 3
{
//TOGGLE_WD();
if ( Timer0Cnt != 0 )
{
--Timer0Cnt;
}
else
{
TR0 = 0 ;
if ((RecvState == RECV_DLE) || (RecvState == RECV_DLE_OR_NAK)) //发送起始字超时
{
ErrorCount++;
if ( ErrorCount <= 3)
{
SendReady = TRUE;
RecvReady = FALSE;
En485 = SEND;
//Ir_En = SEND;
//Delay50us(2);
TI = 1;
}
else
{
ErrorCount = 0 ;
SendReady = FALSE;
RecvReady = TRUE;
RecvState = RECV_STX;
En485 = RECV;
//Ir_En = RECV;
}
}
else //接收超时
{
SendReady = FALSE;
RecvReady = TRUE;
RecvState = RECV_STX;
En485 = RECV;
//Ir_En = RECV;
};
};
}
//******************************************************************************
/****************************************************************************
* *
* Function: isr_UART *
* *
* Input: - *
* Output: - *
* *
* Description: *
****************************************************************************/
void isr_UART(void) interrupt 4 using 1
{
unsigned char c , oldRecvState , i , bcc;
if ( RI ) // Receive Command
{
TR0 = 0 ; //stop t0
c = SBUF;
RI = 0;
if (RecvReady)
{
SendReady = FALSE;
oldRecvState = RecvState;
RecvState = RECV_STX;
switch (oldRecvState)
{
case RECV_STX: // Receive STX and answer DLE
if (c == STX)
{
// RED_LED = ~RED_LED;
En485 = RECV;
//Ir_En = RECV ;
RecvState = RECV_ADDR0;
START_T0(T_533_ms);
}
else
{
CALL_isr_T0() ;
};
break;
case RECV_ADDR0:
if (c == ADDR)//0xd2)//s_ID[0])
{
RecvState = RECV_ADDR1;
START_T0(T_533_ms);
}
else
{
CALL_isr_T0() ;
};
break;
case RECV_ADDR1:
if (c ==0x02)//[1])
{
RecvState = RECV_ADDR2;
START_T0(T_533_ms);
}
else
{
CALL_isr_T0() ;
};
break;
case RECV_ADDR2:
if (c == 0x96)//s_ID[2])
{
RecvState = RECV_ADDR3;
START_T0(T_533_ms);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -