完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好论坛,我刚刚开始学习图片。我正在学习PIC24FJ256GB110。我试图理解由MCC生成的DUART代码,然后从这个代码中开发我的第一个应用程序。我需要使用这个PIC的3个UART端口。我已经成功地使用了Prtff Funcon来编写和读取UART,但是我发现我不能同时在一个以上的UART中启用重定向PrTrF。UART端口还是有更好的方式来编写和读取UART端口?提前感谢!Hector,W5CBF
以上来自于百度翻译 以下为原文 Hello Forum, I just started learning PICs. I am learning PIC24FJ256GB110. I am trying to understand de UART code that is generated by the MCC and then develop my first application from this code. I need to use 3 of the UART ports of this PIC. I have succsesfully used the printf funcion to write and read the UART but I found I can not enable redirect printf in more than one UART at the same time. Is it possible to enable and disable this funcion in the fly every time that I need to use one of the UART ports or is it there a better way to write and read the UART ports? Thanks in advance! Hector, W5CBF |
|
相关推荐
19个回答
|
|
如果你刚刚开始学习或多或少:系统打算在编译时将Prtff()分配给一个UART。但这需要更多的知识。因此,现在最好在编译时满足这个独占的Prtff()赋值……基本上同样适用于动态启用/禁用:告诉MCU您是否希望打开或关闭Primff()输出的方法是什么?
以上来自于百度翻译 以下为原文 If you started learning more or less just now: the system is intended to assign the printf() to a single UART - at compile time. I n p r i n c i p l e it is possible to alter this behavior. But this requires a lot more of Knowledge. Thus for the moment it is better to content with this exclusive printf() assignment at compile time... Basically the same applies for dynamic enabling/disabling: what would be your means to tell the MCU whether you want the printf() Output on or off? |
|
|
|
非常感谢您的帮助!如果我选择启用UART中断而不是PROTF函数,我应该从MCC生成的代码中创建或读取一个特定的变量或数组,或者我必须创建自己的代码来支持UxTXREG UxRXREG。我想要完成的是能够在我的3个UART端口中使用。代码,再次感谢!Hector,W5CBF
以上来自于百度翻译 以下为原文 du00000001 Thank you very much for your help!! If I choose to enable the UART interrupts instead of the printf function should I write/read from/to an specific variable or array already created in the MCC generated code or I have to create my own code to support UxTXREG UxRXREG. What I want to accomplish is to be able to use 3 UART ports in my code. Thanks again! Hector, W5CBF |
|
|
|
使用SaveTf将您的输出放入字符串变量中,然后将该字符串发送到您选择的UART。
以上来自于百度翻译 以下为原文 Use sprintf to place your output into a string variable, then send that string to the UART of your choice. |
|
|
|
非常感谢您的回复!一旦我把数据放进一个字符串变量[/COD] char MyString [30 ] PrimTf(MyString,“数据输入字符串”)[/COD],我如何将字符串发送到一个特定的UART?我明白,如果UXTSR是空的,我可以在UXTXRG中加载一个字节。UXTXRGG =“A”;(/CODE),但是,当我需要发送一个字符串时会发生什么?我需要打扰吗?我应该在每个时钟周期中发送一个字节吗?再次,非常感谢你的帮助!Hector,W5CBF
以上来自于百度翻译 以下为原文 qhb Thanks very much for your reply! Once I have the data into a string variable. [/code] char MyString[30] printf(MyString, "data to go in string") [/code] How can I send the string to a particular UART? I understand I can load a byte in UxTXREG if the UxTSR is empty. [/code] while(!UxSTAbits.TRMT); UxTXREG = "a"; [/code] But, what happen when I need to send a string?? Do I need interruptions? Should I send a byte in each clock cycle? Again, thanks very much for your help! Hector, W5CBF |
|
|
|
注意,你的代码标签不起作用,因为你把“/”放入了两个标签中。它应该只在结束标记中。注意,您使用了Prtff(),而不是SpReff(),使用UTART的TXIF位更有效,它告诉您数据何时从TXREG转移到TSR,这意味着TXREG是免费的。对于APC24FJ256GB110中的UART3,您肯定不能发送一个“EAC”。H时钟周期“!只需调用上面的函数,我就不知道MCC是否已经为您提供了上述功能,但是它们很简单,您可以自己添加。
以上来自于百度翻译 以下为原文 Note, your code tags didn't work because you put "/" into both tags. It should only be in the closing tag. Also note, you used printf(), not sprintf() It's more efficient to use the TXIF bit for the UART, which tells you when data has been shifted from the TXREG to the TSR, which means the TXREG is free. For UART3 in a PIC24FJ256GB110 void putch3(unsigned char OutData) { while (!IFS5bits.U3TXIF); //wait until U3TXREG is free U3TXREG = OutData; } You certainly can't send one "in each clock cycle" ! Just call the above function in a loop void putstr3(unsigned char * OutStr) { while (*OutStr) //loop until we hit a NULL putch3(*OutStr++); //send character, and bump pointer } I don't know if MCC already gives you the above functions, but they are so simple, you can add them yourself. |
|
|
|
还要注意的是,上面的代码对USAT TXIF标志进行了投票,但是它不使用中断。
以上来自于百度翻译 以下为原文 Also note, the code above polls the USART TXIF flag, but it does NOT use interrupts. |
|
|
|
非常感谢您的时间和奉献精神。我非常感激!我一直在寻找更多关于PutCh和PutSTR功能的信息,但是我没有发现任何有用的东西。我想了解更多的细节,请您解释一下,函数后面的数字代表什么?这意味着它将使用UART3吗?如果我想使用UART2,我应该把数字2代替3。如果我想使用UART2,还需要改变什么?在你的例子中,如果我想把字符串发送到UART,我如何用我想发送的字符串加载OutSTR变量?我可以只用S喷雾剂吗?非常感谢,再次,Hector,W5CBF
以上来自于百度翻译 以下为原文 qhb Thanks very much for your time and dedication. I appreciate it very much! I have been trying to look for more information about the putch and putstr funtions but I have not found anything helpful. I would like to learn more details. Could you please explain me what does the number after the function represents? putch3 putstr3 Does it means it is going to use the UART3? If I want to use UART2, should I put number 2 instead of 3. What else should I change If I want to use UART2?? Based in your example, If I want to send an string to the UART, how can I load the OutStr variable with the string I want to send? Can I use just sprintf to itself? Thanks very much, again. Hector, W5CBF |
|
|
|
这些都是你创建的函数,所以你可以把它们称为你想要的任何东西。是的,我把“3”表示为使用USATAR3。3.真正使用哪个USAT控制的是将PutCH3函数写入的寄存器。然后,PutsR3函数假定PutCH3写入正确的UART。您需要创建一组类似的函数来处理每个USAT.N.B。唯一的“特殊”函数名是“PutCH”,没有任何后缀。如果您创建了一个具有该名称的函数,那么库函数Prtff()和PtSU-()将使用它。这在XC编译器用户指南中被记录。
以上来自于百度翻译 以下为原文 These are functions you create, so you can call them anything you want. Yes, I put the "3" there to signify that it is using USART#3. What really controls which USART is used is which registers the putch3 function writes to. Then, the putstr3 function assumes that putch3 s writing to the correct USART. You'd need to create a similar set of functions to handle each USART. n.b. The only "special" function name is "putch", without any suffix. If you create a function with that name, then the library functions printf() and puts() will use it. This is documented in the XC compiler user guide. |
|
|
|
谢谢!我有代码运行。但我有另一个问题。如果我把一个字符串长度超过5 char到函数,UART不发送其余的。UART只发送多达5个字符字符串。我需要发送一个15字符字符串。请看代码:谢谢!!
以上来自于百度翻译 以下为原文 qhb Thank you again! I have the code running. But I am having another issue. If I pass a string longer than 5 char to the function, the UART does not transmit the rest. The UART is just sending up to 5 char strings. I need to send a 15 char string. Please see the code: #include "mcc_generated_files/mcc.h" #include #include #include void putch2(unsigned char OutData) { while (!IFS1bits.U2TXIF); //wait until U2TXREG is free U2TXREG = OutData; } void putstr2(unsigned char * OutStr) { while (*OutStr) //loop until we hit a NULL putch2(*OutStr++); //send character, and bump pointer } /* Main application */ int main(void) { // initialize the device SYSTEM_Initialize(); while (1) { __delay32(140000); putstr2("uarttestr"); } return -1; } /** End of File */ Thanks!! |
|
|
|
确保您没有启用看门狗定时器。
以上来自于百度翻译 以下为原文 Make sure you do not have the Watchdog timer enabled. |
|
|
|
看门狗定时器被禁用:还有其他的想法吗??
以上来自于百度翻译 以下为原文 qhb the Watchdog timer is disabled: // CONFIG1 #pragma config WDTPS = PS32768 // Watchdog Timer Postscaler->1:32768 #pragma config FWPSA = PR128 // WDT Prescaler->Prescaler ratio of 1:128 #pragma config WINDIS = OFF // Watchdog Timer Window->Standard Watchdog Timer enabled,(Windowed-mode is disabled) #pragma config FWDTEN = OFF // Watchdog Timer Enable->Watchdog Timer is disabled #pragma config ICS = PGx1 // Comm Channel Select->Emulator functions are shared with PGEC1/PGED1 #pragma config COE = OFF // Set Clip On Emulation Mode->Disabled #pragma config BKBUG = OFF // Background Debug->Device resets into Operational mode #pragma config GWRP = OFF // General Code Segment Write Protect->Writes to program memory are allowed #pragma config GCP = OFF // General Code Segment Code Protect->Code protection is disabled #pragma config JTAGEN = OFF // JTAG Port Enable->JTAG port is disabled Any other idea?? |
|
|
|
您的设备支持几种不同的中断模式,而不是与它们一起玩,而是尝试使用UTXBF标志。
以上来自于百度翻译 以下为原文 Your device supports several different interrupt modes. Rather than playing around with them, try using the UTXBF flag instead. void putch2(unsigned char OutData) { while (U2STA.UTXBF); //wait until U2TXREG is free U2TXREG = OutData; } |
|
|
|
QHB编译器不使用(U2STA.UTXBF),但我尝试了下面的方法,它工作了:我知道你告诉我这个中断它不是有效的吗?我们能做点更好的事吗?现在,我在UART的TX方面得到了完全的控制!!!!你能帮我设置RX方面吗?我怎样才能收到不同UART的字符串呢?再次感谢你们对我的耐心和奉献!
以上来自于百度翻译 以下为原文 qhb the compiler does not take (U2STA.UTXBF) but I tried the following and it worked: void putch2(unsigned char OutData) { while (!U2STAbits.TRMT); //wait until U2TXREG is free U2TXREG = OutData; } I know you told me this interruption it is not efficient?? Can we do something better? Now, I have full control in the TX side of the UARTs!!! Could you please help me to set up the RX side. How can I receive a string from the different UARTs. Once again, thank you very much for your patience and dedication on teaching me! |
|
|
|
|
|
|
|
这是我的一个打字。它应该有一个标准。UTXBFF使用TrMT会迫使它在每个字符之间传输一个小的空隙。它仍然可靠地工作,只是比它慢一点。每个UART只有一个小的接收FIFO。在每次接收到一个UART时,可以为每个UART创建一个小轮询函数。否则,更全面的技术是为每个USAT设置中断服务,并将接收到的字符放置到循环缓冲器(FIFO)中,以便您的非中断代码读取FRO。M.MCC应该能够为你生成代码,但是如果你自己做的话,你会更好地理解它。我从来没有用PIC24芯片工作,所以有经验的人可以更好地告诉你如何做一个中断服务。
以上来自于百度翻译 以下为原文 That was a typo on my part. It should have been U2STAbits.UTXBF Using TRMT will force it to leave a small gap between each character transmitted. It will still work reliably, just a little slower than it could be. Each UART only has a small receive FIFO. If you know when to expect characters, and will only be receiving from one at a time, then you can make a small polling function for each UART to receive. Otherwise, the more comprehensive technique is to set up an interrupt service for each USART, and place received characters into a circular buffer (=FIFO), for your non interrupt code to read from. MCC should be able to generate that code for you, but you'll understand it better if you do it yourself. I've never worked with a PIC24 chip, so someone more experienced with them can advise yo better how to do an interrupt service. |
|
|
|
谢谢1和0,谢谢QHB!!U2Stest.UTXBF工作!QHB每次我在UART上发送一些东西,我会期待同样的UART上的答案。我需要与所有的UART通信,但不能同时进行。所以,轮询功能可能会起作用。
以上来自于百度翻译 以下为原文 Thanks 1and0, thanks qhb!! U2STAbits.UTXBF works!! qhb Every time I send something on the UART, I am going to expect an answer back on the same UART. I need to communicate with all the UARTs but not at the same time. So, probably the polling function is going to work. |
|
|
|
嗨,先生们,你们都搞得一团糟。当MCC为PIC24设备生成UART代码时,代替了用于拦截STDIN和STDUT的PUTCH(和)GETCHE()函数,它可以生成具有TX和RX通道的循环缓冲器的驱动接口函数。这些缓冲器的大小是特殊的。为每个UART模块分别在MCC配置GUI中为RX和TX进行配置。不要选择重定向PRTTF,而是检查启用UART中断框,并指定缓冲区大小。如果要同时在多个UART信道上发送和接收,中断和缓冲传输将是。无论如何,缓冲传输的驱动接口是这样的:当MCC为不同的UART模块生成代码时,每个UART通道将有一个单独的文件,其中的函数名具有模块号。
以上来自于百度翻译 以下为原文 Hi gentlemen, you are all making a mess. When MCC is generating code for UART for PIC24 devices, Instead of the putch() and getch() functions for intercepting stdin and stdout, it may generate Driver Interface functions with circular buffers, both for TX and RX channels. Size of these buffers are specified in MCC configuration GUI for RX and TX separately for each UART module. Don't select Redirect Printf, instead check the Enable UART Interrupts box, and specify buffer sizes. If you are going to transmit and receive on multiple UART channels simultaneously, interrupts and buffered transfer will be needed anyway. The driver interface for buffered transmit is like this: /** UART2_WriteBuffer( *record, numbytes ); @Summary Transfer bytes to UART Transmit buffer @Description This API transfers the data from application buffer to internal buffer and returns the number of bytes added in that queue @Preconditions UART2_Initializer function should have been called before calling this function @Example
*/ unsigned int UART2_WriteBuffer( const uint8_t *buffer , const unsigned int numbytes ); When MCC generate code for different UART modules, there will be a separate file for each UART channel, with function names that have the module number. There is a similar set of functions for Receive. Regards, Mysil |
|
|
|
Mysil,非常感谢你的回复。请您帮助我理解MCC为UART生成的代码,以及如何创建一个例程来发送字符串并从该驱动程序接收字符串。我需要从一个UART接收数据,处理它,然后将产品发送到其他UART。我刚开始学习Microchip。我将感谢任何帮助。这是MCC为UART2生成的代码。
以上来自于百度翻译 以下为原文 Mysil, Thank you very much for your reply. Could you please help me to understand the code that the MCC generates for the UART and how can I create a routine to transmit a string and receive a string from this driver. I need to receive data from one UART, process it and then send the product to other UART. I just started learning Microchip. I will appreciate any help. This is the code that MCC generated for the UART2 #include "uart2.h" /** Section: Data Type Definitions */ /** UART Driver Queue Status @Summary Defines the object required for the status of the queue. */ typedef union { struct { uint8_t full:1; uint8_t empty:1; uint8_t reserved:6; }s; uint8_t status; } UART_BYTEQ_STATUS; /** UART Driver Hardware Instance Object @Summary Defines the object required for the maintenance of the hardware instance. */ typedef struct { /* RX Byte Q */ uint8_t *rxTail ; uint8_t *rxHead ; /* TX Byte Q */ uint8_t *txTail ; uint8_t *txHead ; UART_BYTEQ_STATUS rxStatus ; UART_BYTEQ_STATUS txStatus ; } UART_OBJECT ; static UART_OBJECT uart2_obj ; /** UART Driver Queue Length @Summary Defines the length of the Transmit and Receive Buffers */ #define UART2_CONFIG_TX_BYTEQ_LENGTH 8 #define UART2_CONFIG_RX_BYTEQ_LENGTH 8 /** UART Driver Queue @Summary Defines the Transmit and Receive Buffers */ static uint8_t uart2_txByteQ[UART2_CONFIG_TX_BYTEQ_LENGTH] ; static uint8_t uart2_rxByteQ[UART2_CONFIG_RX_BYTEQ_LENGTH] ; /** Section: Driver Interface */ void UART2_Initialize (void) { // STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; RXINV disabled; UEN TX_RX; U2MODE = (0x8008 & ~(1<<15)); // disabling UARTEN bit // UTXISEL0 TX_ONE_CHAR; UTXINV disabled; OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled; U2STA = 0x0000; // BaudRate = 38400; Frequency = 3686400 Hz; BRG 23; U2BRG = 0x0017; IEC1bits.U2RXIE = 1; //Make sure to set LAT bit corresponding to TxPin as high before UART initialization U2MODEbits.UARTEN = 1; // enabling UART ON bit U2STAbits.UTXEN = 1; uart2_obj.txHead = uart2_txByteQ; uart2_obj.txTail = uart2_txByteQ; uart2_obj.rxHead = uart2_rxByteQ; uart2_obj.rxTail = uart2_rxByteQ; uart2_obj.rxStatus.s.empty = true; uart2_obj.txStatus.s.empty = true; uart2_obj.txStatus.s.full = false; uart2_obj.rxStatus.s.full = false; } /** Maintains the driver's transmitter state machine and implements its ISR */ void __attribute__ ( ( interrupt, no_auto_psv ) ) _U2TXInterrupt ( void ) { if(uart2_obj.txStatus.s.empty) { IEC1bits.U2TXIE = false; return; } IFS1bits.U2TXIF = false; while(!(U2STAbits.UTXBF == 1)) { U2TXREG = *uart2_obj.txHead; uart2_obj.txHead++; if(uart2_obj.txHead == (uart2_txByteQ + UART2_CONFIG_TX_BYTEQ_LENGTH)) { uart2_obj.txHead = uart2_txByteQ; } uart2_obj.txStatus.s.full = false; if(uart2_obj.txHead == uart2_obj.txTail) { uart2_obj.txStatus.s.empty = true; break; } } } void __attribute__ ( ( interrupt, no_auto_psv ) ) _U2RXInterrupt( void ) { while((U2STAbits.URXDA == 1)) { *uart2_obj.rxTail = U2RXREG; uart2_obj.rxTail++; if(uart2_obj.rxTail == (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH)) { uart2_obj.rxTail = uart2_rxByteQ; } uart2_obj.rxStatus.s.empty = false; if(uart2_obj.rxTail == uart2_obj.rxHead) { //Sets the flag RX full uart2_obj.rxStatus.s.full = true; break; } } IFS1bits.U2RXIF = false; } void __attribute__ ( ( interrupt, no_auto_psv ) ) _U2ErrInterrupt ( void ) { if ((U2STAbits.OERR == 1)) { U2STAbits.OERR = 0; } IFS4bits.U2ERIF = false; } /** Section: UART Driver Client Routines */ uint8_t UART2_Read( void) { uint8_t data = 0; data = *uart2_obj.rxHead; uart2_obj.rxHead++; if (uart2_obj.rxHead == (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH)) { uart2_obj.rxHead = uart2_rxByteQ; } if (uart2_obj.rxHead == uart2_obj.rxTail) { uart2_obj.rxStatus.s.empty = true; } uart2_obj.rxStatus.s.full = false; return data; } unsigned int UART2_ReadBuffer( uint8_t *buffer, const unsigned int bufLen) { unsigned int numBytesRead = 0 ; while ( numBytesRead < ( bufLen )) { if( uart2_obj.rxStatus.s.empty) { break; } else { buffer[numBytesRead++] = UART2_Read () ; } } return numBytesRead ; } void UART2_Write( const uint8_t byte) { IEC1bits.U2TXIE = false; *uart2_obj.txTail = byte; uart2_obj.txTail++; if (uart2_obj.txTail == (uart2_txByteQ + UART2_CONFIG_TX_BYTEQ_LENGTH)) { uart2_obj.txTail = uart2_txByteQ; } uart2_obj.txStatus.s.empty = false; if (uart2_obj.txHead == uart2_obj.txTail) { uart2_obj.txStatus.s.full = true; } IEC1bits.U2TXIE = true ; } unsigned int UART2_WriteBuffer( const uint8_t *buffer , const unsigned int bufLen ) { unsigned int numBytesWritten = 0 ; while ( numBytesWritten < ( bufLen )) { if((uart2_obj.txStatus.s.full)) { break; } else { UART2_Write (buffer[numBytesWritten++] ) ; } } return numBytesWritten ; } UART2_TRANSFER_STATUS UART2_TransferStatusGet (void ) { UART2_TRANSFER_STATUS status = 0; if(uart2_obj.txStatus.s.full) { status |= UART2_TRANSFER_STATUS_TX_FULL; } if(uart2_obj.txStatus.s.empty) { status |= UART2_TRANSFER_STATUS_TX_EMPTY; } if(uart2_obj.rxStatus.s.full) { status |= UART2_TRANSFER_STATUS_RX_FULL; } if(uart2_obj.rxStatus.s.empty) { status |= UART2_TRANSFER_STATUS_RX_EMPTY; } else { status |= UART2_TRANSFER_STATUS_RX_DATA_PRESENT; } return status; } uint8_t UART2_Peek(uint16_t offset) { if( (uart2_obj.rxHead + offset) > (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH)) { return uart2_rxByteQ[offset - (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH - uart2_obj.rxHead)]; } else { return *(uart2_obj.rxHead + offset); } } unsigned int UART2_ReceiveBufferSizeGet(void) { if(!uart2_obj.rxStatus.s.full) { if(uart2_obj.rxHead > uart2_obj.rxTail) { return(uart2_obj.rxHead - uart2_obj.rxTail); } else { return(UART2_CONFIG_RX_BYTEQ_LENGTH - (uart2_obj.rxTail - uart2_obj.rxHead)); } } return 0; } unsigned int UART2_TransmitBufferSizeGet(void) { if(!uart2_obj.txStatus.s.full) { if(uart2_obj.txHead > uart2_obj.txTail) { return(uart2_obj.txHead - uart2_obj.txTail); } else { return(UART2_CONFIG_TX_BYTEQ_LENGTH - (uart2_obj.txTail - uart2_obj.txHead)); } } return 0; } bool UART2_ReceiveBufferIsEmpty (void) { return(uart2_obj.rxStatus.s.empty); } bool UART2_TransmitBufferIsFull(void) { return(uart2_obj.txStatus.s.full); } UART2_STATUS UART2_StatusGet (void) { return U2STA; } /** End of File */ |
|
|
|
比起MySil,我更像是一个原教旨主义者和自我实现者,所以带着一点盐。不过,我认为Mysil会同意,看看MCC正在生成的代码非常重要,看看它在这个部门所做的事情。首先,您需要决定如何控制输出的位置。这个讨论大约和C语言本身一样古老。我熟悉的大多数实现者都假设您的PrTNF或FPrTNF有一个单一的目的地。来自一些相当陈旧的8位(8051和8086)CPU和多环境测试系统,如果测试失败,需要进行诊断,我更喜欢实现一个变量,它指示所有流获取都被发送到PrTNF结果,这是您需要的最基本的东西。MPLEMTE——Primtf将调用一个函数来输出它创建的字符串,无论您决定的是“STDUT”流。在我的XC16标准库中,这是对WrreWe()的调用,它必须将缓冲区从Prtf复制到UART或UART,这通常是缓冲的。例如,写将调用UART2WruteBuffor()。现在,您需要注意某个时间点…这些序列字符中的每一个都需要大约10位的时间,所以每秒总是有最多的字符数,并且总是可以溢出内部缓冲区。通常情况下,其他事情也会限制,就像你的接收器在你必须处理你发送的东西之前有一个有限的缓冲区大小。
以上来自于百度翻译 以下为原文 I am more of a fundamentalist and self-implementer than MySil, so take this with a grain of salt. I think Mysil will agree, however, that it's very important to look at the code MCC is generating and see what it does in this department. First, you need to decide *how* you want to control where your output goes. That discussion is about as old as the C language itself. Most implementers I'm familiar with assume your printf or fprintf has a single destination. Coming from some rather creaky 8-bit (think 8051 and 8086) CPUs and multi-environment test systems, where diagnostics are required if the test fails, I prefer to implement a variable that indicates which streams get are sent the printf results, all at once. That's the fundamental thing you need to implement -- printf will call a function to output the string of characters it creates to whatever you decide is the "stdout" stream. On my XC16 standard library, that's a call to write(), which then has to copy the buffer from printf to the UART or UARTs, which you will typically buffer. Write would then call UART2WriteBuffer(), for example. Now, you will need to pay attention somewhere to timing...each of those serial characters takes about 10 bit times, so there is always a maximum number of characters per second, and you can always overflow your internal buffer. More often than not, something else also constrains that, like your receiver having a limited buffer size before it must process what you sent. |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1929 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3175 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2227 浏览 5 评论
736浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
507浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
633浏览 0评论
530浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 03:27 , Processed in 1.739240 second(s), Total 114, Slave 98 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号