//*******************************************************************
//74hc165驱动
//双字节返回
//Number 接收几组数据 pBuf 接收到的数据
void Equally_To_Strand_74HC165_Drive_Two_Byte(tByte Number, tByte *pBuf)
{
tByte i=0, j, c= 0;
PL_165 = 1;
_nop_();
PL_165 = 0;
_nop_();
PL_165 = 1;
for(j=0; j<(Number*8); j++){
// CP_165 = 1;
i <<= 1;
CP_165 = 0;
_nop_();
i |= DIN_165;
// CP_165 = 0;
CP_165 = 1;
_nop_();
c++;
if(8 == c){
*pBuf = i;
c = 0;
pBuf++;
}
}
}
/*************************************************************/
//两字节传送
////74hc595驱动
//Number 发送几组数据 pBuf要输出的数据
void Strand_To_Equally_74HC595_Two_Byte(tByte Number, tByte *pBuf){
/* tByte i, j;
for(; Number>0; Number++){
i = *pBuf;
for(j=0; j<8; j++){
DS = i&0x80;
i <<= 1;
SH_CP = 0;
SH_CP = 1;
}
ST_CP = 0;
ST_CP = 1;
ST_CP = 0;
pBuf++;
}*/
tByte a, Data, Count=0;
ST_CP= 0;
for(a=0; a<(8*Number); a++){
if(0== (a%8))
Data = pBuf[Count++];
SH_CP = 0;
if(Data & 0x80)
DS = 1;
else
DS = 0;
Data <<= 1;
SH_CP= 1;
}
ST_CP= 1;
ST_CP= 0;
}
//根据线材类型选择相应的测试数据库 对比
//
const tWord code CableLibrary[3][8][2]={
{
{0xfe, 0xfe},
{0xfd, 0xfd},
{0xfb, 0xdf},
{0xf7, 0xf7},
{0xef, 0xef},
{0xdf, 0xdf},
{0xbf, 0xbf},
{0x7f, 0x7f}, //SKP 线材数据
},
{
{0xfe, 0xfe},
{0xfd, 0xfd},
{0xfb, 0xfb},
{0xf7, 0xf7},
{0xef, 0xef},
{0xdf, 0xdf},
{0xbf, 0xbf},
{0x7f, 0x7f}, //VF线材数据
},
{
{0xfe, 0xfe},
{0xfd, 0xfd},
{0xfb, 0xdf},
{0xf7, 0xf7},
{0xef, 0xef},
{0xdf, 0xdf},
{0xbf, 0xbf},
{0x7f, 0x7f}, //SKS线材数据
}
};
//595输出数据数组 2片则2字节
tByte CabelOutData[8][2]={
{0x01, 0x01},
{0x02, 0x02},
{0x04, 0x04},
{0x08, 0x08},
{0x10, 0x10},
{0x20, 0x20},
{0x40, 0x40},
{0x80, 0x90},
};
//165接收数据数组 2片则2字节
tByte CabelInputData[8][2]={0};
//测试函数
void VF_Auto_Test(void){
tWord i, j=0; //循环变量
bit CheckA = 0; //测试结果标志位A组
bit CheckB = 0; //测试结果标志位 B组
//165&595接收数据
for(i=0; i<8; i++){
//想实现595每次输出2个字节的数据循环8次 165采集8组2字节数据
//但是感觉*(CabelOutData+i)是移动1字节的这样做对吗? 不是很清楚用法
//麻烦哪位朋友帮忙给点指导实现我的需求
//需求就是595一次输出2字节数据 循环8次 输出 CabelOutData多维数组
//165就是采集2字节数据,循环8次将数据保存在CabelInputData多维数组
//然后用CabelInputData多维数组和CableLibrary数据库比对
Strand_To_Equally_74HC595_Two_Byte(2, *(CabelOutData+i)); //输出8组2位数据
Delay_50ms(4); //延时100ms
Equally_To_Strand_74HC165_Drive_Two_Byte(2, *(CabelInputData+i)); //接收8组2位数据
Delay_50ms(4); //延时100ms
}
//2片165接收数据
Delay_50ms(10); //延时1S
//据 根据选择的线材数据进行比对
for(i=0; i<8; i++){
if(CableLibrary[1][i][0]== CabelInputData[i][0]){
LCD12864_Write_Str((i+1), 2, "√");
CheckA = 1; //pass
}else{
LCD12864_Write_Str((i+1), 2, "×");
CheckA = 0;
}
if (CableLibrary[1][i][1]== CabelInputData[i][1]){ //VF线材1组测试
LCD12864_Write_Str((i+1), 3, "√");
CheckB = 1;
}else{
LCD12864_Write_Str((i+1), 3, "×");
CheckB = 0;
}
}
if((1==CheckA)&&(1==CheckB)){
Pass_Alarm(); //测试通过提示
LCD12864_Write_Str(4, 4, "合格");
}else{
Fail_Alarm(); //测试失败提示
LCD12864_Write_Str(3, 4, "不合格");
}
}
|