www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] /* Code adapted from Atmel AVRApplICation Note AVR306* Interrupt mode driver forUART.*/#include #include #include "uart.h"/* IMPORTANT: these vector numbers are for 8515! If you use other

/* Code adapted from Atmel AVRApplICation Note AVR306
* Interrupt mode driver forUART.
*/
#include
#include
#include "uart.h"

/* IMPORTANT: these vector numbers are for 8515! If you use other devices

* you must change them to the different set of numbers.
*
* UART_RX_interrupt set to UART, Rx Complete
* UART_TX_interrupt set to UART Data Register Empty
*/

#pragma interrupt_handler UART_RX_interrupt:10 UART_TX_interrupt:11

/* UART Buffer Defines */
#define UART_RX_BUFFER_SIZE 128 /* 1,2,4,8,16,32,64,128 or 256 bytes */
#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1 )
#define UART_TX_BUFFER_SIZE 128 /* 1,2,4,8,16,32,64,128 or 256 bytes */
#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1 )

#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK )
#error RX buffer size is not a power of 2
#endif

/* Static Variables */
static unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE];
static volatile unsigned char UART_RxHead;
static volatile unsigned char UART_RxTail;
static unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE];
static volatile unsigned char UART_TxHead;
static volatile unsigned char UART_TxTail;

/* initialize UART */
void InitUART( unsigned char baudrate )
{
unsigned char x;
UBRR = baudrate; /* set the baud rate */
/* enable UART receiver and transmitter, and
receive interrupt */
UCR = ( (1<x = 0; /* flush receive buffer */
UART_RxTail = x;
UART_RxHead = x;
UART_TxTail = x;
UART_TxHead = x;
}

/* interrupt handlers */
void UART_RX_interrupt( void )
{
unsigned char data;
unsigned char tmphead;
data = UDR; /* read the received data */
/* calculate buffer index */
tmphead = ( UART_RxHead 1 ) & UART_RX_BUFFER_MASK;
UART_RxHead = tmphead; /* store new index */
if ( tmphead == UART_RxTail )
{
/* ERROR! Receive buffer overflow */
}
UART_RxBuf[tmphead] = data; /* store received data in buffer */
}

void UART_TX_interrupt( void )
{
unsigned char tmptail;

/* check if all data is transmitted */
if ( UART_TxHead != UART_TxTail )
{
/* calculate buffer index */
tmptail = ( UART_TxTail 1 ) & UART_TX_BUFFER_MASK;
UART_TxTail = tmptail; /* store new index */
UDR = UART_TxBuf[tmptail]; /* start transmition */
}
else
{
UCR &= ~(1<}
}

/* Read and write functions */
unsigned char ReceiveByte( void )
{
unsigned char tmptail;

while ( UART_RxHead == UART_RxTail ) /* wait for incomming data */
;
tmptail = ( UART_RxTail 1 ) & UART_RX_BUFFER_MASK;/* calculate buffer index */
UART_RxTail = tmptail; /* store new index */
return UART_RxBuf[tmptail]; /* return data */
}

void TransmitByte( unsigned char data )
{
unsigned char tmphead;
/* calculate buffer index */
tmphead = ( UART_TxHead 1 ) & UART_TX_BUFFER_MASK;
/* wait for free sPACe in buffer */

while ( tmphead == UART_TxTail )
;
UART_TxBuf[tmphead] = data; /* store data in buffer */
UART_TxHead = tmphead; /* store new index */
UCR |= (1<}

unsigned char DataInReceiveBuffer( void )
{
return ( UART_RxHead != UART_RxTail );
/* return 0 (FALSE) if the receive buffer is empty */
}

#ifdef TEST
/* main - a simple test program*/
void main( void )
{
InitUART( 25 ); /* set the baudrate to 9600 bps using a 4MHzcrystal */
_SEI(); /* enable interrupts => enable UART interrupts */
while ( 1 ) /* forever */
{
TransmitByte( ReceiveByte() ); /* echo the received character */
}
}
#endif


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

在這篇文章中,小編將為大家?guī)?lái)單片機(jī)的相關(guān)報(bào)道。如果你對(duì)本文即將要講解的內(nèi)容存在一定興趣,不妨繼續(xù)往下閱讀哦。

關(guān)鍵字: 單片機(jī) AVR PIC

串口全稱是串行接口(Serial Interface),串口通訊指僅用一對(duì)傳輸線就能將數(shù)據(jù)以比特位進(jìn)行傳輸?shù)囊环N通訊方式。盡管串口通訊必按字節(jié)傳輸?shù)牟⑿型ㄐ怕?,但是串口可以在僅用兩根線的情況下完成數(shù)據(jù)傳輸,大大降低了成本...

