/****************wiegand34_v1.0 Head File***********************/
/**作者:SLY*************************版本:1.0***************/
/**********************MC9S08GB60**************************/
/***************************************************************
说明:BusClock = 8m
****************************************************************/
#i nclude "derivative.h"
#define wiegand34_data0DIR PTCDD_PTCDD6
#define wiegand34_data1DIR PTCDD_PTCDD7
#define Data0 PTCD_PTCD6
#define Data1 PTCD_PTCD7
void delay100us (void);
void delay1500us(void);
void wigand34_Send(unsigned char *ptrx);
/*******************wiegand34.c source file*********************/
/**作者:sly*************************版本:1.0***************/
/*********************MC9S08GB60**************************/
/***************************************************************
说明:BusClock = 8m
****************************************************************/
#i nclude"wiegand34_v1.0.h"
void wigand34_Send(unsigned char *ptrx)
{
unsigned char data_temp[2];
static unsigned int sdata[2];
unsigned long S_data = 0;
unsigned char i;
unsigned char onenum = 0;
unsigned char oddflag,evenflag;
unsigned long temp;
/********前16位偶校验************/
data_temp[0] = *ptrx;
data_temp[1] = *(ptrx+1);
sdata[0] = (sdata[0]|data_temp[0]);
sdata[0]<<=8;
sdata[0] = (sdata[0]|data_temp[1]);
S_data = ((S_data|sdata[0])<<16);
for(i=0;i<16;i++){
if(sdata[0]&0x01){
onenum++;
}
sdata[0]>>=1;
}
((onenum%2) == 0)?(evenflag = 0)evenflag = 1);
onenum =0;
/*******后16位奇校验*************/
data_temp[0] = *(ptrx+2);
data_temp[1] = *(ptrx+3);
sdata[1] = (sdata[1]|data_temp[0]);
sdata[1]<<=8;
sdata[1] = (sdata[1]|data_temp[1]);
S_data = (S_data|sdata[1]);
for(i=0;i<16;i++){
if(sdata[1]&0x01){
onenum++;
}
sdata[1]>>=1;
}
((onenum%2) == 0)?(oddflag = 1)oddflag = 0);
onenum = 0;
/****************发送数据*****************/
Data0 = 1;
Data1 = 1;
if(evenflag==1){
Data1 = 0;
delay100us ();
Data1 = 1;
}else{
Data0 = 0;
delay100us ();
Data0 = 1;
}
delay1500us(); //延时一个发送周期
for(i=0;i<32;i++){
temp="S"_data&0x80000000;
if(temp==0){
Data0 = 0;
delay100us();
Data0 = 1;
}else{
Data1 = 0;
delay100us();
Data1 = 1;
}
S_data<<=1;
delay1500us();
}
if(oddflag==1){
Data1 = 0;
delay100us ();
Data1 = 1;
}else{
Data0 = 0;
delay100us ();
Data0 = 1;
}
}
void delay100us (void){
asm{
LDA #120
Delay_us:
NOP ;1个时钟周期
NOP ;1个时钟周期
DBNZA Delay_us ;3个时钟周期
}
}
void delay1500us(void){
unsigned char i;
for(i=0;i<15;i++){
delay100us();
}
}
文章评论(0条评论)
登录后参与讨论