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

📄 test.c

📁 单片机程序代码,经过很详细的测试.呵呵,硬件相关.
💻 C
📖 第 1 页 / 共 5 页
字号:
				init_recover[1] = 1;
				path_switch_mcbb_tu();
			}
		}
	}

//	judge = int_flg & 0x04;
//	if (judge == 0x04){
	if (f2rc7820_rd(F2Int_reg)){
		f2rc7820_wr(F2Encrypt_reg,0xAA);       //open 7820 write reg
		f2rc7820_wr(F2Intmask_reg,0xFF);
	}

//	judge = int_flg & 0x08;								//取出OTB7860的中断
//	if (judge == 0x08){
	int_reg = f2rc7860_rd(F2Int_vec);
	if (int_reg){
		if (start_flg[0] == 1){
			f2rc7860_wr(F2Reg_protect,0xAA);       //open 7860 write reg protect
			f2rc7860_wr(F2Int_mask,0x80);
		}
		else{
		if (int_reg & 0xF0){
	   		judge = f2rc7860_rd(F2Ia0_a);					//光分支盘A口中断处理
			judge1 = f2rc7860_rd(F2Ia1_a);
			judge2 = f2rc7860_rd(F2Ia2_a);
			judge3 = f2rc7860_rd(F2Ia3_a);
			f2rc7860_wr(F2Rdint_clr,0x40);		//清除OTB盘的F2Ia3_a与F2Ia3_b中断位
			for (temp = 0; temp <= 7; temp++){				//取出63个时隙的AIS寄存器值
				ais_reg[2][temp] |= f2rc7860_rd(temp + 0x00A6);
			}
			if ((judge & 0xDA) | (judge2 & 0xE0) | (judge3 & 0x80)){
				intflg_OTBA = 1;
			}
			if (judge != 0){
				f2rc7860_wr(F2Intmask0_a,judge);
				judge &= 0xD0;					//取出可发生自动倒换的bit位
				if (judge != 0){
//					SetExtRdyTbl(5);
					init_recover[2] = 1;
					path_switch_otba();
				}
			}
			if (judge1 != 0){
				f2rc7860_wr(F2Intmask1_a,judge1);
//				judge1 &= 0xF0;
//				if (judge1 != 0){
//					SetExtRdyTbl(5);
//					path_switch_otba();
//				}
			}
			if (judge2 != 0){
				f2rc7860_wr(F2Intmask2_a,judge2);
				judge2 &= 0xE0;
				if (judge2 != 0){
//					SetExtRdyTbl(5);
					init_recover[2] = 1;
					path_switch_otba();
				}
			}
			if (judge3 != 0){
//				f2rc7860_wr(F2Intmask3_a,judge3);
				judge3 &= 0x80;
				if (judge3 != 0){
					SetExtRdyTbl(6);
					init_recover[2] = 1;
					path_switch_otba_tu();
				}
			}
		}

		if (int_reg & 0x0F){
			judge = f2rc7860_rd(F2Ia0_b);					//光分支盘B口中断处理
			judge1 = f2rc7860_rd(F2Ia1_b);
			judge2 = f2rc7860_rd(F2Ia2_b);
			judge3 = f2rc7860_rd(F2Ia3_b);
			f2rc7860_wr(F2Rdint_clr,0x40);		//清除OTB盘的F2Ia3_a与F2Ia3_b中断位
			for (temp = 0; temp <= 7; temp++){				//取出63个时隙的AIS寄存器值
				ais_reg[3][temp] |= f2rc7860_rd(temp + 0x02A6);
			}
			if ((judge & 0xDA) | (judge2 & 0xE0) | (judge3 & 0x80)){
				intflg_OTBB = 1;
			}
			if (judge != 0){
				f2rc7860_wr(F2Intmask0_b,judge);
				judge &= 0xD0;					//取出可发生自动倒换的bit位
				if (judge != 0){
//					SetExtRdyTbl(7);
					init_recover[3] = 1;
					path_switch_otbb();
				}
			}
			if (judge1 != 0){
				f2rc7860_wr(F2Intmask1_b,judge1);
//				judge1 &= 0xF0;
//				if (judge1 != 0){
//					SetExtRdyTbl(7);
//					path_switch_otbb();
//				}
			}
			if (judge2 != 0){
				f2rc7860_wr(F2Intmask2_b,judge2);
				judge2 &= 0xE0;
				if (judge2 != 0){
//					SetExtRdyTbl(7);
					init_recover[3] = 1;
					path_switch_otbb();
				}
			}
			if (judge3 != 0){
//				f2rc7860_wr(F2Intmask3_b,judge3);
				judge3 &= 0x80;
				if (judge3 != 0){
					SetExtRdyTbl(8);
					init_recover[3] = 1;
					path_switch_otbb_tu();
				}
			}
		}
	}
	}

	SetExtRdyTbl(15);					//每秒查询改写2M盘的AIS速率
	Rdint_clr = 0x40;					//清除MCB盘的Ia3_a与Ia3_b中断位
	f2rc7860_wr(F2Rdint_clr,0x40);		//清除OTB盘的F2Ia3_a与F2Ia3_b中断位

}

