Xin code mẫu ngắt uart

thienminh_npn

Thành Viên PIF
Có anh chị nào cho em xin một đoạn code ngắt uart với. Tình hình là thử hoài vẫn chưa thành công ạ. Em cảm ơn nhiều.
 

tungbk

Cố Vấn CLB
Staff member
PHP:
/****************************************************************
 *
 * PIC Training Course 4
 * 
 ****************************************************************/

/****************************************************************
 *
 *	Module	: main_uart_int.c
 *	Description	: test uart interrupt
 *     Tool		: HI-TECH PIC
 *	Chip		: 16F887
 * 	History	: 21/11/2011
 *				
 *	Author	: Dang Anh Tung, CLB PIF			
 *	Description	: PORTD<==>LCD16x2 ; UART<==>PC
 *				
 *
 ****************************************************************/
 

 /****************************************************************
 * 							IMPORT
 ****************************************************************/
  #include <htc.h>
  #include "uart.h"
  
 
 __CONFIG(XT & WDTDIS & PWRTEN & MCLREN & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS);    //1st config. word
 __CONFIG(BORV21);    //2st config. word
#define _XTAL_FREQ 4000000

/*****************************************************************
* 							DEFINE
******************************************************************/



/*****************************************************************
* 						GLOBAL VARIABLES
******************************************************************/


/*****************************************************************
* 						SUBROUTINES
******************************************************************/

void system_init();

/*****************************************************************
* 						INTERRUPT
******************************************************************/
void interrupt isr()
{
	char temp;
	if(RCIE &&RCIF)
	{
		//RXIF is cleared by hardware
		//get the character
		temp = RCREG;
		//wait until transmitter buffer is available
		while(!TXIF);
                //echo the character
		TXREG = temp;
	}
}


/*****************************************************************
* 						MAIN
******************************************************************/
 
void main(void)
{ 
	system_init();
	while(1)
	{	
	}
}



/*****************************************************************
** Function name:		SystemInit
**
** Descriptions:		
**						
** parameters:			None
** Returned value:		None
** 
*******************************************************************/
void system_init()
{
	//digital pins
	ANSEL = 0;
	ANSELH = 0;
	//init uart peripheral	
	uart_init();
	uart_puts("hello");
	//uart interrupt enable
	RCIE = 1;
	PEIE = 1;
	GIE = 1;
}



/****************************************************************
 * END OF standard form.c
 ****************************************************************/
Ủa anh thấy code bình thường mà (đã thử lại trên mạch), hay là có nhầm gì chăng? E thử lại code này xem.
 
Top