📄 mmm.c
字号:
//#include <reg52.h>
#include<w77c32.h>
#include <absacc.h>
#include "string.h"
#include "serial.h"
#include "intrins.h"
#include "e25045.h"
#include "comm.h"
static unsigned char xdata RemainRec[4][16];
unsigned char xdata Card_id[200];
unsigned char idata ring_flg=0,x,ADDR;
//*********************************************************
union charint{
unsigned char chrX[2];
unsigned int intX;
};
union charint ad_temp, recordint;
//************************程序用的变量********************
unsigned char data RXtem[6], RXdata[6];//程序接收数据缓冲区
unsigned char data RXNOM,RXSTAT;
unsigned char data RXTimerOUT,com1=0,com2=0; //接收超时
bit rxok,Waring=0; // 接收完成标志
sbit CS=P2^4;
sbit PWR_UP=P2^5;
sbit TX_EN=P2^6;
sbit Test_led=P1^4;
unsigned char c ;
/****************************************************************************/
void Delay100ms(unsigned char x)
{
unsigned char i,j;
while(x-- != 0)
{ //Watch_dog();
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 idata x)
{
unsigned char i;
while(x-- != 0)
{ Watch_dog();
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_() ;};
}
}
/****************************************************************************/
void Delay(unsigned char idata x)
{
while(x-- != 0)
{
_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;
_nop_() ;_nop_() ;_nop_() ;
}
}
/****************************************************************************
* *
* Function: init_com *
* *
* Input: - *
* Output: - *
* *
* Description: *
****************************************************************************/
void init_com(void)
{
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;
}
/****************************************************************************
* *
* Function: START_T0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void START_T0com2(unsigned char x)
{
ET0 = 0 ;
TR0 = 0;
RXTimerOUT = x ;
TL0 = 0;
TH0 = 0;
TR0 = 1;
ET0 = 1 ;
com2=1;
}
/****************************************************************************
* *
* 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 ;
com1=1;
}
/****************************************************************************
* *
* Function: CALL_isr_T0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void CALL_isr_T0com2(void)
{
//TR0 = 0;
RXTimerOUT = 0;
//TF0 = 1;
com2=0;
}
/****************************************************************************
* *
* Function: CALL_isr_T0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void CALL_isr_T0(void)
{
// TR0 = 0;
Timer0Cnt = 0;
// TF0 = 1;
com1=0;
}
//********************串口中断处理程序**************************************************************
void ub1ISR(void) interrupt 7 using 1
{
unsigned char data c;
if ( RI_1 ) // Receive Command
{
RI_1 = 0;
c = SBUF1;
switch(RXSTAT)
{
case 0: //接受帧头02
if(c==0x88)
{RXSTAT=1;START_T0com2(20); }
else
CALL_isr_T0com2();
break;
case 1: //接收
if(c==0xff)
{
RXSTAT=2;
START_T0com2(20);
}
else
{
RXSTAT=0;
CALL_isr_T0com2();
}
// RXSTAT=0;
break;
case 2:
x=c;
RXSTAT=3;
START_T0com2(20);
break;
case 3:
if(x==c)
{
rxok=1;
ring_flg=x;
}
RXSTAT=0;
x=0;
CALL_isr_T0com2();
break;
default:
RXSTAT=0;
break;
}
}
else
{
TI_1=0;
}
}
/****************************************************************************
* *
* Function: isr_UART *
* *
* Input: - *
* Output: - *
* *
* Description: *
****************************************************************************/
void isr_UART(void) interrupt 4 using 2
{
// WatchDog();
if ( RI ) // Receive Command
{
TR0 = 0 ; //stop t0
c = SBUF;
Test_led=! Test_led;
RI = 0;
En485=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();
SBUF=c;
while(!TI);
TI=0;
En485=0;
_nop_(); _nop_(); _nop_(); _nop_();
}
if ( TI && !RI )
{
TI = 0 ;
};
}
/*************************原有的函数需改变*************************************
* *
* Function: isr_timer0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void isr_timer0(void) interrupt 1 using 0
{
//TR0=0;
if(com2)
{
if(RXTimerOUT!=0) //此if{}else{} 为新加入的判断超时功能
{
RXTimerOUT--;
}
else
{
RXSTAT=0;
RXNOM=0;
}
}//end ifcom2
if(com1)
{
if ( Timer0Cnt != 0 )
{
--Timer0Cnt;
}
else
{
TR0 = 0 ;
if ((RecvState == RECV_DLE) || (RecvState == RECV_DLE_OR_NAK)) //发送起始字超时
{
ErrorCount++;
if ( ErrorCount <= 1)
{
SendReady = TRUE;
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;
};
};
}
TR0=1;
TH0=0X90;
TL0=0X95;
//TR0=1;
}
//**************************************************************
unsigned char Find(unsigned char addr)
{
unsigned char i=0;
TX_EN=1;
Delay1ms(4);
// Test_led=!Test_led;
PutChar1(0x55);
PutChar1(0xaa);
PutChar1(addr);
PutChar1(addr);
TX_EN=0;
Comm_On();
Delay1ms(13);
/*while(!rxok)
{
Delay1ms(1);
i++;
if(i>20)break;
}*/
Comm_Off();
TX_EN=1;
if(rxok)
{
rxok=0;
if(ring_flg==2)Waring=1;
return(ring_flg);
}
else
{
return 0;// return 0;
}
}
/****************************************************************************
* *
* Function: TransferRecord *
* *
* Input: - uchar 1 *
* Output: - 0 *
* *
* Description: *
****************************************************************************/
TransferRecord(unsigned char Day , unsigned int i)
{
Day=0;
SerBuffer[3] = RemainRec[i][0];//.Flg ;
SerBuffer[4] = RemainRec[i][1];//ParkingRecord[i].CardID.chrX[3] ;
SerBuffer[5] =RemainRec[i][2];//ParkingRecord[i].CardID.chrX[2] ;
SerBuffer[6] =RemainRec[i][3];//ParkingRecord[i].CardID.chrX[1] ;
SerBuffer[7] =RemainRec[i][4];//ParkingRecord[i].CardID.chrX[0] ;
SerBuffer[8] = RemainRec[i][5];// ParkingRecord[i].BeginTime.hour ;
SerBuffer[9] =RemainRec[i][6];// ParkingRecord[i].BeginTime.minute ;
SerBuffer[10]= RemainRec[i][7];// ParkingRecord[i].BeginTime.second ;
SerBuffer[11] =RemainRec[i][8]; // ParkingRecord[i].BeginTime.century ;
SerBuffer[12] =RemainRec[i][9];// ParkingRecord[i].BeginTime.year ;
SerBuffer[13] =RemainRec[i][10];// ParkingRecord[i].BeginTime.month ;
SerBuffer[14] =RemainRec[i][11];// ParkingRecord[i].BeginTime.day ;
SerBuffer[15] =RemainRec[i][12];
SerBuffer[16] =RemainRec[i][13];
SerBuffer[17] =RemainRec[i][14];
SerBuffer[18] =RemainRec[i][15];
//SerBuffer[14] =RemainRec[i][16];
}
//*************************************************************************
void SetPosNum(unsigned char xdata *dat)
{
//ByteWrite_Check (124,dat[0]);
ByteWrite_Check(20,dat[0]);
ADDR=dat[0];
}
/****************************************************************************
* cmd_execution(); *
* Function: *
* *
* Input: *
* Output: - *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -