我自己写了一个基于pic单片机的TDA5150的无线发送程序,tda5150网上找不到参考程序,都是自己瞎摸索,用示波器测量时钟引脚和数据输入输出引脚都有波形,但是用频谱分析仪去观测有没有射频信号发送出来,就一直观测不到波形,麻烦用过TDA5150的高手帮我看看程序哪儿有问题。
#include "pic18F25K80.h"
#include "delays.h"
#pragma config CONFIG1L=0x10
#pragma config FOSC =HS1,IESO=0,PLLCFG=0
#pragma config WDTEN =OFF
#pragma config MCLRE=1
#pragma config WRTC=0
#pragma config STVREN=0
#pragma config CP0=0,CP1=0,CP2=0,CP3=0
#pragma config XINST=OFF
void Delay10TCYx(unsigned char);
#define HF_SCK LATCbits.LATC1
#define HF_SDIO LATCbits.LATC2
#define HF_CS LATCbits.LATC0
#define SPICHKSUN 0x00
#define TXCFG0 0x04
#define TXSTAT 0x01
#define TXCFG1 0x25
#define POWCFG0 0x1A
#define POWCFG1 0x1B
#define PLLINTA 0x09
#define PLLFRACA0 0x0A
#define PLLFRACA1 0x0B
#define PLLFRACA2 0x0C
#define BDRDIV 0x07
#define SLOPEDIV 0x19
#define FDEV 0x1C
#define GFDIV 0x1D
#define GFXOSC 0x1E
#define ANTTDCC 0x1F
#define VAC0 0x21
#define VAC1 0x22
#define CPCFG 0x24
#define PLLBW 0x25
#define ENCCNT 0x27
//#define TX_ADR_WIDTH 5 // 5 uints TX address width
//#define RX_ADR_WIDTH 5 // 5 uints RX address width
#define TX_PLOAD_WIDTH 24
unsigned char Tx_buf[4];
//unsigned char TX_ADDRESS[TX_ADR_WIDTH]= {0xe7,0xe7,0xe7,0xe7,0xe7};
//unsigned char RX_ADDRESS[RX_ADR_WIDTH]= {0xaa,0xbb,0xcc,0xdd,0xee};
void TDA5150PORT_Init(void);
void TDA5150_Init(void);
void TDA5150_write_spi_1_byte(unsigned char temp);
unsigned char TDA5150_RcvByte(void);
void TDA5150_WriteRegsiter_cmd(unsigned char reg,unsigned char value);
void TDA5150_ReadRegsiter(unsigned char reg,unsigned char *value);
void TDA5150_Transmit(unsigned char Data);
void TDA5150PORT_Init(void)
{
TRISCbits.TRISC3=0;
LATCbits.LATC3=1;
TRISCbits.TRISC0=0;
TRISCbits.TRISC1=0;
}
void TDA5150_Init(void)
{
// HF_CS=1;
// TDA5150_WriteRegsiter_cmd(0x00,0x00);
TDA5150_WriteRegsiter_cmd(0x04,0x0e);
TDA5150_WriteRegsiter_cmd(0x01,0x07);
TDA5150_WriteRegsiter_cmd(0x05,0x17);
TDA5150_WriteRegsiter_cmd(0x06,0x07);
TDA5150_WriteRegsiter_cmd(0x09,0x18);
TDA5150_WriteRegsiter_cmd(0x0A,0x75);
TDA5150_WriteRegsiter_cmd(0x0B,0x62);
TDA5150_WriteRegsiter_cmd(0x0C,0x07);
TDA5150_WriteRegsiter_cmd(0x07,0xca);
TDA5150_WriteRegsiter_cmd(0x08,0xab);
TDA5150_WriteRegsiter_cmd(0x19,0xff);
TDA5150_WriteRegsiter_cmd(0x1A,0xff);
TDA5150_WriteRegsiter_cmd(0x1B,0xbb);
TDA5150_WriteRegsiter_cmd(0x1C,0xd9);
TDA5150_WriteRegsiter_cmd(0x1D,0x08);
TDA5150_WriteRegsiter_cmd(0x1E,0x78);
TDA5150_WriteRegsiter_cmd(0x1F,0x20);
TDA5150_WriteRegsiter_cmd(0x21,0xc8);
TDA5150_WriteRegsiter_cmd(0x20,0x4c);
TDA5150_WriteRegsiter_cmd(0x22,0x40);
TDA5150_WriteRegsiter_cmd(0x23,0x00);
TDA5150_WriteRegsiter_cmd(0x24,0x2f);
TDA5150_WriteRegsiter_cmd(0x25,0x88);
TDA5150_WriteRegsiter_cmd(0x25,0xc0);
TDA5150_WriteRegsiter_cmd(0x27,0x00);
// HF_CS=0;
}
void TDA5150_write_spi_1_byte(unsigned char temp)
{
unsigned char m;
// HF_CS=0;
TRISCbits.TRISC2=0;
// HF_CS=1;
for(m=0;m<8;m++)
{
if((temp<<m)&0x80)
HF_SDIO=1;
else
HF_SDIO=0;
HF_SCK=1;
// temp=(temp<<1);
Delay10TCYx(40);//10us
HF_SCK=0; //??????????
Delay10TCYx(40);//10us
}
}
unsigned char TDA5150_RcvByte(void)
{
unsigned char status=0;
unsigned int i;
TRISCbits.TRISC2=1;
for(i=0;i<8;i++)
{
status<<=1;
HF_SCK=0;
Delay10TCYx(30);//10us
// __delay_cycles(50);//10us
if(1==HF_SDIO )
status |= 0x01;
else
status &= ~0x01;
HF_SCK=1;
Delay10TCYx(30);//10us
// __delay_cycles(50);//10us
}
return(status);
}
void TDA5150_WriteRegsiter_cmd(unsigned char reg,unsigned char value)
{
unsigned char outbuf[3];
unsigned char i;
outbuf[0] = reg & 0x3F; //write mode
// outbuf[1]=reg;
outbuf[1]=value;
HF_CS=1;
HF_SCK=1;
for(i=0;i<2;i++)
{
TDA5150_write_spi_1_byte(outbuf[i]);
outbuf[i++];
}
HF_SCK=0;
HF_CS=0;
}
void TDA5150_ReadRegsiter(unsigned char reg,unsigned char *value)
{
unsigned char outbuf[2];
outbuf[0] = 0x40 | (reg & 0x3F); // read mode
// outbuf[1]=reg;
unsigned char rfbuf[2] = {0};
unsigned char j=0;
HF_CS=1;
HF_SCK=0;
TDA5150_write_spi_1_byte(outbuf[0]);
// TDA5150_write_spi_1_byte(outbuf[1]);
for(j=0;j<2;j++)
{
rfbuf[j]=TDA5150_RcvByte();
rfbuf[j++];
}
HF_SCK=1;
HF_CS=0;
*value=rfbuf[0];
}
void TDA5150_Transmit(unsigned char Data)
{
unsigned char outbuf[2];
outbuf[0] = 0xC4;//transmit mode
outbuf[1]=Data;
unsigned int i;
HF_CS=1;
// HF_SCK=1;
Delay10TCYx(50);
TDA5150_write_spi_1_byte(outbuf[0]);
// HF_SCK=0;
Delay10TCYx(50);
// HF_SCK=0;
// TDA5150_ReadRegsiter(0x01,0x07);
TDA5150_write_spi_1_byte(outbuf[1]);
// HF_SCK=1;
Delay10TCYx(50);
HF_CS=0;
}
void main(void)
{
unsigned int i;
TDA5150PORT_Init();
TDA5150_Init();
//TDA5150_write_spi_1_byte(12345678);
// TDA5150_RcvByte();
//TDA5150_WriteRegsiter_cmd(0x05,0x65);
Tx_buf[1]=1;
Tx_buf[2]=2;
Tx_buf[3]=3;
for(i=1;i<4;i++)
{
TDA5150_Transmit(Tx_buf[1]);
}
Delay10TCYx(50);
}
|
|