📄 si470x_low.c
字号:
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f320.h>
#include <stddef.h>
#include "typedefs.h"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#define READ 1
#define WRITE 0
#define IO3W 0
#define IO2W 1
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
sbit RSTB = P1^3;
sbit SENB = P1^2;
sbit SCLK = P1^1;
sbit SDIO = P0^7;
u16 xdata si470x_shadow[16];
u8 io_mode = IO2W;
//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
void io2w_write (u8 lastreg, u16 *reg_array);
void io2w_read (u8 lastreg, u16 *reg_array);
void io3w_write (u8 firstreg, u8 lastreg, u16 *reg_array);
void io3w_read (u8 firstreg, u8 lastreg, u16 *reg_array);
void wait_ns(u16 ns);
void _nop_(void);
//-----------------------------------------------------------------------------
// Externals
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void si470x_reset (void)
{
// default conditions
SCLK = 1;
P0MDOUT = P0MDOUT | 0x80; // Configure P0^7(SDIO) as push-pull
SENB = (io_mode == IO2W) ? 1 : 0; // 0 = 3-wire, 1 = 2-wire
SDIO = 0;
// initialization
RSTB = 0;
wait_ns(30); // tSRST
RSTB = 1;
wait_ns(30); // tHRST
// default conditions
SENB = 1;
P0MDOUT &= ~(0x80); // Configure P0^7(SDIO) as open-drain
SDIO = 1; // Configure P0^7(SDIO) as a digital input
}
//-----------------------------------------------------------------------------
// Put the Si470x in powerdown mode. Set the disable bit in register 2, but
// bypass the shadow registers. This makes it easier to restore register 2
// during powerup.
//
//-----------------------------------------------------------------------------
void si470x_powerdown (void) {
u16 powerdown_val[3] = {0, 0, 0x0041}; // DISABLE = 1, ENABLE = 1
if (io_mode == IO3W) {
io3w_write(2, 2, powerdown_val);
} else {
io2w_write(2, powerdown_val);
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void si470x_reg_read (u8 firstreg, u8 lastreg)
{
if (io_mode == IO3W) {
io3w_read(firstreg, lastreg, si470x_shadow);
} else {
io2w_read(lastreg, si470x_shadow);
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void si470x_reg_write (u8 firstreg, u8 lastreg)
{
if (io_mode == IO3W) {
io3w_write(firstreg, lastreg, si470x_shadow);
} else {
io2w_write(lastreg, si470x_shadow);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -