?? ade7758.c
字號:
/**************************************************
ade7758 sub
***************************************************/
#include "reg52.h"
#include "ade7758.h"
sbit MISO=P1^1;
sbit SCK=P1^2;
sbit MOSI=P1^3;
sbit CS=P1^4;
sbit IRQ=P3^2;
void SpiSentByte(uchar bb)
{
uchar i;
for(i=0;i<8;i++){
SCK=1;
if((CC&0x80)==0) MOSI=0;
else MOSI=1;
bb<<=1;
SCK=0;
}
SCK=1;
}
uchar SpiReceiveByte(void)
{
uchar i,bb=0;
for(i=0;i<8;i++){
SCK=1;
bb>>=1;
MISO=1;
if (MISO==1) bb|=0x01;
SCK=0;
}
SCK=1;
return bb;
}
void Enable7758(void)
{
EX0=0;
EX1=0;
CS=0;
SCK=1;
IRQ=1;
CS=0;
}
void Disable7758(void)
{
CS=1;
SCK=1;
IRQ=1;
CS=1;
EX0=1;
EX1=1;
}
void Read7758(uchar addr,uchar idata *pnt,uchar cnt)
{
uchar i;
SpiSentByte(addr);
for(i=0;i<cnt;i++) *pnt++=SpiReceiveByte();
}
void Write7758(uchar addr,uchar idata *pnt,uchar cnt)
{
uchar i;
SpiSentByte(addr|0x80);
for(i=0;i<cnt;i++) SpiSentByte(*pnt++);
}
void Init7758(void)
{
uchar i;
SpiSentByte(OPMODE|0x80);
SpiSentByte(0x40);
for(i=0;i<20;i++);
SpiSentByte(OPMODE|0x80);
SpiSentByte(0x00);
SpiSentByte(MMODE|0x80);
SpiSentByte(0x00);
SpiSentByte(GAIN|0x80);
SpiSentByte(0x00);
SpiSentByte(WAVMODE|0x80);
SpiSentByte(0x00);
SpiSentByte(COMPMODE|0x80);
SpiSentByte(0x9c);
SpiSentByte(LCYCMODE|0x80);
SpiSentByte(0x78);
SpiSentByte(MASK|0x80);
SpiSentByte(0x00);
SpiSentByte(0x0e);
SpiSentByte(0x00);
SpiSentByte(WDIV|0x80);
SpiSentByte(0x08);
SpiSentByte(VARDIV|0x80);
SpiSentByte(0x08);
SpiSentByte(VADIV|0x80);
SpiSentByte(0x00);
SpiSentByte(APCFNUM|0x80);
SpiSentByte(0x78);
SpiSentByte(MASK|0x80);
SpiSentByte(0x00);
SpiSentByte(0x0e);
SpiSentByte(0x00);
SpiSentByte(WDIV|0x80);
SpiSentByte(0x08);
SpiSentByte(VARDIV|0x80);
SpiSentByte(0x08);
SpiSentByte(VADIV|0x80);
SpiSentByte(0x00);
SpiSentByte(APCFNUM|0x80);
SpiSentByte(0x78);
SpiSentByte(MASK|0x80);
SpiSentByte(0x00);
SpiSentByte(0x0e);
SpiSentByte(0x00);
SpiSentByte(WDIV|0x80);
SpiSentByte(0x08);
SpiSentByte(VARDIV|0x80);
SpiSentByte(0x08);
SpiSentByte(VADIV|0x80);
SpiSentByte(0x00);
SpiSentByte(APCFNUM|0x80);
SpiSentByte(0x00);
SpiSentByte(0x00);
SpiSentByte(APCFDEN|0x80);
SpiSentByte(0xff);
SpiSentByte(0xff);
SpiSentByte(VARCFNUM|0x80);
SpiSentByte(0x00);
SpiSentByte(0x00);
SpiSentByte(VARCFDEN|0x80);
SpiSentByte(0xff);
SpiSentByte(0xff);
for(i=0;i<30;i++){
IdAdr((i+0x24),0xff);
ReadFm24c16(0x01,E2_adr,buf,E2_cnt);
Write7758((i+0x24),buf,E2_cnt);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -