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

📄 eos.c

📁 单片机程序代码,经过很详细的测试.呵呵,硬件相关.
💻 C
字号:
#include <reg54.h>
#include <stdio.h>
#include "se0121.h"
#include "cmd_para_save.h"

extern unsigned long int xdata commandid;                              //表示命令代码的变量
extern void SetResRdyTbl(unsigned char prio) large reentrant;
extern unsigned char se0121_reg_rd(unsigned char Laddr,unsigned char slot);
extern void se0121_reg_wr(unsigned char Laddr,unsigned char value,unsigned char slot);
extern unsigned char xdata tx_buf[];
extern unsigned char xdata tx_buf_pointer;
extern bit tx_done;

unsigned char xdata EOS_address_value = 0;

unsigned char reset_EOS(struct cmd_para_save *reset_EOS){
//C90软件复位EOS
unsigned char xdata board;
unsigned char xdata value;
unsigned char xdata return_value;

	commandid = 0x00433930;
	board = reset_EOS -> reset_EOS_board;
	value = reset_EOS -> reset_EOS_value;

	if (value == 0)
	{
		value = se0121_reg_rd(Eos_cortrol,board);
		value |= 0x80;
		se0121_reg_wr(Eos_cortrol,value,board);			//先复位EOS盘的SDH接口部分
		value &= 0x7F;
		se0121_reg_wr(Eos_cortrol,value,board);			//再恢复正常
		return_value = 0;
	}
	else if (value == 1)
	{
		value = se0121_reg_rd(E_cortrol,board);
		value |= 0x80;
		se0121_reg_wr(E_cortrol,value,board);			//先复位EOS盘的以太网接口部分
		value &= 0x7F;
		se0121_reg_wr(E_cortrol,value,board);			//再恢复正常
		return_value = 0;
	}
	else return_value = 2;

	SetResRdyTbl(1);
	return(return_value);
}


unsigned char set_EOS_address(struct cmd_para_save *set_EOS_address){
//C91设置发送接收端地址
unsigned char xdata board;
unsigned char xdata type;
unsigned char xdata value;
unsigned char xdata return_value;

	commandid = 0x00433931;
	board = set_EOS_address -> set_address_board;
	type  = set_EOS_address -> set_address_type;
	value = set_EOS_address -> set_address_value;

	value &= 0x1F;
	if (type == 0)
	{
		se0121_reg_wr(CA_send,value,board);
		return_value = 0;
	}
	else if (type == 1)
	{
		se0121_reg_wr(CA_recv,value,board);
		return_value = 0;
	}
	else return_value = 2;

	SetResRdyTbl(1);
	return(return_value);
}


unsigned char get_EOS_address(struct cmd_para_save *get_EOS_address){
//C92读取发送接收端地址
unsigned char xdata board;
unsigned char xdata type;
unsigned char xdata return_value;

	commandid = 0x00433931;
	board = get_EOS_address -> get_address_board;
	type  = get_EOS_address -> get_address_type;

	if (type == 0)
	{
		EOS_address_value = se0121_reg_rd(CA_send,board);
		return_value = 0;
	}
	else if (type == 1)
	{
		EOS_address_value = se0121_reg_rd(CA_recv,board);
		return_value = 0;
	}
	else
	{
		EOS_address_value = 0;
		return_value = 2;
	}

	SetResRdyTbl(33);
	return(return_value);
}

void report_EOS_address(unsigned char value){
//C92回应函数
unsigned char xdata temp;

    tx_buf[0] = '$';
	tx_buf[1] = '2';
	tx_buf[2] = '1';
	tx_buf[3] = 0x43;
	tx_buf[4] = 0x39;
	tx_buf[5] = 0x32;
	tx_buf[6] = '0';
	tx_buf[7] = '0';
	tx_buf[8] = '0';
	tx_buf[9] = '3';
	tx_buf[10] = value + 0x30;
	temp = EOS_address_value >> 4;
	if (temp > 9)
		tx_buf[11] = temp + 0x37;
	else tx_buf[11] = temp + 0x30;
	temp = EOS_address_value & 0x0F;
	if (temp > 9)
		tx_buf[12] = temp + 0x37;
	else tx_buf[12] = temp + 0x30;
	tx_buf[13] = '*';
	tx_buf_pointer = 0;	
	while(tx_buf[tx_buf_pointer] != '*'){
		SBUF = tx_buf[tx_buf_pointer];
		while(tx_done == 0);
		tx_done = 0;
		tx_buf_pointer++;
	}
	SBUF = tx_buf[tx_buf_pointer];          //发送最后一个字符'*'
	while(tx_done == 0);
	tx_done = 0;
}

unsigned char set_search_location(struct cmd_para_save *set_EOS_search){
//C93设置监控点
unsigned char xdata board;
unsigned char xdata type;
unsigned char xdata value;
unsigned char xdata return_value;

	commandid = 0x00433933;
	board = set_EOS_search -> set_search_board;
	type  = set_EOS_search -> set_search_locate;

	if (type == 0)
	{
		value = se0121_reg_rd(E_cortrol,board);
		value &= 0xF7;
		se0121_reg_wr(E_cortrol,value,board);
		return_value = 0;
	}
	else if (type == 1)
	{
		value = se0121_reg_rd(E_cortrol,board);
		value |= 0x08;
		se0121_reg_wr(E_cortrol,value,board);
		return_value = 0;
	}
	else return_value = 2;

	SetResRdyTbl(1);
	return(return_value);
}

unsigned char get_search_location(struct cmd_para_save *get_EOS_search){
//C94读取监控点
unsigned char xdata board;
unsigned char xdata value;
unsigned char xdata return_value;

	board = get_EOS_search -> get_search_board;

	value = se0121_reg_rd(E_cortrol,board);
	value &= 0x08;
	if (value == 0)
	{
		return_value = 0;
	}
	else if (value == 0x08)
	{
		return_value = 1;
	}
	else return_value = 2;

	SetResRdyTbl(35);
	return(return_value);
}

void report_search_location(unsigned char value){
//C94回应函数
    tx_buf[0] = '$';
	tx_buf[1] = '2';
	tx_buf[2] = '1';
	tx_buf[3] = 0x43;
	tx_buf[4] = 0x39;
	tx_buf[5] = 0x34;
	tx_buf[6] = '0';
	tx_buf[7] = '0';
	tx_buf[8] = '0';
	tx_buf[9] = '2';
	if (value < 2)
		tx_buf[10] = '0';
	else tx_buf[10] = '2';
	tx_buf[11] = value + 0x30;
	tx_buf[12] = '*';
	tx_buf_pointer = 0;	
	while(tx_buf[tx_buf_pointer] != '*'){
		SBUF = tx_buf[tx_buf_pointer];
		while(tx_done == 0);
		tx_done = 0;
		tx_buf_pointer++;
	}
	SBUF = tx_buf[tx_buf_pointer];          //发送最后一个字符'*'
	while(tx_done == 0);
	tx_done = 0;
}


unsigned char set_EOS_work_state(struct cmd_para_save *set_EOS_work){
//C95设置EOS盘工作方式
unsigned char xdata board;
unsigned char xdata type;
unsigned char xdata value;
unsigned char xdata return_value;

	commandid = 0x00433935;
	board = set_EOS_work -> set_work_state_board;
	type  = set_EOS_work -> set_work_state_value;

	if (type == 0)
	{
		value = se0121_reg_rd(E_cortrol,board);
		value &= 0xFB;
		se0121_reg_wr(E_cortrol,value,board);
		return_value = 0;
	}
	else if (type == 1)
	{
		value = se0121_reg_rd(E_cortrol,board);
		value |= 0x04;
		se0121_reg_wr(E_cortrol,value,board);
		return_value = 0;
	}
	else return_value = 2;

	SetResRdyTbl(1);
	return(return_value);
}

