trf3765寄存器问题
#include "trf3765.h"
#include <msp430x14x.h>
#include <intrinsics.h>
#include "uart0.h"
//////////////////////////////////////
//#define trf_latch_h P4OUT |= BIT1引脚定义
//#define trf_latch_l P4OUT |= ~BIT1
//#define trf_data_h P4OUT |= BIT3
//#define trf_data_l P4OUT |= ~BIT3
//#define trf_clock_h P4OUT |= BIT2
//#define trf_clock_l P4OUT |= ~BIT2
uchar i,j,num=0,num1=0;
//////////////////////////////////////////////////////////////////////////////
uchar trf_instruction[4]={0x00,0x00,0x00,0x00};
////////////////////////////////////////////////////////////////////////
uchar trf_reg1[4]={0x89,0x01,0x50,0x41};
uchar trf_reg2[4]={0x0A,0x5A,0x00,0x88};
uchar trf_reg3[4]={0x0B,0x00,0x00,0x00};
uchar trf_reg4[4]={0x0C,0xE0,0x00,0x0A};
uchar trf_reg5[4]={0x1D,0xA6,0x96,0x8D};
uchar trf_reg6[4]={0x0E,0x20,0x89,0xD5};
uchar trf_reg0[4]={0x0A,0x00,0x00,0x90};
void trfwrite_byte(void)
{
trf_clock_l;
__no_operation();__no_operation();
trf_latch_l;
__no_operation();__no_operation();
trf_latch_h;
__no_operation();__no_operation();__no_operation();__no_operation();
for(i=0;i<4;i++)
{
num=trf_instruction[i];
for(j=0;j<8;j++)
{
if(num&0x01)trf_data_h;
else trf_data_l;
__no_operation();__no_operation();
trf_latch_l;
__no_operation();__no_operation();
trf_clock_h;
__no_operation();__no_operation();
trf_clock_l;
__no_operation();__no_operation();
num>>=1;
}
}
trf_latch_h;
__no_operation();__no_operation();__no_operation();__no_operation();
trf_latch_l;
__no_operation();__no_operation();
}
void trf_config(void)
{
P4DIR = 0XFF;P4OUT = 0XFF;
for(i=0;i<4;i++)
{
trf_instruction[i]=trf_reg1[i];
}
trfwrite_byte();
for(i=0;i<4;i++)
{
trf_instruction[i]=trf_reg2[i];
}
trfwrite_byte();
for(i=0;i<4;i++)
{
trf_instruction[i]=trf_reg3[i];
}
trfwrite_byte();
for(i=0;i<4;i++)
{
trf_instruction[i]=trf_reg4[i];
}
trfwrite_byte();
for(i=0;i<4;i++)
{
trf_instruction[i]=trf_reg5[i];
}
trfwrite_byte();
for(i=0;i<4;i++)
{
trf_instruction[i]=trf_reg6[i];
}
trfwrite_byte();
}
void trfread()
{
trf_clock_l;
__no_operation();__no_operation();
trf_latch_l;
__no_operation();__no_operation();
//trf_latch_h;
__no_operation();__no_operation();__no_operation();__no_operation();
P4DIR = 0XFF;P4OUT = 0XFF;
for(i=0;i<4;i++)
{
num=trf_reg0[i];
for(j=0;j<8;j++)
{
if(num&0x01)trf_data_h;
else trf_data_l;
__no_operation();__no_operation();
trf_latch_l;
__no_operation();__no_operation();
trf_clock_h;
__no_operation();__no_operation();
trf_clock_l;
__no_operation();__no_operation();
num>>=1;
}
}
trf_latch_h;
__no_operation();__no_operation();__no_operation();__no_operation();
trf_clock_h;
__no_operation();__no_operation();
trf_clock_l;
__no_operation();__no_operation();
trf_latch_l;
__no_operation();__no_operation();
P4DIR = 0XF7;
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
num1<<=1;
trf_clock_h;
__no_operation();__no_operation();
trf_clock_l;
__no_operation();__no_operation();
if(P2IN&BIT3)
num1=num1|0x01;
}
Send1Char(num1);
}
}
我这里寄存器数据读出的数据是错的,是软件问题还是硬件问题呢?
谢谢你的函数代码, 要判断是软件问题还是硬件问题,需要用示波器看时序.
请把时序抓来看, 你写的是多少,读出来长什么样?