帶時鐘恢複的曼徹斯特解碼:
CL_DAT 為曼徹斯特的時鐘,在時鐘的上升沿對應穩定的資料。
檢測CL_DAT 的上升沿, 讀取DAT資料。
讀取一個位元組資料:
for(i = 0;i < 8;i ++) //接收一個位元組
{
count = 0;
while(!CL_DAT()) //CL_DAT低電平,等待高電平跳出while循環
{
count ++; //等待計時
Delay_US(1);
if(count > 1000) //等待逾時 1ms
break;
}
LF_DataBuff[0] = LF_DataBuff[0] << 1; // DAT資料腳預設指派0
if(DAT())
LF_DataBuff[0] = LF_DataBuff[0] | 0x01; //檢測讀取DAT腳資料, 若為高,數值賦1
count = 0;
while(CL_DAT()) //CL_DAT高電平,等待低電平跳出while循環
{
count ++;
Delay_US(1);
if(count > 1000) //等待逾時 1ms
break;
}
}