/*****************************************************************************/

timer0 () interrupt 1 using 2{
unsigned char xdata btemp;
	TH0 = -46080/256;
	TL0 = -46080%256;
	if (++time3 >= 8){
		time3 = 0;
		P1_0 = ~P1_0;
	}
	time++;
//	if (++time == 20){
//		time = 0;
//		P3_4 =  ~P3_4;
//	}	
	if (++time1 >= 40){
		time1 = 0;
		if (init_temp){
			SetExtRdyTbl(10);							//每秒查询单盘状态
			SetExtRdyTbl(11);							//设置每秒钟收集性能与告警函数事件表
			SetExtRdyTbl(14);							//设置查询通道倒换函数
//			if (!GetExtRdyTbl(15))							//每秒查询改写2M盘的AIS速率
//				SetExtRdyTbl(15);
		}
		if (clkmode_reg == 0){							//每秒查询是否需要进行时钟自动倒换
			btemp = check_alarm_mcb[2] & 0x01;
			if (btemp & clkarray_flg){					//主用时钟源丢失,并且时钟优先级表有设置
				SetExtRdyTbl(12);
			}
			else if (clkarray_flg){						//主用源未丢失,时钟优先级表有设置
				get_clk_prio(clk_source);				//得到主用时钟的优先级
				if (clk_prio >= 1){						//优先级不在最高
					SetExtRdyTbl(13);
				}
			}
		}
		if (clk_check_flg[1] != 0)
		{
			SetExtRdyTbl(17);
		}
		if (min15_flg){									//如果15分钟性能值没有发送完,置位该事件表
			if (!GetResRdyTbl(15))
				SetResRdyTbl(15);
		}
	}
	if (++time2 >= 120){
		time2 = 0;
		if (init_temp)							//设置每3秒钟收集告警函数事件表
			SetExtRdyTbl(16);
	}		
}                       
                        
                        
/*	name:			AsciiToHex(Uchar ascii)
	parameter:		ASCII code
	function:		translate the ASCII code(numbers) to HEX
*/
Uchar AsciiToHex(Uchar ascii){
Uchar xdata hex_num=0;
	if ((ascii>=0x30) && (ascii<=0x39))
		hex_num = ascii-0x30;
	else
		switch(ascii){
			case 0x61:
			case 0x41:hex_num = 0x0A;break;
			case 0x62:
			case 0x42:hex_num = 0x0B;break;
			case 0x63:
			case 0x43:hex_num = 0x0C;break;
			case 0x64:
			case 0x44:hex_num = 0x0D;break;
			case 0x65:
			case 0x45:hex_num = 0x0E;break;
			case 0x66:
			case 0x46:hex_num = 0x0F;break;
			default:hex_num = 0;
		}
	return(hex_num);
}
void serial() interrupt 4 using 3{
Uchar xdata temp=0; 
	if (RI && !rx_buf_overflow[rx_buf_num]){
		temp = SBUF;
		if (temp == '$'){
			rx_buf_pointer[rx_buf_num] = 0;
			rx_buf[rx_buf_num][rx_buf_pointer[rx_buf_num]++] = temp;
			cmd_head[rx_buf_num] = 1;								//mark recieved char '$'
		}
		else if ((temp == '*') && cmd_head[rx_buf_num]){			//avoid recieved '*' but no '$'
			rx_buf[rx_buf_num][rx_buf_pointer[rx_buf_num]] = temp;
			cmd_head[rx_buf_num] = 0;
			save_cmd_enable[rx_buf_num] = 1;						//analysis command and save the para
			cmd_length[rx_buf_num] = rx_buf_pointer[rx_buf_num] - 0xA;
			if (rx_buf_num)
				rx_buf_num = 0;
			else
				rx_buf_num = 1;
		}
		else if (cmd_head[rx_buf_num]){
			rx_buf[rx_buf_num][rx_buf_pointer[rx_buf_num]++] = temp;
			if (rx_buf_pointer[rx_buf_num] > RX_BUF_SIZE-1){		//recieve buffer overflow
				rx_buf_overflow[rx_buf_num] = 1;
				cmd_head[rx_buf_num] = 0;
			}
		}
	}
	if(TI){
		tx_done = 1;
		TI = 0;
	}
	RI = 0;
}
/*	name:			reply_unknown_cmd(Uchar i)
	parameter:		recieve buffer's number
	function:		reply MCP for unknown command
*/
void reply_unknown_cmd(Uchar i){
	Uchar xdata j;
	rx_buf_overflow[i] = 0;

//	if (tx_paused)							//检测是否中断了发送缓存
//		tx_paused = 0;
//	TI = 1;									//把中断的发送缓存中的内容发完
//	while(!tx_buf_empty && !tx_paused){}	//查询发送缓存是否为空且没有停止
//	while(!tx_buf_empty){}
	//向发送缓存中填入信息
//	if (!tx_paused){						//如果发送缓存停止则丢弃这一帧的发送
		for(j=0;j<0x9;j++)
			tx_buf[j] = rx_buf[i][j];
		tx_buf[1] = rx_buf[i][2];
		tx_buf[2] = rx_buf[i][1];
		tx_buf[6] = '0';
		tx_buf[7] = '0';
		tx_buf[8] = '0';
		tx_buf[9] = '1';
		tx_buf[0xA] = '1';
		tx_buf[0xB] = '*';
//	}
//	while(!tx_done && !tx_paused){}				//查询上一次发送是否完成且没有停止
//	while(!tx_done){}
//	if(!tx_paused){								//如果发送缓存停止则丢弃这一帧的发送
//		tx_done = 0;							//发送完成标志归零
//		tx_buf_empty = 0;						//发送缓存空标志清除
//		TI = 1;									//产生发送中断
//	}

	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;	
}
/*	name:			reply_recieved_cmd(Uchar i)
	parameter:		recieve buffer's number
	function:		reply MCP for command recieved


void reply_recieved_cmd(Uchar i){
	Uchar xdata j;
//	while(!tx_buf_empty){}
	for(j=0;j<0x9;j++)
		tx_buf[j] = rx_buf[i][j];
	tx_buf[1] = rx_buf[i][2];
	tx_buf[2] = rx_buf[i][1];
	tx_buf[6] = '0';
	tx_buf[7] = '0';
	tx_buf[8] = '0';
	tx_buf[9] = '3';
	tx_buf[0xA] = 'r';
	tx_buf[0xB] = 'c';
	tx_buf[0xC] = 'v';
	tx_buf[0xD] = '*';
//	while(!tx_done){}
//	tx_done = 0;
//	tx_buf_empty = 0;
//	TI = 1;
	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;
}
*/
/*	name:			analysis_cmd(Uchar i)
	parameter:		recieve buffer's number
	function:		analysis the command and save the parameters of commands
*/

