📄 per.c
字号:
void wdt_init(void)
{
WDTREL=WDT_TIME;
WDT=1;
SWDT=1;
}
void wdt_refresh(void)
{ //WatchDogTimer refresh function
WDT=1;
SWDT=1;
}
/*void output (unsigned int ad_value){
TMOD = 0x20;
TL1 = 0xe8;
TH1 = 0xe8;
TR1 = 1;
SCON = 0x40;
TI = 1;
// printf("The A/D value is %4.2fV. \n",(float)ad_value*5.0/1024);
}*/
/*//////////////////// functions for finding bit from message table/////*/
//******************************************************************************
//function: bit get_bit(unsigned char ModuleName,unsigned char BitNumber,
// unsigned char * BasePointer);
//description: thi function get the bit value from specified location of
// the seven row and eight line array such as MsgTrans[7][8].
//parameter: ModuleName---which module;BitNumber---bit location of the data block
// BasePointer---the pointer pointing to the base address.
//return: the bit value. |
//******************************************************************************
bit get_bit(unsigned char ModuleName,unsigned char BitNumber,unsigned char * BasePointer)
{
unsigned char char_v;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + (unsigned char)(BitNumber>>3);
BasePointer += char_v;
while(BitNumber>=8)
{
BitNumber-=8;
}
if (*BasePointer & (unsigned char)(1<<BitNumber)) return 1;
else return 0;
}
//******************************************************************************
//function: void set_bit(unsigned char ModuleName,unsigned char BitNumber,bit value
// unsigned char * BasePointer);
//description: thi function set the bit value specified location of
// the seven row and eight line array such as MsgTrans[7][8].
//parameter: ModuleName---which module;BitNumber---bit location of the data block
// value---specified bit value;
// BasePointer---the pointer pointing to the base address.
//return: none. |
//******************************************************************************
void set_bit(unsigned char ModuleName,unsigned char BitNumber,bit value,unsigned char * BasePointer)
{
unsigned char char_v;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + (unsigned char)(BitNumber>>3);
BasePointer += char_v;
while(BitNumber>=8)
{
BitNumber-=8;
}
if(value)
*BasePointer |= (unsigned char)(1<<BitNumber);
else
*BasePointer &= ~(unsigned char)(1<<BitNumber);
}
/////////////////????????????????????????//////////////////////////////////////////////
/////////////// 函数有问题///////////////////////////////////////////////////////
//****************************************************************************
//function: unsigned char get_byte(unsigned char ModuleName,unsigned char ByteNumber,
// unsigned char * BasePointer);
//description: thi function set the byte value from specified location of
// the seven row and eight line array such as MsgTrans[7][8].
//parameter: ModuleName---which module;ByteNumber---byte location of the data block
// value---specified byte value;
// BasePointer---the pointer pointing to the base address.
//return: none. |
//******************************************************************************
unsigned char get_byte(unsigned char ModuleName,unsigned char ByteNumber,unsigned char * BasePointer)
{
unsigned char char_v;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + ByteNumber;
BasePointer += char_v;
return(*BasePointer);
}
//******************************************************************************
//function: void set_byte(unsigned char ModuleName,unsigned char ByteNumber,unsigned char value
// unsigned char * BasePointer);
//description: thi function set the byte value from specified location of
// the seven row and eight line array such as MsgTrans[7][8].
//parameter: ModuleName---which module;ByteNumber---byte location of the data block
// value---specified byte value;
// BasePointer---the pointer pointing to the base address.
//return: none. |
//******************************************************************************
void set_byte(unsigned char ModuleName,unsigned char ByteNumber,unsigned char value,unsigned char * BasePointer)
{
unsigned char char_v;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + ByteNumber;
BasePointer += char_v;
*BasePointer=value;
}
//******************************************************************************
//function: unsigned char get_byte1(unsigned char ModuleName,unsigned char ByteNumber,
// unsigned char * BasePointer);
//description: thi function set the byte value from specified location of
// the seven row and eight line array such as MsgTrans[7][8].
//parameter: ModuleName---which module;ByteNumber---byte location of the data block
// value---specified byte value;
// BasePointer---the pointer pointing to the base address.
//return: none. |
//******************************************************************************
unsigned char get_byte1(unsigned char ModuleName,unsigned char ByteNumber,unsigned char * BasePointer)
{
unsigned char char_v;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + ByteNumber;
BasePointer += char_v;
return(*BasePointer);
}
//******************************************************************************
//function: void set_byte1(unsigned char ModuleName,unsigned char ByteNumber,unsigned char value
// unsigned char * BasePointer);
//description: thi function set the byte value from specified location of
// the seven row and eight line array such as MsgTrans[7][8].
//parameter: ModuleName---which module;ByteNumber---byte location of the data block
// value---specified byte value;
// BasePointer---the pointer pointing to the base address.
//return: none. |
//******************************************************************************
void set_byte1(unsigned char ModuleName,unsigned char ByteNumber,unsigned char value,unsigned char * BasePointer)
{
unsigned char char_v;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + ByteNumber;
BasePointer += char_v;
*BasePointer=value;
}
//******************************************************************************
//function: void set_feedback(unsigned char ModuleName,unsigned char FBNumber,unsigned char value
// unsigned char * BasePointer);
//description: thi function set the feedback value to the specified location
//
//parameter: ModuleName---which module;FBNumber---feedback location of the data block
// value---specified byte value;
// BasePointer---the pointer pointing to the base address.
//return: none. |
//******************************************************************************
void set_feedback(unsigned char ModuleName,unsigned char FBNumber,unsigned char value,unsigned char * BasePointer)
{
unsigned char char_v;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + (unsigned char)(FBNumber>>2);
BasePointer += char_v;
while(FBNumber>=4) //1 byte include 4 feedback value
{
FBNumber-=4;
}
value=(unsigned char) (value & 0x03)<<(FBNumber * 2);
(*BasePointer)|=value;
}
//******************************************************************************
//function: unsigned char get_feedback(unsigned char ModuleName,unsigned char FBNumber,
// unsigned char * BasePointer);
//description: thi function get the feedback value from specified location
//parameter: ModuleName---which module;FBNumber---feedback location of the data block
// BasePointer---the pointer pointing to the base address.
//return: feedback value. |
//******************************************************************************
unsigned char get_feedback(unsigned char ModuleName,unsigned char FBNumber,
unsigned char * BasePointer)
{
unsigned char char_v;
unsigned char temp_value;
// ModuleName--;
char_v = (unsigned char)(ModuleName<<3) + (unsigned char)(FBNumber>>2);
BasePointer+=char_v;
while(FBNumber>=4) //1 byte include 4 feedback value
{
FBNumber-=4;
}
temp_value= (*BasePointer)>>(FBNumber*2) & 0x03;
return temp_value;
}
//**********************************************************************************
//fuction: unsigned char Sort_Port_Bit(bit d0,bit d1,bit d2,bit d3
// bit d4,bit d5,bit d6,bit d7);
//description: This function modify one memory unit by the given bit value,the
// parameter location correspond to the memory unit bit location.
//parameter: "d7,d6...d0" is the corresponging bit value which will be sort.
//return: unsigned char combinated by sorted bit.
//**********************************************************************************
unsigned char Sort_Port_Bit(bit d0,bit d1,bit d2,bit d3,
bit d4,bit d5,bit d6,bit d7)
{
unsigned char PortBuffer;
PortBuffer=(PortBuffer&0x7f)|((unsigned char)d7<<7);
PortBuffer=(PortBuffer&0xbf)|((unsigned char)d6<<6);
PortBuffer=(PortBuffer&0xdf)|((unsigned char)d5<<5);
PortBuffer=(PortBuffer&0xef)|((unsigned char)d4<<4);
PortBuffer=(PortBuffer&0xf7)|((unsigned char)d3<<3);
PortBuffer=(PortBuffer&0xfb)|((unsigned char)d2<<2);
PortBuffer=(PortBuffer&0xfd)|((unsigned char)d1<<1);
PortBuffer=(PortBuffer&0xfe)|((unsigned char)d0);
return(PortBuffer);
}
//**********************************************************************************
//fuction: unsigned char Sort_Port_Bit1(bit d0,bit d1,bit d2,bit d3
// bit d4,bit d5,bit d6,bit d7);
//description: This function modify one memory unit by the given bit value,the
// parameter location correspond to the memory unit bit location.
//parameter: "d7,d6...d0" is the corresponging bit value which will be sort.
//return: unsigned char combinated by sorted bit.
//**********************************************************************************
unsigned char Sort_Port_Bit1(bit d0,bit d1,bit d2,bit d3,
bit d4,bit d5,bit d6,bit d7)
{
unsigned char PortBuffer;
PortBuffer=(PortBuffer&0x7f)|((unsigned char)d7<<7);
PortBuffer=(PortBuffer&0xbf)|((unsigned char)d6<<6);
PortBuffer=(PortBuffer&0xdf)|((unsigned char)d5<<5);
PortBuffer=(PortBuffer&0xef)|((unsigned char)d4<<4);
PortBuffer=(PortBuffer&0xf7)|((unsigned char)d3<<3);
PortBuffer=(PortBuffer&0xfb)|((unsigned char)d2<<2);
PortBuffer=(PortBuffer&0xfd)|((unsigned char)d1<<1);
PortBuffer=(PortBuffer&0xfe)|((unsigned char)d0);
return(PortBuffer);
}
///////////////////外部RAM或外设操作函数///////////////////////////////////////////////////
//***************************************************************************************
//fuction: void write_memory_bit(xp,n,value);
//description: modify one bit of the memory unit.
//parameter: xp---pointer on data or xdata; n---bit location;value---value to be write.
//return: none
//data: 2001-3-29
//***************************************************************************************
void write_memory_bit(xp,n,value) //write value "0" or "1" to a bit of extern ram
unsigned char * xp;
unsigned char n;
bit value;
{
if(value==1)
{
*xp=(*xp)|(unsigned char)(1<<n);
}
else
{
*xp=(*xp)&(~(unsigned char)(1<<n));
}
}
//***************************************************************************************
//fuction: void write_memory_bit1(xp,n,value);
//description: modify one bit of the memory unit.
//parameter: xp---pointer on data or xdata; n---bit location;value---value to be write.
//return: none
//data: 2001-3-29
//***************************************************************************************
/*
void write_memory_bit1(xp,n,value) //write value "0" or "1" to a bit of extern ram
unsigned char * xp;
unsigned char n;
bit value;
{
if(value==1)
{
*xp=(*xp)|(unsigned char)(1<<n);
}
else
{
*xp=(*xp)&(~(unsigned char)(1<<n));
}
}
*/
//***************************************************************************************
//fuction: bit read_memory_bit(xp,n,value);
//description: read one bit from the memory unit.
//parameter: xp---pointer on data or xdata; n---bit location.
//return: bit value
//data: 2001-3-29
//***************************************************************************************
bit read_memory_bit(xp,n) //read one bit of the extern ram and retern the bit value
unsigned char * xp;
unsigned char n;
{
bit temp_bit;
if( ((unsigned char)((*xp)>>n) & 0x01)==0x01 )
{
temp_bit=1;
}
if( ((unsigned char)((*xp)>>n) & 0x01)==0x00 )
{
temp_bit=0;
}
return(temp_bit);
}
//***************************************************************************************
//fuction: bit read_memory_bit1(xp,n,value);
//description: read one bit from the memory unit.
//parameter: xp---pointer on data or xdata; n---bit location.
//return: bit value
//data: 2001-3-29
//***************************************************************************************
/*
bit read_memory_bit1(xp,n) read one bit of the extern ram and retern the bit value
unsigned char * xp;
unsigned char n;
{
bit temp_bit;
if( ((unsigned char)((*xp)>>n) & 0x01)==0x01 )
{
temp_bit=1;
}
if( ((unsigned char)((*xp)>>n) & 0x01)==0x00 )
{
temp_bit=0;
}
return(temp_bit);
}
*/
//**********************************************************************************
//bit bit rain_fil0(MsgTrans[2][5]); added by lihx
//**********************************************************************************
//function: bit rain_fil0(MsgTrans[2][5]);
//description: read one bit of the extern memory unit,return a bit type value .
//parameter: MsgTrans[2][5]---the value to filter
//return: the bit value of rainscarft
//**********************************************************************************
bit rain_fil0(unsigned char rainfilter0,unsigned char rainfilter1)
{
bit rainfil0=0;
if((rainfilter0&&0x0c)==(rainfilter1&&0x0c))
{
rainfil0=(~rainfilter1&0x0c);
}
else
{
;
}
return (rainfil0);
}
//**********************************************************************************
//bit bit rain_fil1(MsgTrans[2][5]); added by lihx
//**********************************************************************************
//function: bit rain_fil1(MsgTrans[2][5]);
//description: read one bit of the extern memory unit,return a bit type value .
//parameter: MsgTrans[2][5]---the value to be filter
//return: the bit value of rainscarft
//**********************************************************************************
bit rain_fil1(unsigned char rainfilter2,unsigned char rainfilter3)
{
bit rainfil1=0;
if((rainfilter2&&0x30)==(rainfilter3&&0x30))
{
rainfil1=(~rainfilter3&0x30);
}
else
{
;
}
return (rainfil1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -