Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1423235
  • 博文数量: 613
  • 博客积分: 11499
  • 博客等级: 上将
  • 技术积分: 5511
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-12 19:27
  • 认证徽章:
文章分类

全部博文(613)

文章存档

2016年(5)

2015年(18)

2014年(12)

2013年(16)

2012年(300)

2011年(45)

2010年(37)

2009年(79)

2008年(101)

分类: LINUX

2008-04-18 22:53:42




无绳电话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

阅读(999) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册