testcode:
我用Procyon的uartsw做模拟串口,M8,7.3728MHz。编译通过,然后在pro***s里模拟,PB1发送的都是0x00。搞不清楚要怎么用这个uartsw库。
代码如下,请帮忙看一下,调用是不是有问题。
/* uartswconf.h */
#ifndef UARTSWCONF_H
#define UARTSWCONF_H
// constants/macros/typdefs
#define UARTSW_RX_BUFFER_SIZE 0x20 ///< UART receive buffer size in bytes
#define UARTSW_INVERT ///< define to invert polarity of RX/TX signals
// when non-inverted, the serial line is appropriate for passing though
// an RS232 driver like the MAX232. When inverted, the serial line can
// directly drive/receive RS232 signals to/from a DB9 connector. Be sure
// to use a current-limiting resistor and perhaps a diode-clamp circuit when
// connecting incoming RS232 signals to a microprocessor I/O pin.
// if non-inverted, the serial line idles high (logic 1) between bytes
// if inverted, the serial line idles low (logic 0) between bytes
// UART transmit pin defines
#define UARTSW_TX_PORT PORTB ///< UART Transmit Port
#define UARTSW_TX_DDR DDRB ///< UART Transmit DDR
#define UARTSW_TX_PIN PB1 ///< UART Transmit Pin
// UART receive pin defines
// This pin must correspond to the
// Timer1 Input Capture (ICP or IC1) pin for your processor
#define UARTSW_RX_PORT PORTB ///< UART Receive Port
#define UARTSW_RX_DDR DDRB ///< UART Receive DDR
#define UARTSW_RX_PORTIN PINB ///< UART Receive Port Input
#define UARTSW_RX_PIN PB0 ///< UART Receive Pin
#endif
====================
/* main.c */
//----- Include Files ---------------------------------------------------------
#include // include I/O definitions (port names, pin names, etc)
#include // include interrupt support
#include "global.h" // include our global settings
#include "uartsw.h" // include uart function library
#include "rprintf.h" // include printf function library
//#include "timer.h" // include timer function library (timing, PWM, etc)
void rprintfTest(void);
//----- Begin Code ------------------------------------------------------------
int main(void)
{
// initialize our libraries
// initialize the UART (serial port)
uartswInit();
uartswInitBuffers();
// set the baud rate of the UART for our debug/reporting output
uartswSetBaudRate(9600);
// initialize rprintf system
// - use uartSendByte as the output for all rprintf statements
// this will cause all rprintf library functions to direct their
// output to the uart
// - rprintf can be made to output to any device which takes characters.
// You must write a function which takes an unsigned char as an argument
// and then pass this to rprintfInit like this: rprintfInit(YOUR_FUNCTION);
rprintfInit(uartswSendByte);
// run the test
rprintfTest();
return 0;
}
void rprintfTest(void)
{
// print single characters
rprintfChar('H');
rprintfChar('e');
rprintfChar('l');
rprintfChar('l');
rprintfChar('o');
rprintfChar(' ');
rprintfChar('W');
rprintfChar('o');
rprintfChar('r');
rprintfChar('l');
rprintfChar('d');
// print a carriage return, line feed combination
//rprintfCRLF();
// note that using rprintfCRLF() is more memory-efficient than
// using rprintf("\r\n"), especially if you do it repeatedly
}