當前位置:首頁 > 單片機 > 單片機
[導讀] ProjectName:Methodofauto-baudrateforATmega8Date:2006-June-01Author:EighthArmySystemcrystal:Internal8MHzbyRCCompilerReversion:IARforAVR412AAdditionalinformation:1Embeddedsystemstartupbaudr

ProjectName:Methodofauto-baudrateforATmega8
Date:2006-June-01
Author:EighthArmy

Systemcrystal:Internal8MHzbyRC
CompilerReversion:IARforAVR412A
Additionalinformation:
1Embeddedsystemstartupbaudrateis2400bps.
2HigherbaudrateofPCisnotrecommend.(Ref.BAUD_RATE_ARRAYspecifICation)
3Afterslaverreturns"AA55",itmeansthebaudratesetcompleted.
4Filename:Main.c
Debuggingdata:AA55
*******************************************************************/

#i nclude
#i nclude"INCLUDES.H"
#i nclude"CONSTANTS.H"
#i nclude"FUNCTIONS.H"
#i nclude"VARIABLES.H"

constucharBAUD_RATE_ARRAY[12]={
/*Embeddedstartupvalue->PCRepeatTimes*/
0xA0,0X01,/*2400*/
0xCF,0x00,/*4800->48005Times*/
0x67,0x00,/*9600->96007Times*/
0x33,0x00,/*19200->1920010Times*/
0x19,0x00,/*38400->3840030Times*/
0x10,0x00/*57600->5760017Times*/
};

