日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] 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

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