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

📄 245_hyper.c

📁 Mitsubishi M30245 SampleCode
💻 C
字号:
 /*****************************************************************************
*
*	File Name:  245_hyper.c                                         
*                                                                  
*	Content:   	This program communicates from the M30245 starter board 
*			to windows Hyperterm program via RS232.  UART configuration is:
*  			9600 baud, 8 data bits, 1 stop bit, no parity. Connect serial cable
*			from J2 to a COM port on the PC
*
*			Version: 1.1
*  			Date: 8-29-02
*                                                                                   
*	Copyright 2002 Mitsubishi Electric & Electronics US                           
*	All rights reserved                                            
*                                                                  
*=============================================================================
*	$Log:$
*===========================================================================*/


#include "sfr245.h"		 /*  include M30245 header file */

/* Setup interrupt routine for UART3 receive */
/*  This must be setup in the vector table in SECT30.INC also */
#pragma INTERRUPT /B	U3rec_ISR

int U3_in;				/* declare UART3 recieve variable */

/*****************************************************************************
Name:       Main    
Parameters:                     
Returns:        
Description: This is the main program    

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

main() {

	int count;			/* declare count variables */
	int count2;
	int count3;
	int convert;		/* declare ASCII variable */
	unsigned int delay;	/* declare delay variable */
	int i;				/* declare string pointer variable */

/* Define text to be displayed at the beginning of the output to hyperterminal */
	
	char text[] = "Press z to stop, any key to continue.";

/* Initialize Port2 for LED output */

	pd7 = 0x1F;	 		/* Configure port 7 direction */
	p7dr = 0x0F;		/* Configure high drive capacity for LEDs */
	p7 |= 0x0F;			/* Initialize port7_0 to 7_3, LEDs off */

/*  Configure Uart3 for 9600 baud, 8 data bits, 1 stop bit, no parity */

  	u3mr = 0x05;		/* set mode register */
  	u3c0 = 0x18; 		/* set control register */
	u3brg = 0x67;		/* set bit rate generator */
						/*  (16Mhz/16/9600)-1 */ 

  	u3tb = 0;			/* clear transmit buffer */
  	count = u3rb;		/* clear receive buffer by reading */

  	count = 0x00;		/* Initaialize count data */
	te_u3 = 1;			/* Enable UART3 transmit */
	re_u3 = 1; 			/* Enable UART3 receive	*/
	s3ric = 0x04;		/* Enable UART3 receive interrupt, */
						/*  priority level 4 */	
	asm("FSET I");		/* Enable all interrupts */


	u3tb = 0x0d;			 	/* The following sends text at the beginning */ 
	while(ti_u3 == 0);	 		/*  of the program to hyperterminal */
	u3tb = 0x0a;
	for (i=0; i<=36; i++){	 	/* This loop reads in the text string and */
		while(ti_u3 == 0); 		/*  puts it in the transmit buffer */
		u3tb = text[i];
	}
	
 	/* ************** PROGRAM LOOP ***********************/

  while (1){
  	
/* setup program loop to count from 0 to 9, stop when "z" is received */

	while (U3_in != 'z'){
		while(ti_u3 == 0);	  	  	/* wait for previous transmission to complete */ 
		u3tb = 0x0d;			  	/* send carrige return */
		while(ti_u3 == 0);	  	  	/* wait for previous transmission to complete */
		u3tb = 0x0a;				/* send line feed */

		for (count=0;(count<=9)&&(U3_in!='z');count ++){
 			convert = count + 0x30;	  	/* convert count data to ASCII */
			while(ti_u3 == 0);	  		/* wait for previous transmission to complete */
	 		u3tb = convert;			  	/* put ASCII data in transmit buffer */

			count2 = ~count;		 /* Invert data for common anode LEDs */
			count3 = p7;			 /* Get current data on P7 */
			count3 |= 0x0f;			 /* clear out LED data (lower byte) and */
			count2 &= count3;		 /*   replace with new LED data */
			p7 = count2;			 /* Output new count value to P7 */

			for (delay=0xafff; delay>0; delay--)	/* Delay, control speed of counting */
				asm("NOP"); 						
		}
	}
	asm("NOP");						/* Do nothing while stopped	*/
  }									/*  (after "z" is pressed) */
}
/******************** END OF MAIN *******************************************/

/*****************************************************************************
Name:    UART3 Receive Interrupt Routine       
Parameters:                     
Returns:        
Description:	Gets data entered into the keyboard. "z" will stop the 
				program counting 
*****************************************************************************/

void U3rec_ISR(void){
	while(ri_u3 == 0);	  	/* make sure receive is complete */
	U3_in = u3rb;		    /* read in received data */
	if (U3_in=='z'){		/* If "z" was entered do the following: */
	while(ti_u3 == 0);	  	/*   wait for previous transmission to complete */
	u3tb = 'z';				/*   write "z" to screen */
	}	
}							

⌨️ 快捷键说明

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