/******SuperLoopbody*******************************************/
voidmain(void){
InitialSystem();
while(1)
{
if(!(ucStatusProgram&bSET_BAUD))
{
if(uiTenor&bRECEIVED)
{
uiTenor&=~bRECEIVED;
if(!Judge(&uCCommunicatorBuffer[0]))
{
ExchangeBaudRate((uchar*)&BAUD_RATE_ARRAY[ucSearch]);
ucSearch+=2;
}
else
{
PORTB|=(1<ucStatusProgram|=bSET_BAUD;
TransmitData(ucCommunicatorBuffer,2);
}
}
}
else
{
if(uiTenor&bRECEIVED)
{
uiTenor&=~bRECEIVED;
PORTB^=(1<TransmitData(ucCommunicatorBuffer,ucCommunicatorBuffer[1]);
}
}
}
}
/*******************************************************************
@Fn:InitialSystem()
@Br:Initializationofsystem
@Pa:None
@Rt:None
*******************************************************************/
voidInitialSystem(void){
_DI();
ConfigTimerSystem();
ConfigParallelPort();
ConfigSerialPort();
ucSearch=0;
_EI();
}
/*******************************************************************
@Fn:Delay_mS()
@Br:Non-InterruptonemilliSeconddelay
@Pa:uiMS
@Rt:None
*******************************************************************/
voidDelay_mS(uintuiMS){
ulongulMultiplex;
ulMultiplex=(ulong)uiMS*(ulong)8;
while(ulMultiplex--);
}
/*******************************************************************
@Fn:ConfigSerialPort()
@Br:ConfigurationofMCU
@Pa:None
@Rt:None
*******************************************************************/
voidConfigSerialPort(void){
UCSRA=(1<UBRRH=0x01;
UBRRL=0xA0;/*2400bps@8MHz*/
UCSRB=(1<UCSRC=(1<}
/*******************************************************************
@Fn:ConfigTimerSystem()
@Br:ConfigurationofTIMERonsystem
@Pa:None
@Rt:None
*******************************************************************/
voidConfigTimerSystem(void){
TCCR0=(1<TCNT0=0X00;
TIMSK=(1<}
/*******************************************************************
@Fn:ConfigTimerSystem()
@Br:Configurationofoutputport
@Pa:None
@Rt:None
*******************************************************************/
voidConfigParallelPort(void){
PORTB=0xFE;/*Setofall*/
DDRB=0xFF;/*Settooutputmodeofall*/
}
/*******************************************************************
@Fn:TransmitData()
@Br:Sendaframontoserial-bus
@Pa:ucpDataAddress:Pointofdatabuffer
ucLength:Lengthofdata
@Rt:None
*******************************************************************/
voidTransmitData(uchar*ucpDataAddress,ucharucLength){
while(ucLength)
{
while(!(UCSRA&(1<UDR=*ucpDataAddress++;
ucLength--;
}
}
/*******************************************************************
@Fn:ExchangeBaudRate()
@Br:Exchangevaluesformodifybaudrate
@Pa:ucpChar:Charactervalue
@Rt:None
*******************************************************************/
voidExchangeBaudRate(uchar*ucpChar){
UCSRB&=~(1<UBRRL=*ucpChar++;
UBRRH=*ucpChar++;
UCSRB=(1<}
/*******************************************************************
@Fn:Judge()
@Br:Judgebaudrateaccordingtothereceiveddata
@Pa:ucpCharacter:Pointerofreceiveddatabuffer
@Rt:1:Right0:Error
*******************************************************************/
ucharJudge(uchar*ucpCharacter){
if((*ucpCharacter++!=CHAR0)||(*ucpCharacter++!=CHAR1))returnFAILURE;
else
returnSUCCESS;
}

/*Filename:INTERRUPTS.H*/
#i nclude
#i nclude"includes.h"
#i nclude"CONSTANTS.H"
#i nclude"FUNCTIONS.H"
#i nclude"GLOBALS.H"

/*******************************************************************
@Fn:T0OVERFLOW_Handler
@Br:ServiceofTimer_0interrupt
@Pa:None
@Rt:None
*******************************************************************/
#pragmavector=TIMER0_OVF_vect
__interruptvoidT0OVERFLOW_Handler(void){
TCNT0=0;
}
/*******************************************************************
@Fn:USART_RX
@Br:ServiceofUSARTinterrupt
@Pa:None
@Rt:None
*******************************************************************/
#pragmavector=USART_RXC_vect
__interruptvoidUSART_RX(void){
ucCommunicatorBuffer[ucReceiveCounter++]=UDR;
if(!(ucStatusProgram&bSET_BAUD))
{
if(ucReceiveCounter>1)
{
ucReceiveCounter=0;
uiTenor|=bRECEIVED;
}
}
else
{
if(ucReceiveCounter>2)
{
if(ucReceiveCounter>=ucCommunicatorBuffer[1])
{
ucReceiveCounter=0;
uiTenor|=bRECEIVED;
}
}
}
}

#ifndefCONSTANTS_H
#defineCONSTANTS_H

/******SystemMacro**********************************************************/
#define_EI()SREG|=0X80
#define_DI()SREG&=~0X80
#defineSLEEP()MCUCR|=(1<
/******StatusMacro**********************************************************/
#definebSET_BAUD0x01

/******TenorMacro***********************************************************/
#definebRECEIVED0x01

/******ApplicationMacro*****************************************************/
#defineINDICATEPB0
#defineCHAR00xAA
#defineCHAR10x55

#endif

#ifndefFUNCTIONS_H
#defineFUNCTIONS_H

/******Main.c****************************************************************/
voidInitialSystem(void);
voidDelay_mS(uintuiMS);
voidConfigSerialPort(void);
voidConfigTimerSystem(void);
voidConfigParallelPort(void);
voidTransmitData(uchar*ucpDataAddress,ucharucLength);
voidExchangeBaudRate(uchar*ucpChar);
ucharJudge(uchar*ucpCharacter);

#endif

#ifndefVERIABLES_H
#defineVERIABLES_H

ucharucReceiveCounter;
ucharucCommunicatorBuffer[64];
uintuiTenor;
ucharucStatusProgram;
ucharucSearch;

#endif

#ifndefGLOBALS_H
#defineGLOBALS_H

externucharucReceiveCounter;
externucharucCommunicatorBuffer[64];
externuintuiTenor;
externucharucStatusProgram;
externucharucSearch;

#endif

#ifndefINCLUDES_H
#defineINCLUDES_H

#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude

#defineMax(A,B)(A>B:A?B)
#defineMin(A,B)(A
#ifndefuchar
#defineucharunsignedchar
#endif

#ifndefuint
#defineuintunsignedint
#endif

#ifndefulong
#defineulongunsignedlong
#endif

#ifndefSUCCESS
#defineSUCCESS1
#endif

#ifndefFAILURE
#defineFAILURE0
#endif
#endif

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

9月2日消息,不造車的華為或將催生出更大的獨角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數字化轉型技術解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關鍵字: AWS AN BSP 數字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術公司SODA.Auto推出其旗艦產品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關鍵字: 汽車 人工智能 智能驅動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據媒體報道,騰訊和網易近期正在縮減他們對日本游戲市場的投資。

關鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數據產業(yè)博覽會開幕式在貴陽舉行,華為董事、質量流程IT總裁陶景文發(fā)表了演講。

關鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數據產業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數字世界的話語權最終是由生態(tài)的繁榮決定的。

關鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經營業(yè)績穩(wěn)中有升 落實提質增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領增長 以科技創(chuàng)新為引領,提升企業(yè)核心競爭力 堅持高質量發(fā)展策略,塑強核心競爭優(yōu)勢...

關鍵字: 通信 BSP 電信運營商 數字經濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術學會聯合牽頭組建的NVI技術創(chuàng)新聯盟在BIRTV2024超高清全產業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現場 NVI技術創(chuàng)新聯...

關鍵字: VI 傳輸協議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯合招商會上,軟通動力信息技術(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關鍵字: BSP 信息技術
關閉
關閉