關(guān)鍵字: 串口 UART

隨著電腦技術(shù)的發(fā)展,一些老的設(shè)備在新電腦上不能被使用,主要原因是不管是臺(tái)式電腦,還是筆記本電腦,都很少有串口接口,也就是我們常說(shuō)的COM口。好在這些設(shè)備都有USB接口,不妨通過(guò)接口轉(zhuǎn)換的方式,使我們的設(shè)備在新電腦上重新被...

關(guān)鍵字: 串口 USB

串口:串口是一個(gè)泛稱,UART、TTL、RS232、RS485都遵循類似的通信時(shí)序協(xié)議,因此都被通稱為串口。串口通訊應(yīng)用是工控人必須掌握的一個(gè)技能,幾乎在每一個(gè)項(xiàng)目中都會(huì)用到,今天我們就來(lái)詳細(xì)比較一下它們究竟有何區(qū)別。

關(guān)鍵字: 串口 協(xié)議

在嵌入式開(kāi)發(fā)過(guò)程中,許多系統(tǒng)通常使用串口驅(qū)動(dòng)來(lái)滿足通信要求,但在實(shí)際應(yīng)用中,使用SPI通信方式會(huì)更加高效和快捷。

關(guān)鍵字: 串口 驅(qū)動(dòng)

串口WiFi模塊作為新一代嵌入式WiFi模塊,因其體積小、功耗低的特點(diǎn),廣泛應(yīng)用于物聯(lián)網(wǎng)、智能家居等領(lǐng)域。

關(guān)鍵字: 串口 WiFi模塊 嵌入式

在現(xiàn)代嵌入式系統(tǒng)設(shè)計(jì)中,F(xiàn)PGA(現(xiàn)場(chǎng)可編程門(mén)陣列)的靈活性和可重構(gòu)性使其成為許多應(yīng)用的理想選擇。而在FPGA的開(kāi)發(fā)和部署過(guò)程中,如何實(shí)現(xiàn)遠(yuǎn)程升級(jí)和故障恢復(fù)成為了一個(gè)重要議題。本文將詳細(xì)探討如何通過(guò)BPI FLASH實(shí)現(xiàn)...

關(guān)鍵字: FPGA 串口 MultiBoot 嵌入式系統(tǒng)

在現(xiàn)代電子設(shè)計(jì)中,F(xiàn)PGA(現(xiàn)場(chǎng)可編程門(mén)陣列)因其高度的靈活性和可重構(gòu)性,成為眾多領(lǐng)域的核心組件。特別是在需要?jiǎng)討B(tài)更新或調(diào)整系統(tǒng)功能的場(chǎng)景中,F(xiàn)PGA的串口升級(jí)和MultiBoot功能顯得尤為重要。本文將深入探討FPGA...

關(guān)鍵字: FPGA 串口 MultiBoot

之前有個(gè)同事因?yàn)橛么诓樵兎绞桨l(fā)送數(shù)據(jù),被我說(shuō)了一頓,明明有DMA資源,竟然放著不用,對(duì)于魚(yú)鷹這種性能強(qiáng)迫癥來(lái)說(shuō),肯定無(wú)法忍受,所以當(dāng)時(shí)就和他說(shuō),有時(shí)間你把它改一下。誰(shuí)知道過(guò)了好幾個(gè)月他才有時(shí)間弄這個(gè),然后還是出了問(wèn)題,...

關(guān)鍵字: DMA 串口

自動(dòng)電壓調(diào)節(jié)器 (AVR) 用于通過(guò)補(bǔ)償輸入電壓的任何波動(dòng)來(lái)調(diào)節(jié)供電電壓水平。AVR 也通常稱為電壓穩(wěn)定器,可用于許多工業(yè)和住宅應(yīng)用。例如,AVR 用于船舶發(fā)電機(jī)組、應(yīng)急電源和石油鉆井平臺(tái),以在電力需求波動(dòng)期間穩(wěn)定電壓水...

關(guān)鍵字: AVR 電壓調(diào)節(jié)
關(guān)閉