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

📄 armuart.c

📁 64输入32输出单片机程序
💻 C
字号:
//---------------------------------------------------------------------------
//	Project Title : Armature (Resistance) tester for stator.
//	  Project No. : 
//	 Project Ver. : 1.00
//	    File Name : ArmUart.c
//	     Revision : 1.00
//	 Initial Date : 22-Nov,2002
//	  Modify Date : 27-DEC,2003
//	  Description :
//---------------------------------------------------------------------------
#include <..\atmel\at89s53.h>
#include <absacc.h>
#include "dom12a.h"

#define UART_SEND 		1
#define UART_RECEIVE    0

#define UART_TEST			0x80
#define UART_CONFIG_SLOT	0x81
#define UART_CONFIG_PGAIN	0x82
#define UART_ROOM_TEMP		0x83
#define UART_R180_TEST		0x84
#define UART_RCOIL_TEST         0x85
#define UART_LCOIL_TEST         0x86
#define UART_RESET_TEST         0X87           // test end then reset relay
#define UART_EEPR_LSB           0x90
#define UART_EEPR_MSB           0x91
#define UART_EEPROM_R           0x92
#define UART_EEPROM_W           0x93
//---------------------------------------------------------------------------
#define BAUD96_MSB                      0x0ff
#define BAUD96_LSB			0x0b2
#define BAUD192_MSB			0x0ff
#define BAUD192_LSB			0x0d9
#define BAUD288_MSB			0x0ff
#define BAUD288_LSB			0x0e6
#define BAUD576_MSB			0x0ff
#define BAUD576_LSB                     0x0f3

//---------------------------------------------------------------------------
sbit	RS485_WR	= P1^0;
sbit 	RS485_RD	= P1^1;
sbit 	MPU_CS		= P1^2;

//extern func.

//------
uUART_protocol  uart;
uUART_protocol  uartIn;
bit 			uartReply;
//uchar *data ptrSBuf;
//uchar *data ptrSBufIn;
uchar data		uartCNT;
uchar data		idxrxbuf = 0;
uchar data 		idxtxbuf = 0;

//	Fuctions prototype
void _uart_initial (void);
char _uart_command (unsigned char cmdcode);
char _uart_reply (void);
void Disable_Uart(void);

//---------------------------------------------------------------------------
void _uart_initial (void)
{
    TH2 = RCAP2H = BAUD96_MSB;
    TL2 = RCAP2L = BAUD96_LSB;
    SCON = 0x50;       			// SM0=0,SM1=1,SM2=0,REN=1,TB8=0,TR8=0,TI=0,RI=0;
    T2CON = 0x30;       		// set time2
    TR2 = 1;                    // turn on timer2
    ES = REN  = 1;               // enable serial
    RS485_WR  = 0;
    RS485_RD  = 1;
	uartReply = FALSE;
	
	//ptrSBuf = uart.sbuf;
} // end func.

//---------------------------------------------------------------------------
char _uart_command (unsigned char cmdcode)
{
    TI = RI = 0;
	MPU_CS = SBIT_LOW;	
    uartReply = FALSE;
    REN = FALSE;
    ES = TRUE;
	SBUF = cmdcode;

	idxrxbuf = 0;
	idxtxbuf = 1;

	//ptrSBuf   = &uart.sbuf[1];
	//ptrSBufIn = &uartIn.sbuf[0];
	uartCNT = 9;
	return TRUE;
} // end func.

//---------------------------------------------------------------------------
char _uart_reply (void)
{
   return (uartReply);
} // end func.

//***************************************************************
void Disable_Uart(void)
{
  ES = REN = 0;
  MPU_CS = SBIT_HIGH;
} // end func.

//---------------------------------------------------------------------------
//		Serial port RX or TX (vector 4) Interrupt handler. 
//---------------------------------------------------------------------------
void serialport (void) interrupt 4 using 3
{ // multiple bytes r/tx
  register uchar cx;

  if ( TI ) {
	  TI = 0; // Clear flag
	  if (uartCNT--) {
		 cx = uart.sbuf[idxtxbuf++];
		 SBUF = cx;
	  } else {
	  	 REN = 1;
		 uartCNT = 10;	//FINALIZED ver should be 10
		 idxrxbuf = 0;
	  } // end else
  } // end if
	  	
  if ( RI ) {
		RI = 0;
		cx = SBUF;
		uartIn.sbuf[idxrxbuf++] = cx;
		//*ptrSBufIn++ = cx; 
		if ( !--uartCNT) {
 			uartReply = TRUE;
        	ES = REN = 0;
			MPU_CS = SBIT_HIGH;
		} // END IF
  } // end if
} // end isr

⌨️ 快捷键说明

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