📄 lc72131.c
字号:
#include <reg52.h>
#include <absacc.h>
#include <intrins.h>
#include "baCommon.h"
#include "resource.h"
#include "lc72131.h"
void outByte(U8 b)
{
U8 i;
for(i=8;i>0;i--)
{
PIN_lc72131_clk=0;
PIN_lc72131_di=(b&0x80);
b=(b<<1);
PIN_lc72131_clk=1;
}
}
U8 inByte()
{
U8 i,b=0;
U8 x=0x80;
for(i=8;i>0;i--)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
PIN_lc72131_clk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
PIN_lc72131_clk=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
PIN_lc72131_clk=1;
PIN_lc72131_do=1;
if(PIN_lc72131_do)
b|=x;
x>>=1;
}
return b;
}
void sendMode1(U8 loByte, U8 hiByte, U8 mode)
{
PIN_lc72131_ce=0;
outByte(PLL_IN1);
PIN_lc72131_ce=1;
outByte(loByte);
outByte(hiByte);
//outByte(PLL_IN1_FMIN|PLL_IN1_CTERESET|PLL_IN1_XS72M|PLL_IN1_RF25K1);
outByte(mode);
}
void sendMode2(U8 b)
{
PIN_lc72131_ce=0;
outByte(PLL_IN2);
PIN_lc72131_ce=1;
outByte(b);
outByte(0xAC);
outByte(0xC8);
PIN_lc72131_ce=0;
}
#if 1
U32 PLLReadData()
{
union{
U32 count;
struct{
U8 a[4];
}a;
}ifcount;
PIN_lc72131_ce=0;
outByte(PLL_OUT);
PIN_lc72131_ce=1;
_nop_();
_nop_();
ifcount.count=0;
ifcount.a.a[0]=0;
ifcount.a.a[1]=inByte();
ifcount.a.a[2]=inByte();
ifcount.a.a[3]=inByte();
PIN_lc72131_ce=0;
/* again */
PIN_lc72131_ce=0;
outByte(PLL_OUT);
PIN_lc72131_ce=1;
_nop_();
_nop_();
ifcount.count=0;
ifcount.a.a[0]=0;
ifcount.a.a[1]=inByte();
ifcount.a.a[2]=inByte();
ifcount.a.a[3]=inByte();
PIN_lc72131_ce=0;
return(ifcount.count&0x000fffff);
}
#endif
void PLLSetStation(U8 band, U8 f1, U8 f2, U8 mode, bit mute)
{
band=band;
sendMode1(f1,f2,mode);
if(!mute)
sendMode2(0x51);
else
sendMode2(0x50);
}
#if 0
U32 PLLStepSearch(bit direction, U16 freq)
{
UNUSED(direction);
UNUSED(freq);
return 0;
}
#endif
/* */
U16 dataReverse(U16 x)
{
U16 b;
U8 a;
for(a=0;a<16;a++)
{
b=(x&0x0001)?((b<<1)+1):(b<<1);
x=x>>1;
}
return(b);
}
#if 0
void main(void)
{
U32 ret;
PIN_tuner_switch=0;
while(1)
{
PIN_lc72131_ce=0;
outByte(PLL_IN1);
PIN_lc72131_ce=1;
outByte(0xE1);
outByte(0x10);
outByte(0xD4);
PIN_lc72131_ce=0;
outByte(PLL_IN2);
PIN_lc72131_ce=1;
outByte(0x50);
outByte(0xac);
outByte(0xc8);
PIN_lc72131_ce=0;
ret=PLLReadData();
PIN_lc72131_ce=0;
outByte(PLL_IN1);
PIN_lc72131_ce=1;
outByte(0xE1);
outByte(0x10);
outByte(0xF4);
PIN_lc72131_ce=0;
outByte(PLL_IN2);
PIN_lc72131_ce=1;
outByte(0x50);
outByte(0xac);
outByte(0xc8);
PIN_lc72131_ce=0;
ret=PLLReadData();
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -