⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plc.h

📁 此源码为商用的电力抄表系统的主机端源程序。通过电力载波模块
💻 H
字号:
/* //////////////////////////////////////////////////////////////////////////
// PLC.h  - header file for PLC API
// 
// Copyright 2004, Leaguer MicroElectronics Co., Ltd
// www.leaguerme.com
//////////////////////////////////////////////////////////////////////////// */
#define uint unsigned int
#define uchar unsigned char

#define SMOD_ASYNC   1
#define SMOD_SYNC    2


//////////////////////////////////////////////////////////////////////////
// Command for register operations

#define REG_WR_EA			0x32		// Write detection threshold 1
#define REG_RD_EA			0xF2
#define REG_WR_EB			0x36		// Write detection threshold 2
#define REG_RD_EB			0xF6

#define REG_WR_3E			0x3e
#define REG_RD_FE			0xFe

#define REG_WR_3F			0x3f
#define REG_RD_FF			0xFf

#define REG_WR_33			0x33
#define REG_RD_F3			0xF3

#define REG_WR_3c			0x3c
#define REG_RD_Fc			0xFc


#define REG_WR_SYNC_ERR		0x34		// Write sync error tolerance
#define REG_RD_SYNC_ERR		0xF4

#define REG_RD_STATUS		0xF1		// read status reg

#define BUF_RD_LUT			0x80		// 512 bytes
#define BUF_RD_TXBUF		0xA0		// Read tx buffer
#define BUF_RD_RXBUF		0xC0		// Read rx buffer
#define BUF_WR_TXBUF		0x7F		// Write tx buffer
#define BUF_RD_FIR			0x90		// 62 bytes
#define BUF_WR_FIR			0x77		// 62 bytes		

#define CMD_TRANSMIT		0x7E		// Tx start cmd
#define CMD_RESET			0x7D		// Reset the chip
	


///////////////////////////////////////////////////////////////////
// Function prototypes

void send_data(uchar c);  // /Send a single byte
void send_block(uchar block[], uint len); // Send a data block of specified length
void write_reg(uchar op, uchar val); // Write specified register with specified value

// Read specified register. Return -1 if error,
// otherwise, the result is in the lower byte of the returned value
int read_reg(uchar op);
int read_buffer(uchar op, uchar buf[], uint len);

void send_command(uchar cmd);

int set_rate(uchar val);
int get_rate();
int set_mode(uchar val);
int get_mode();

// Set FEC: on = 1 (FEC on) or on = 0 (FEC off)
int set_fec(uint on);

// Set sync auto adjustment, on = 1 or 0
int set_autosync(uint on);

int set_op(uint normal_op);

int set_timing(uchar t1, uchar t2, uchar t3);

int get_timing(uchar t[3]);

int set_thres_sync(uchar val);
int get_thres_sync();

int set_thres_det(uchar val);
int get_thres_det();

int set_carrier(uchar f1, uchar f2, uchar f3, uchar f4);
int get_carrier(uchar f[4]);

int set_scaling(uchar val);
int get_scaling();

int set_agc(uchar agc[8]);
int get_agc(uchar agc[8]);

int read_crc();

int read_rssi(uchar rssi[2]);

int write_txbuffer(uchar buffer[]);

int read_txbuffer(uchar buffer[]);

int read_rxbuffer(uchar buffer[]);

void send();

//////////////////////////////////////////////////////////////////////
// High-level API function

/* this function must be called before using any other api functions.
   smod = SMOD_ASYNC or SMOD_SYNC, must be consistant with the hardware
   smod pin connection.
*/
int plc_init(uint smod);
int plc_config(uchar buf[], uint len);
int plc_send(uchar frame[]);
int plc_resend();
int plc_recved();
int plc_getframe(uchar frame[]);
int plc_reset();
void plc_power_on(void);

void ist_count();

void timeout_t2(void);
void thres_adjust();

void timeout_t4(void);

void w_flsh(uchar dat,uchar dat1);
void Remote_Replies(uchar buf[]);//远程测试应答
void Rx_Command_Reply(uchar comm);//远程控制回复




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -