avr模拟串口通讯c语言,AVR单片机模拟串口程序 C语言(占一个定时器和两个IO)...

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

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值