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

📄 sofe-uart.c

📁 it is code for briging up_machtion to down machtion,it s functions act protol changing and comunica
💻 C
字号:


#include "port.h"
#include "function.h"
#include  "Exvariable.h"
#include  "ExHeadFileRs232.h"

void Rec485(void);
void PCA_ISR(void) interrupt 9
	{ 

	 	unsigned int PCA_TEMP; 
	 	unsigned int PCA_TEMP1; 
		unsigned char TDR2;
		PageTemp=SFRPAGE;
			if (CCF0)
			{
				CCF0 = 0; // Clear interrupt flag. 
				PCA0CPM0=0x00;
				switch (SURXST)
					{ 
						case 0: 
							if (!RxRs485)
								{ 
									SFRPAGE=PCA0_PAGE;
									PCA_TEMP1 = 0x0000; 
									PCA0H=PCA_TEMP1;
				    				PCA0L=PCA_TEMP1;
									PCA0CPH0= (TH_TIME_COUNT >> 8); // module 1 capture/compare registers. 
									PCA0CPL0= TH_TIME_COUNT; 		// Store updated match value into 
									PCA0CPM0=0x49;
									Rs485RxShift=0;
									CR=1;
									SURXST++;
								}
							break; 

						case 1: 
						case 2: 
						case 3: 
						case 4: 
						case 5: 
						case 6: 
						case 7:
						case 8: 
							SFRPAGE=CONFIG_PAGE;
							CY=0;
							Rs485RxShift = Rs485RxShift >> 1; 
							if (RxRs485) 
							{
			 					Rs485RxShift |= 0x80; 
							}
							SFRPAGE=PCA0_PAGE;
							PCA0H=0x00;
			    			PCA0L=0x00;
							PCA0CPL0= TIME_COUNT2; 			// Store updated match value into 
							PCA0CPH0= (TIME_COUNT2 >> 8); 	// module 1 capture/compare registers. 
							PCA_TEMP1=0x49;
							PCA0CPM0 = PCA_TEMP1; 			// Enable module 1 software timer.
							CR=1;
							SURXST++; 
			   				break; 

						case 9: 
							Rs485RxData=Rs485RxShift;
							Rs485RxShift=0x00;
							SFRPAGE=PCA0_PAGE;
							CR=0;
							SURXST=0;
							PCA0CPM0 = 0x51; //triggle by negative lever
							SFRPAGE=CONFIG_PAGE;
							if (RxRs485) 
								{
									//分析收到的数据
									AnalysisRs485();
								}
								
			    			break;
		
					}
		
			} 

		if (CCF1)
			{  
				CCF1 = 0; // Clear interrupt flag 
				PCA0CPM1=0x00;
			
				switch (SUTXST)
					{ 
		  				case 0x00:
							SFRPAGE=CONFIG_PAGE;
							EnRs485=0x01;
							TxRs485 = 0x00; // Drop TX pin as START bit. 
							SFRPAGE=PCA0_PAGE;
							PCA_TEMP1 = 0x00; 
							PCA0H=PCA_TEMP1;
		    				PCA0L=PCA_TEMP1;
							PCA0CPH1= (TIME_COUNT >> 8); // module 1 capture/compare registers. 
							PCA0CPL1= TIME_COUNT; // Store updated match value into 
							PCA0CPM1=0x49;
							CR=1;
							SUTXST++;
							break; 
    

						// States 1-9: Transmit Bit.
						// - Output LSB of TDR onto TX
						// - Shift TDR 1 bit right.
						// - Shift a '1' into MSB of TDR for STOP bit in State 9.
						// - Add 1 bit time to module 1 capture register
						case 0x01:
						case 0x02:
						case 0x03: 
						case 0x04: 
						case 0x05: 
						case 0x06: 
						case 0x07: 
						case 0x08:
						
							SFRPAGE=CONFIG_PAGE;
							CY=0x00;
							TxRs485 = (TDR & 0x01); 
							TDR2=TDR/2; 
							TDR=TDR2;
							SFRPAGE=PCA0_PAGE;
							PCA0H=0x00;
		    				PCA0L=0x00;
							PCA0CPL1= TIME_COUNT1; // Store updated match value into 
							PCA0CPH1= (TIME_COUNT1 >> 8); // module 1 capture/compare registers. 
							PCA0CPM1=0x49; // Enable module 1 software timer.
							SUTXST++; 
							break; 

						case 0x09: 
							SFRPAGE=CONFIG_PAGE;
							TxRs485=1;
							SFRPAGE=PCA0_PAGE;
							PCA0H=0x00;
		   		 			PCA0L=0x00;
							PCA0CPL1= TIME_COUNT1; // Store updated match value into 
							PCA0CPH1= (TIME_COUNT1 >> 8); // module 1 capture/compare registers. 
							PCA_TEMP=0x49;
							PCA0CPM1 = PCA_TEMP; // Enable module 1 software timer.
		  					SUTXST++;
		    				break;


						case 0xa:

							SFRPAGE=PCA0_PAGE;
							CR=0;
							SUTXST = 0;
							if ( Rs485ReadPointer<Rs485SendLen )
								{				
									TDR = Rs485RxBuffer[Rs485ReadPointer++]; 
									SFRPAGE=PCA0_PAGE;
									PCA0CPM1=0x49;
									CCF1 = 1; 
								}
							else
								{
									Rs485ReadPointer=0x00;
									SFRPAGE=CONFIG_PAGE;
									LampSendModule=0x01;
				    				EnRs485=0x00;
									SFRPAGE=PCA0_PAGE;			
						  			PCA0CPM1 = 0x01;
		 							CR=0;
								}
							break; 

						default:
							break;
					} 

					
			}
		SFRPAGE=PageTemp;
	}		 






























⌨️ 快捷键说明

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