Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15490576
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类:

2007-05-17 15:53:22

无绳电话PLL控制芯片MC145162驱动源码at91rm9200(作者:gliethttp

1MC145162.c源码文件

//****

#include

//---

uint8   MCControlR;

uint16 MC14bitsAuxCount;

uint16 MC12bitsRefCount;

uint16 MCTxCount;

uint16 MCRxCount;

uint32 MC32bitsBuf;

#define MC145162_DEBUG_OUT 1

//---

//MC145162初始化

void MC145162_Mod_Setup(void);

void MC145162_Mod_Reference(void);

void MC145162_Tx_Rx_Counter(void);

void MC145162_ini(void)

{

MCControlR          = 0x88;

MC14bitsAuxCount    = 10240;

MCTxCount           = 39983;

MCRxCount           = 45180;

MC145162_Pin_Install();

MC145162_Mod_Setup();

MC145162_Mod_Reference();

MC145162_Tx_Rx_Counter();

}

//---

//发送control命令集

void MC145162_SendData(uint32 data,uint8 bits,uint8 mod);

void MC145162_Mod_Setup(void)

{

#define MC145162_TEST_BIT_OUTPUT 1

MC32bitsBuf = MCControlR | 0x80;

#if MC145162_TEST_BIT_OUTPUT

MC32bitsBuf |= 0x20;

#endif

MC32bitsBuf <<= 24;

MC145162_Pin_Enb(1);

MC145162_SendData(MC32bitsBuf,8,false);

MC145162_Pin_Enb(0);

}

//---

//发送reference命令集

void MC145162_Mod_Reference(void)

{

if(MC14bitsAuxCount > 16383)MC14bitsAuxCount = 16383;

if(MC12bitsRefCount >  4095)MC12bitsRefCount  = 4095;

if(MC14bitsAuxCount <     16)MC14bitsAuxCount = 16;

if(MC12bitsRefCount <     16)MC12bitsRefCount = 16;

#if MC145162_DEBUG_OUT

{static char data[50];

sprintf(data,"MCA=%d\r\n",MC14bitsAuxCount);

dprintf(data);

}

#endif

#define MC145162_Mod_Reference_Bit_AUX (0x01                << 30)

#define MC145162_Mod_Reference_Bit_Tx0 (0x00                << 29)

#define MC145162_Mod_Reference_Bit_Rx0 (0x00                << 28)

#define MC145162_Mod_Reference_12B_REF (MC12bitsRefCount    << 16)

#define MC145162_Mod_Reference_Bit_RS1 (0x00                << 15)

#define MC145162_Mod_Reference_Bit_RS2 (0x00                << 14)

#define MC145162_Mod_Reference_Bit_AUXD(MC14bitsAuxCount    <<  0)

MC32bitsBuf =   MC145162_Mod_Reference_Bit_AUX |

MC145162_Mod_Reference_Bit_Tx0 |

MC145162_Mod_Reference_Bit_Rx0 |

MC145162_Mod_Reference_12B_REF |

MC145162_Mod_Reference_Bit_RS1 |

MC145162_Mod_Reference_Bit_RS2 |

MC145162_Mod_Reference_Bit_AUXD;

MC145162_Pin_Enb(1);

MC145162_SendData(MC32bitsBuf,32,false);

MC145162_Pin_Enb(0);

}

//---

//发送counter分频命令集

void MC145162_Tx_Rx_Counter(void)

{

if(MCTxCount < 16)MCTxCount = 16;

if(MCRxCount < 16)MCRxCount = 16;

MC32bitsBuf = (MCTxCount << 16) | MCRxCount;

#if MC145162_DEBUG_OUT

{static char data[50];

sprintf(data,"MCTxCount=%d\r\nMCRxCount=%d\r\n" ,MCTxCount,MCRxCount);

dprintf(data);

}

#endif

MC145162_Pin_Enb(0);

MC145162_SendData(MC32bitsBuf,32,true);

}

//---

//数据发送子函数

void MC145162_SendData(uint32 data,uint8 bits,uint8 mod)

{uint8 i;

if(bits)bits--;

for(i = 0;i < bits;i++)

{

MC145162_Pin_Din(data&0x80000000);

MC145162_Pin_Clk(1)

MC145162_Pin_Clk(0);

Data <<= 1;

}

MC145162_Pin_Din(data&0x80000000);

MC145162_Pin_Clk(1)

if(mod){MC145162_Pin_Enb(1);}

MC145162_Pin_Clk(0);

if(mod){MC145162_Pin_Enb(0);}

}

 

2MC145162.h源码文件

#include

/*

MC14bitsAuxCount    : 16 ~ 16383

MC12bitsRefCount    : 16 ~ 4095

MCTxCount           : 16 ~ 65535

MCRxCount           : 16 ~ 65535

*/

#define MC145162_BASE_PIO               AT

阅读(1638) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~