void analysis_cmd(Uchar i){
	Uchar xdata cmd_num[3]={0,0,0},temp,temp1,temp2;
	unsigned long int xdata cmd=0;
	unsigned int xdata cmd_length_temp,cmd_length_temp1,cmd_length_temp2,cmd_length_temp3,cmd_length_temp4;
	unsigned long int xdata per_threshold1,per_threshold2,per_threshold3,per_threshold4,per_threshold5,per_threshold6,per_threshold7,per_threshold8;

	cmd_num[0] = rx_buf[i][3];
	cmd_num[1] = rx_buf[i][4];
	cmd_num[2] = rx_buf[i][5];
	cmd = cmd_num[2] | (cmd_num[1] << 8) | ((unsigned long)cmd_num[0] << 16);
	cmd_length_temp1 = (unsigned int)AsciiToHex(rx_buf[i][9]);
	cmd_length_temp2 = (unsigned int)AsciiToHex(rx_buf[i][8]);
	cmd_length_temp3 = (unsigned int)AsciiToHex(rx_buf[i][7]);
	cmd_length_temp4 = (unsigned int)AsciiToHex(rx_buf[i][6]);
	cmd_length_temp = cmd_length_temp1 | cmd_length_temp2 << 4 | cmd_length_temp3 << 8 | cmd_length_temp4 << 12;

	if ((cmd_length[i] >= 0xF7) || (cmd_length[i] < 0x0))
		reply_unknown_cmd(i);
	else if (cmd_length[i] != cmd_length_temp)
		reply_unknown_cmd(i);
	else switch (cmd){
		case 0x433030:				//command:"C00"
		case 0x633030:				//command:"c00"
			if (!GetMcpRdyTbl(1)){
				cmd_para_save.tsset_Sboard = rx_buf[i][0x0A] - 0x30;
				cmd_para_save.tsset_Stype = rx_buf[i][0x0B] - 0x30;
				temp1 = rx_buf[i][0xC]-0x30;
				temp2 = rx_buf[i][0xD]-0x30;
				cmd_para_save.tsset_Sport = temp1 * 10 + temp2;

				temp1 = rx_buf[i][0xE]-0x30;
				temp2 = rx_buf[i][0xF]-0x30;
				cmd_para_save.tsset_Sslot = temp1 * 10 + temp2;

				cmd_para_save.tsset_Dboard = rx_buf[i][0x10] - 0x30;
				cmd_para_save.tsset_Dtype = rx_buf[i][0x11] - 0x30;
				temp1 = rx_buf[i][0x12]-0x30;
				temp2 = rx_buf[i][0x13]-0x30;
				cmd_para_save.tsset_Dport = temp1 * 10 + temp2;

				temp1 = rx_buf[i][0x14]-0x30;
				temp2 = rx_buf[i][0x15]-0x30;
				cmd_para_save.tsset_Dslot = temp1 * 10 + temp2;
				SetMcpRdyTbl(1);
			}
			//reply_recieved_cmd(i);
			break;
		case 0x433031:				//command:"C01"
		case 0x633031:				//command:"c01"
			if (!GetMcpRdyTbl(2)){
				cmd_para_save.tsdel_Sboard = rx_buf[i][0xA]-0x30;
				cmd_para_save.tsdel_Stype = rx_buf[i][0x0B] - 0x30;
				temp1 = rx_buf[i][0xC]-0x30;
				temp2 = rx_buf[i][0xD]-0x30;
				cmd_para_save.tsdel_Sport = temp1 * 10 + temp2;

				temp1 = rx_buf[i][0xE]-0x30;
				temp2 = rx_buf[i][0xF]-0x30;
				cmd_para_save.tsdel_Sslot = temp1 * 10 + temp2;

				cmd_para_save.tsdel_Dboard = rx_buf[i][0x10]-0x30;
				cmd_para_save.tsdel_Dtype = rx_buf[i][0x11] - 0x30;
				temp1 = rx_buf[i][0x12]-0x30;
				temp2 = rx_buf[i][0x13]-0x30;
				cmd_para_save.tsdel_Dport = temp1 * 10 + temp2;

				temp1 = rx_buf[i][0x14]-0x30;
				temp2 = rx_buf[i][0x15]-0x30;
				cmd_para_save.tsdel_Dslot = temp1 * 10 + temp2;
				SetMcpRdyTbl(2);
			}
//			reply_recieved_cmd(i);
			break;
		case 0x433130:				//command:"C10"
		case 0x633130:				//command:"c10"
			if (!GetMcpRdyTbl(3)){
				cmd_para_save.force_clock_source = rx_buf[i][0xA]-0x30;
				SetMcpRdyTbl(3);
			}
//			reply_recieved_cmd(i);
			break;
		case 0x433131:				//command:"C11"
		case 0x633131:				//command:"c11"
			if (!GetMcpRdyTbl(4)){
				cmd_para_save.clock_source_mode = rx_buf[i][0xA]-0x30;
				SetMcpRdyTbl(4);
			}
//			reply_recieved_cmd(i);
			break;
		case 0x433132:				//command:"C12"
		case 0x633132:				//command:"c12"

⌨️ 快捷键说明

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