想要了解嵌入式行业经济发展 & 欧盟工业发展趋势吗?速点>>
首页 » 问答 » 医疗电子 » 诊断设备类 » Renesas M16C/62P串口通信问题

Renesas M16C/62P串口通信问题

菜鸟
2008-03-20 15:34:09
芯片是Renesas M16C/62P,调试工具是StarterKit包中的学习板和E8仿真器,调试软件是HEW中提供的UART样例程序。但是发现串口没有工作,甚至无法对u0tb和u0brg寄存器进行写操作,现将程序贴出,请高手指点,不胜感激。 /*********************************************************************************** FILE NAME : main_UART.c DESCRIPTION : Main routine for UART sample code This program communicates from the M16C/62P to a terminal program via UART0 and RS232. UART0 configuration is: 19200 baud, 8-bit data, 1 stop bit, no parity, no flow control. Incrementing data (0 to 9) is sent to the terminal window. To stop receiving data, press z on the keyboard. To resume, press any key. While data is transmitting LED1 is on and LED2 is off. When transmission is stoppeb by pressing "z" LED2 turns on and LED1 turns off Copyright : 2005 Renesas Technology Europe Ltd. Copyright : 2005 Renesas Technology Corporation. All Rights Reserved ***********************************************************************************/ /*********************************************************************************** Revision History DD.MM.YYYY OSO-UID Description 11.08.2005 RTA-MGF First Release ***********************************************************************************/ /********************************************************************************** System Includes ***********************************************************************************/ /********************************************************************************** User Includes ***********************************************************************************/ /* sfr62p.h provides common defines for widely used items. */ #include "sfr62p.h" /* rskM16C62pdef.h defines some common definitions*/ #include "rskM16C62pdef.h" #include "main.h" /********************************************************************************** User Defines ***********************************************************************************/ /********************************************************************************** Global variables ***********************************************************************************/ /* declare UART0 receive variable*/ unsigned char U0_in; /* String constants used for screen output far since they are outside 64k boundary */ _far const char cmd_clr_scr[] = {27,'[','2','J',0}; _far const char cmd_cur_home[] = {27,'[','H',0}; /********************************************************************************** User Program Code ***********************************************************************************/ /*********************************************************************************** Name: Main Parameters: none Returns: none Description: This is the main program ***********************************************************************************/ void main(void) { unsigned char ucCount; unsigned char ucConvert; unsigned short usDelay; /* UART initialization */ uart_init(); /* Text to be displayed at the beginning of the program output to the terminal window (\r\n = carriage return & linefeed) */ text_write(cmd_clr_scr); text_write(cmd_cur_home); text_write("Renesas Technology Corporation \r\n"); text_write("RSKM16C62P UART demo. \r\n"); text_write("Press z to stop, any key to continue. \r\n"); while (1) { /* count as long as "z" wasn't pressed, send carrige return and line feed and turn on LED1 */ while (U0_in != 'z') { /* Send carriage return and line feed */ text_write("\r\n"); LED2 = LED_OFF; LED1 = LED_ON; /* count 0 to 9 */ for (ucCount=0;(ucCount0; usDelay--); } } /* Do nothing while stopped (after "z" is pressed) */ _asm("NOP"); } } /********************************************************************************** End of function main **********************************************************************************/ /********************************************************************************** Name: UART0 Receive Interrupt Routine Parameters: none Returns: none Description: Interrupt routine for UART0 receive Reads character received from keyboard and stores U0_in variable *********************************************************************************/ void U0rec_ISR(void) { /* make sure receive is complete */ while(ri_u0c1 == 0); /* read in received data */ U0_in = (char)u0rb; /* If "z" was entered: wait for previous transmission to complete, echo "z" to screen and turn LED2 ON */ if (U0_in == 'z') { /* wait for previous transmission to complete */ while(ti_u0c1 == 0); /* echo "z" to screen */ u0tb = 'z'; LED2 = LED_ON; LED1 = LED_OFF; } } /********************************************************************************** End of function U0rec_ISR ***********************************************************************************/ /***************************************************************************** Name: uart_init Parameters: None Returns: None Description: Uart0 initialization - 19200 baud, 8 data bits, 1 stop bit, no parity. *****************************************************************************/ void uart_init(void) { /* set UART0 bit rate generator bit rate can be calculated by: bit rate = ((BRG count source / 16)/baud rate) - 1 Baud rate is based on main crystal or PLL not CPU core clock */ u0brg = (unsigned char)(((f1_CLK_SPEED/16)/BAUD_RATE)-1); u0brg = 0x4D; /* UART Transmit/Receive Control Register 2 */ ucon = 0x00; /* 00000000 b0 U0IRS UART0 transmit irq cause select bit, 0 = transmit buffer empty b1 U1IRS UART1 transmit irq cause select bit, 0 = transmit buffer empty b2 U0RRM UART0 continuous receive mode enable bit, set to 0 in UART mode b3 U1RRM UART1 continuous receive mode enable bit, set to 0 in UART mode b4 CLKMD0 CLK/CLKS select bit 0, set to 0 in UART mode b5 CLKMD1 CLK/CLKS select bit 1, set to 0 in UART mode b6 RCSP Separate CTS/RTS bit, b7 Reserved, set to 0 */ /* UART0 transmit/receive control register 0 */ /* f1 count source, CTS/RTS disabled, CMOS output */ u0c0 = 0x10; /* 00010000 b1:b0 CLK01:CLK0 BRG count source select bits b2 CRS CTS/RTS function select bit b3 TXEPT Transmit register empty flag b4 CRD CTS/RTS disable bit b5 NCH Data output select bit b6 CKPOL CLK polarity select bit,set to 0 in UART mode b7 UFORM Transfer format select bit,set to 0 in UART mode */ /* UART0 transmit/receive control register 1 */ /* disable transmit and receive, no error output pin, data not inverted */ u0c1 = 0x00; /* 00000000 b0 TE Transmit enable bit b1 TI Transmit buffer empty flag b2 RE Receive enable bit b3 RI Receive complete flag b5:b4 Reserved, set to 0 b6 UOLCH Data logic select bit b7 UOERE Error signal output enable bit */ /* UART0 transmit/receive mode register */ /* 8-bit data,asynch mode, internal clock, 1 stop bit, no parity */ u0mr = 0x05; /* 00000101 b2:b0 SMD12:SMD1 Serial I/O Mode select bits b3 CKDIR Internal/External clock select bit, CKDIR b4 STPS Stop bit length select bit, STPS b5 PRY Odd/even parity select bit, PRY b6 PRYE Parity enable bit, PRYE b7 IOPOL TxD, RxD I/O polarity reverse bit */ /* clear UART0 receive buffer by reading */ u0tb = u0rb; /* clear UART0 transmit buffer */ u0tb = 0; /* disable irqs before setting irq registers */ DISABLE_IRQ /* Enable UART0 receive interrupt, priority level 4 */ s0ric = 0x04; /* Enable all interrupts */ ENABLE_IRQ /* UART0 transmit/receive control register 1 */ /* enable transmit and receive */ u0c1 = 0x05; /* 00000101 enable transmit and receive b0 TE Transmit enable bit b1 TI Transmit buffer empty flag b2 RE Receive enable bit b3 RI Receive complete flag b5:b4 Reserved, set to 0 b6 UOLCH Data logic select bit b7 UOERE Error signal output enable bit */ } /********************************************************************************** End of function uart_init ***********************************************************************************/ /***************************************************************************** Name: text_write Parameters: msg_string - the text string to output Returns: none Description: The following sends a text string to the terminal program *****************************************************************************/ void text_write ( _far const char * msg_string) { char i; /* This loop reads in the text string and puts it in the UART 0 transmit buffer */ for (i=0; msg_string[i]; i++) { while(ti_u0c1 == 0); /*Write the character out*/ asm("nop"); u0tb = msg_string[i]; asm("nop"); } } /********************************************************************************** End of function text_write ***********************************************************************************/
关键词: Renesas, 串口通信  
工程师
2008-03-20 17:55:56
1楼

这个问题问的好!~~~~~~

工程师
2008-04-02 17:12:29
2楼

我没看懂

院士
2009-06-15 10:47:12
3楼

代码真长啊

回复

匿名不能发帖!请先 [ 登陆 注册 ]