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

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]#include#include#defineRXB81#defineTXB80#defineUPE2#defineOVR3#defineFE4#defineUDRE5#defineRXC7#defineFRAMING_ERROR(1

#include

#include

#defineRXB81

#defineTXB80

#defineUPE2

#defineOVR3

#defineFE4

#defineUDRE5

#defineRXC7

#defineFRAMING_ERROR(1<

#definePARITY_ERROR(1<

#defineDATA_OVERRUN(1<

#defineDATA_REGISTER_EMPTY(1<

#defineRX_COMPLETE(1<

//USARTReceiverbuffer

#defineRX_BUFFER_SIZE8

charrx_buffer[RX_BUFFER_SIZE];

unsignedcharnCount=0;//定義串口接收計(jì)數(shù)變量

#ifRX_BUFFER_SIZE<256

unsignedcharrx_wr_index,rx_rd_index,rx_counter;

#else

unsignedintrx_wr_index,rx_rd_index,rx_counter;

#endif

//ThisflagissetonUSARTReceiverbufferoverflow

bitrx_buffer_overflow;

//USARTReceiverinterruptserviceroutine

interrupt[USART_RXC]voidusart_rx_isr(void)

{

charstatus,data;

status=UCSRA;

data=UDR;

if((status&(FRAMING_ERROR|PARITY_ERROR|DATA_OVERRUN))==0)

{

//printf("interruptiontriged!rn");//插樁測試,驗(yàn)證中斷服務(wù)程序處于有效工作狀態(tài)

nCount++;//接收到數(shù)據(jù)時(shí),每接收一個(gè),接收計(jì)數(shù)加1

rx_buffer[rx_wr_index]=data;

if(++rx_wr_index==RX_BUFFER_SIZE)rx_wr_index=0;

if(++rx_counter==RX_BUFFER_SIZE)

{

rx_counter=0;

rx_buffer_overflow=1;

};

};

}

#ifndef_DEBUG_TERMINAL_IO_

//GetacharacterfromtheUSARTReceiverbuffer

#define_ALTERNATE_GETCHAR_

#pragmaused+

chargetchar(void)

{

chardata;

while(rx_counter==0);

data=rx_buffer[rx_rd_index];

if(++rx_rd_index==RX_BUFFER_SIZE)rx_rd_index=0;

#asm("cli")

--rx_counter;

#asm("sei")

returndata;

}

#pragmaused-

#endif

//StandardInput/Outputfunctions

//Declareyourglobalvariableshere

voidmain(void)

{

//Declareyourlocalvariableshere

unsignedchartemp_data=0;

//Input/OutputPortsinitialization

//PortAinitialization

//Func7=InFunc6=InFunc5=InFunc4=InFunc3=InFunc2=InFunc1=InFunc0=In

//State7=TState6=TState5=TState4=TState3=TState2=TState1=TState0=T

PORTA=0x00;

DDRA=0x00;

//PortBinitialization

//Func7=InFunc6=InFunc5=InFunc4=InFunc3=InFunc2=InFunc1=InFunc0=In

//State7=TState6=TState5=TState4=TState3=TState2=TState1=TState0=T

PORTB=0x00;

DDRB=0x00;

//PortCinitialization

//Func7=InFunc6=InFunc5=InFunc4=InFunc3=InFunc2=InFunc1=InFunc0=In

//State7=TState6=TState5=TState4=TState3=TState2=TState1=TState0=T

PORTC=0x00;

DDRC=0x00;

//PortDinitialization

//Func7=InFunc6=InFunc5=InFunc4=InFunc3=InFunc2=InFunc1=InFunc0=In

//State7=TState6=TState5=TState4=TState3=TState2=TState1=TState0=T

PORTD=0x00;

DDRD=0x00;

//Timer/Counter0initialization

//Clocksource:SystemClock

//Clockvalue:Timer0Stopped

//Mode:Normaltop=FFh

//OC0output:Disconnected

TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

//Timer/Counter1initialization

//Clocksource:SystemClock

//Clockvalue:Timer1Stopped

//Mode:Normaltop=FFFFh

//OC1Aoutput:Discon.

//OC1Boutput:Discon.

//NoiseCanceler:Off

//InputCaptureonFallingEdge

//Timer1OverflowInterrupt:Off

//InputCaptureInterrupt:Off

//CompareAMatchInterrupt:Off

//CompareBMatchInterrupt:Off

TCCR1A=0x00;

TCCR1B=0x00;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;

//Timer/Counter2initialization

//Clocksource:SystemClock

//Clockvalue:Timer2Stopped

//Mode:Normaltop=FFh

//OC2output:Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

//ExternalInterrupt(s)initialization

//INT0:Off

//INT1:Off

//INT2:Off

MCUCR=0x00;

MCUCSR=0x00;

//Timer(s)/Counter(s)Interrupt(s)initialization

TIMSK=0x00;

//USARTinitialization

//CommunicationParameters:8Data,1Stop,NoParity

//USARTReceiver:On

//USARTTransmitter:On

//USARTMode:Asynchronous

//USARTBaudRate:9600

UCSRA=0x00;

UCSRB=0x98;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33;

//AnalogComparatorinitialization

//AnalogComparator:Off

//AnalogComparatorInputCapturebyTimer/Counter1:Off

ACSR=0x80;

SFIOR=0x00;

//Globalenableinterrupts

#asm("sei")

SREG|=0x80;//開全局中斷

while(1)

{

//Placeyourcodehere

if(nCount>0)//判斷是否有接收數(shù)據(jù)

{

nCount--;//處理過的數(shù)據(jù),減少數(shù)據(jù)計(jì)數(shù)

temp_data=getchar();//獲取接收字符

if(temp_data<='9'&&temp_data>='0')

{

temp_data=temp_data-38;

printf("%d",temp_data);

}

elseif(temp_data<='Z'&&temp_data>='A')

{temp_data=temp_data+32;

printf("%c",temp_data);

}

elseif(temp_data<='z'&&temp_data>='a')

{temp_data=temp_data-32;

printf("%c",temp_data);}

else

{printf("errorn");}

}

};

}


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