unsigned char get_EOS_work_state(struct cmd_para_save *get_EOS_work){
//C96读取EOS盘工作方式
unsigned char xdata board;
unsigned char xdata value;
unsigned char xdata return_value;

	board = get_EOS_work -> get_work_state_board;

	value = se0121_reg_rd(E_cortrol,board);
	value &= 0x04;
	if (value == 0)
	{
		return_value = 0;
	}
	else return_value = 1;

	SetResRdyTbl(37);
	return(return_value);
}

void report_EOS_work_state(unsigned char value){
//C96回应函数
    tx_buf[0] = '$';
	tx_buf[1] = '2';
	tx_buf[2] = '1';
	tx_buf[3] = 0x43;
	tx_buf[4] = 0x39;
	tx_buf[5] = 0x36;
	tx_buf[6] = '0';
	tx_buf[7] = '0';
	tx_buf[8] = '0';
	tx_buf[9] = '2';
	tx_buf[10] = '0';
	tx_buf[11] = value + 0x30;
	tx_buf[12] = '*';
	tx_buf_pointer = 0;	
	while(tx_buf[tx_buf_pointer] != '*'){
		SBUF = tx_buf[tx_buf_pointer];
		while(tx_done == 0);
		tx_done = 0;
		tx_buf_pointer++;
	}
	SBUF = tx_buf[tx_buf_pointer];          //发送最后一个字符'*'
	while(tx_done == 0);
	tx_done = 0;
}

unsigned char set_timeslot_num(struct cmd_para_save *timeslot_num){
//C97设置EOS盘的时隙个数
unsigned char xdata board;
unsigned char xdata num;
unsigned char xdata value;
unsigned char xdata return_value;

	commandid = 0x00433937;
	board = timeslot_num -> set_EOS_num_board;
	num = timeslot_num -> set_EOS_num_value;

	if (num < 6)
	{
		value = se0121_reg_rd(Eos_clock,board);		//取出EOS盘时隙个数寄存器值
		value = (value & 0xC7) | (num << 3);		//使配值时隙个数寄存器的bit位为零后再配置
		se0121_reg_wr(Eos_clock,value,board);
		return_value = 0;
	}
	else return_value = 2;

	SetResRdyTbl(1);
	return (return_value);
}

unsigned char get_timeslot_num(struct cmd_para_save *timeslot_num){
//C98读取EOS盘的时隙个数
unsigned char xdata board;
unsigned char xdata num;
unsigned char xdata value;

	board = timeslot_num -> get_EOS_num_board;

	value = se0121_reg_rd(Eos_clock,board);		//取出EOS盘时隙个数寄存器值
	num = (value & 0x38) >> 3;

	SetResRdyTbl(39);
	return (num);
}

void report_EOS_num(unsigned char time_num){
//C98回应函数
    tx_buf[0] = '$';
	tx_buf[1] = '2';
	tx_buf[2] = '1';
	tx_buf[3] = 0x43;
	tx_buf[4] = 0x39;
	tx_buf[5] = 0x38;
	tx_buf[6] = '0';
	tx_buf[7] = '0';
	tx_buf[8] = '0';
	tx_buf[9] = '2';
	tx_buf[10] = '0';
	tx_buf[11] = time_num + 0x30;
	tx_buf[12] = '*';
	tx_buf_pointer = 0;	
	while(tx_buf[tx_buf_pointer] != '*'){
		SBUF = tx_buf[tx_buf_pointer];
		while(tx_done == 0);
		tx_done = 0;
		tx_buf_pointer++;
	}
	SBUF = tx_buf[tx_buf_pointer];          //发送最后一个字符'*'
	while(tx_done == 0);
	tx_done = 0;
}

⌨️ 快捷键说明

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