SlideShare a Scribd company logo
1 of 10
Download to read offline
임베디드임베디드 마이크로프로세서마이크로프로세서
프로그래밍프로그래밍 실전실전
제작제작 :: 네네 로로 테테 크크
강의강의 :: 김김 종종 형형
--22--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
ATMEGA128 USARTATMEGA128 USART 직렬통신직렬통신
1. USART의 개요
2. USART의 레지스터
3. USART 실습
--33--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-1 USART의 개요
⊙ 2개의 USART(Universal Synchronous and Asynchronous Receive and Transmitter) 구성
- 외부 디바이스와 직렬로 인터페이스를 통해 데이터를 송수신할 수 있게 해 줌
(외부 디바이스는 다른 마이컴 혹은 PC)
⊙ USART0, USART1
⊙ 전이중 통신 및 멀티 프로세서 통신가능
⊙ 동기식 전송 모드
- 마스터 동작의 경우 전송속도는 내부 클럭사용
- 슬레이브 동작의 경우 XCKn 단자로 입력되는 외부 클럭신호에 의해 동작한다.
⊙ 비동기식 전송 모드에서는 항상 내부의 시스템 클럭에 의하여 보레이트가 결정된다.
⊙ 송신 완료(TX Complete), 송신 데이터 레지스터 준비완료(TX Data Register Empty), 수신
완료(RX Complete) 등 3가지의 인터럽트 사용 가능
--44--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-2 USART의 레지스터
⊙ USART I/0 데이터 레지스터 (UDR0, UDR1)
: USART0 또는 USART1 포트의 송수신 데이터 버퍼의 기능
RXB0[7..0]UDR0 (READ)
Init Value
UDR0 (Write)
BIT
00000000
TXB0[7..0]
01234567
RXB1[7..0]UDR1 (READ)
Init Value
UDR1 (Write)
BIT
00000000
TXB1[7..0]
01234567
--55--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-2 USART의 레지스터
⊙ USART 제어 및 상태 레지스터 A (UCSR0A, UCSR1A)
: USART0, USART1 포트의 송수신 동작제어 ,송수신 상태 저장 기능
- RXCn (USARTn Receiver Complete): 수신버퍼의 상태 플래그
- TXCn (USARTn Transmit Complete): 송신버퍼의 상태 플래그
- UDREn (USARTn Data Register Empty) : 새로운 송신 데이터를 받기 위한 상태 플래그
- FEn (Frame Error) : 수신 프레임 에러 상태 플래그
- DORn (Data Overrun Error) : 수신동작 오버런 에러 상태 플래그
- UPEn (USARTn Parity Error)
- U2Xn (Double the USARTn Transmission Speed) : 비동기 모드에서만 유효하며, 클럭의
분주비를 16에서 8로 낮추어 전송속도를 2배 높이는 기능
- MPCMn (USARTn Multi-Processor Communication Mode)
MPCMnU2XnUPEnDORnFEnUDREnTXCnRXCnUCSRnA
Init Value
BIT
00000000
01234567
--66--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-2 USART의 레지스터
⊙ USART 제어 및 상태 레지스터 B (UCSR0B, UCSR1B)
: USART0, USART1 포트의 송수신 동작제어, 전송데이터를 9비트로 설정한 경우에 전송
데이터의 9번째 비트값을 저장하는 기능을 수행
- RXCIEn (USARTn RX Complete Interrupt Enable): 수신완료 인터럽트
- TXCIEn (USARTn TX Complete Interrupt Enable): 송신완료 인터럽트
- UDRIEn (USARTn Data Register Empty Interrupt Enable) : 송신 데이터 레지스터 준비완료 인터럽트
- RXENn (USARTN Receiver Enable) : 수신부 동작허용, 직렬 데이터 수신단자로 동작하도록 설정하며,
FEn , DORn, UPEn 의 동작을 유효하게 함
- TXENn (USARTn Transmitter Enable) : 송신부 동작허용
- UCSZn2 (USARTn Character Size) : UCSRnC 레지스터의 UCSZn1~0 비트와 함께 전송 문자의 비트수를
설정
- RXB8n (USARTn Receiver Data 8Bit) : 전송문자가 9비트로 설정된 경우 수신된 문자의 9번째 비트
(MSB)를 저장. 반드시 UDRn 레지스터 보다 먼저 읽어야 함
- TXB8n (USARTn Transmit Data 8Bit) : 전송문자가 9비트로 설정된 경우 송신할 문자의 9번째 비트
(MSB)를 저장. 반드시 UDRn 레지스터 보다 먼저 라이트되어야 함
TXB8nRXB8nUCSZn2TXENnRXENnUDRIEnTXCIEnRXCIEnUCSRnB
Init Value
BIT
00000000
01234567
--77--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-2 USART의 레지스터
⊙ USART 제어 및 상태 레지스터 C (UCSR0C, UCSR1C)
: 송수신 동작 제어
- UMSELn (USARTn Mode Select) : 동기전송모드 시 1, 비동기 전송모드 시 0
- UPMn1~0 (USARTn Parity Mode) : 패리티 모드 설정
- USBSn (USARTn Stop Bit Select)
USBSn = 0 , Stop Bit 1 USBSn = 1, Stop Bit
UCPOLnUCSZn0UCSZn1USBSnUPMn0UPMn1UMSELn-UCSRnC
Init Value
BIT
00000000
01234567
ODD PARITY MODE11
EVEN PARITY MODE01
RESERVED10
NO PARITY MODE00
PARITY MODEUPMn0UPMn1
--88--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-2 USART의 레지스터
⊙ USART 제어 및 상태 레지스터 C (UCSR0C, UCSR1C)
- UCSZn1~0 (USARTn Character Size) : UCSRnB 레지스터의 UCSZn2 비트와 함께 전송 문자의 데이터
비트수를 설정
- UCPOLn (USARTn Clock Polarity) : 동기 전송모드의 슬레이브 동작에서만 유효
UCPOLn = 0, 송신데이터는 XCKn 클럭의 상승 에지에서는 새로운 값이 출력되고, 수신 데이터는 XCKn
클럭의 하강 에지에서 검출
UCPOLn = 1 이면 송신 데이터는 XCKn 클럭의 하강 에지에서 새로운 값이 출력되고 수신 데이터는 XCKn
클럭의 상승 에지에서 검출
9bit111
Reserve011
Reserve101
Reserve001
8bit110
7bit010
6bit100
5bit000
Character SizeUCSZn0UCSZn1UCSZn2
--99--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-2 USART의 레지스터
⊙ USART BAUD RATE REGISTER (UBRR0H/L , UBRR1H/L)
: 16비트 중 12비트 만 유효, 송수신 속도를 설정, 클럭의 분주비로 작용하여 직렬포트의 전송속도인
보레이트를 결정
UBRRn[11:8]----UBRRnH
UBRRn[7:0]UBRRnL
Init Value
BIT
00000000
01234567
-0.79%34+2.12%1657,600
+0.16%51+0.16%2538,400
+0.64%68-0.79%3428,800
+0.16%103+0.16%5119,200
-0.08%138+0.64%6814,400
+0.16%207+0.16%1039600
-0.08%416+0.16%2074800
+0.04%832-0.08%4162400
ErrorUBRRnErrorUBRRn
비동기 2배속 모드
(U2Xn=1)
비동기 일반모드
(U2Xn=0)Baud Rate
(bps) / 16MHz
--1010--20062006--0404--0505
Embedded AVR ProgrammingEmbedded AVR Programming
1-3 USART0 실습 1
☞ 송신은 폴링 방식, 수신은 인터럽트 방식으로 PC와 연결하여 USART0로 데이터를 받으면
그 받은 데이터를 전송하는 프로그램
void main(void)
{
// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No
Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud rate: 9600
UCSR0A=0x00;
UCSR0B=0x98;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x67; //16MHz일 때
//UBRR0L=0x33; //8MHz일 때
#asm("sei")
while (1)
; // do nothing
}
#include <mega128.h>
#include <delay.h>
#define UDRE0 5
void TxData(char data)
{
while(!(UCSR0A & (1<<UDRE0)));// UDRE0 CHECK
//while((UCSR0A & 0x20) == 0X00);
UDR0 = data;
}
interrupt [USART0_RXC] void usart0_rx_isr(void)
{
char status,data;
status=UCSR0A;
data=UDR0;
TxData(data);
}

More Related Content

Viewers also liked

2013 mcu( 마이크로컨트롤러 ) 수업자료 2
2013 mcu( 마이크로컨트롤러 ) 수업자료 22013 mcu( 마이크로컨트롤러 ) 수업자료 2
2013 mcu( 마이크로컨트롤러 ) 수업자료 2진우 김
 

Viewers also liked (6)

2013 mcu( 마이크로컨트롤러 ) 수업자료 2
2013 mcu( 마이크로컨트롤러 ) 수업자료 22013 mcu( 마이크로컨트롤러 ) 수업자료 2
2013 mcu( 마이크로컨트롤러 ) 수업자료 2
 
Avr lecture4
Avr lecture4Avr lecture4
Avr lecture4
 
Avr lecture3
Avr lecture3Avr lecture3
Avr lecture3
 
Avr lecture2
Avr lecture2Avr lecture2
Avr lecture2
 
Avr lecture7
Avr lecture7Avr lecture7
Avr lecture7
 
Avr lecture8
Avr lecture8Avr lecture8
Avr lecture8
 

More from 봉조 김

창의·융합·문제해결을 배우는 메이커 활동 리스트
창의·융합·문제해결을 배우는 메이커 활동 리스트창의·융합·문제해결을 배우는 메이커 활동 리스트
창의·융합·문제해결을 배우는 메이커 활동 리스트봉조 김
 
Softboxcoding brand name
Softboxcoding brand nameSoftboxcoding brand name
Softboxcoding brand name봉조 김
 
Weather station performance sharing
Weather station performance sharingWeather station performance sharing
Weather station performance sharing봉조 김
 
Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서
Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서
Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서봉조 김
 
Softbox coding - raspberrypi3 b+ 2019 Lecture File
Softbox coding - raspberrypi3 b+ 2019 Lecture File Softbox coding - raspberrypi3 b+ 2019 Lecture File
Softbox coding - raspberrypi3 b+ 2019 Lecture File 봉조 김
 
Sw education and maker
Sw education and makerSw education and maker
Sw education and maker봉조 김
 
소프트박스 라즈베리파이 교육키트 개발환경 설정
소프트박스 라즈베리파이 교육키트 개발환경 설정소프트박스 라즈베리파이 교육키트 개발환경 설정
소프트박스 라즈베리파이 교육키트 개발환경 설정봉조 김
 
Expansion of maker culture and promotion of maker activity
Expansion of maker culture and promotion of maker activityExpansion of maker culture and promotion of maker activity
Expansion of maker culture and promotion of maker activity봉조 김
 
2018년 따복공동체 활동 공유 - 과천 디지털 창작집단
2018년 따복공동체 활동 공유 - 과천 디지털 창작집단2018년 따복공동체 활동 공유 - 과천 디지털 창작집단
2018년 따복공동체 활동 공유 - 과천 디지털 창작집단봉조 김
 
강사료 원천징수 관련 설명자료
강사료 원천징수 관련 설명자료강사료 원천징수 관련 설명자료
강사료 원천징수 관련 설명자료봉조 김
 
Softbox review and quickstartguide-20180926
Softbox review and quickstartguide-20180926Softbox review and quickstartguide-20180926
Softbox review and quickstartguide-20180926봉조 김
 
디지털창작집단 활동 소개문서
디지털창작집단 활동 소개문서디지털창작집단 활동 소개문서
디지털창작집단 활동 소개문서봉조 김
 
Softbox arduino software education, softbox 소프트박스 제품소개서
Softbox arduino software education, softbox 소프트박스 제품소개서 Softbox arduino software education, softbox 소프트박스 제품소개서
Softbox arduino software education, softbox 소프트박스 제품소개서 봉조 김
 
Stuffed animals 20180605
Stuffed animals 20180605Stuffed animals 20180605
Stuffed animals 20180605봉조 김
 
20180329 reco computer for maker
20180329 reco computer for maker20180329 reco computer for maker
20180329 reco computer for maker봉조 김
 
2018 donga marathon training schedule
2018 donga marathon training schedule2018 donga marathon training schedule
2018 donga marathon training schedule봉조 김
 
2017 marathob trainning schedule
2017 marathob trainning schedule2017 marathob trainning schedule
2017 marathob trainning schedule봉조 김
 
Marathon safe guide
Marathon safe guideMarathon safe guide
Marathon safe guide봉조 김
 
사물인터넷서비스와 클라우드
사물인터넷서비스와 클라우드사물인터넷서비스와 클라우드
사물인터넷서비스와 클라우드봉조 김
 
4차 산업혁명과 io t 20170919
4차 산업혁명과 io t  201709194차 산업혁명과 io t  20170919
4차 산업혁명과 io t 20170919봉조 김
 

More from 봉조 김 (20)

창의·융합·문제해결을 배우는 메이커 활동 리스트
창의·융합·문제해결을 배우는 메이커 활동 리스트창의·융합·문제해결을 배우는 메이커 활동 리스트
창의·융합·문제해결을 배우는 메이커 활동 리스트
 
Softboxcoding brand name
Softboxcoding brand nameSoftboxcoding brand name
Softboxcoding brand name
 
Weather station performance sharing
Weather station performance sharingWeather station performance sharing
Weather station performance sharing
 
Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서
Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서
Aircleaner 20190616 - 미세먼지 공기청정기 메이커활동 제안서
 
Softbox coding - raspberrypi3 b+ 2019 Lecture File
Softbox coding - raspberrypi3 b+ 2019 Lecture File Softbox coding - raspberrypi3 b+ 2019 Lecture File
Softbox coding - raspberrypi3 b+ 2019 Lecture File
 
Sw education and maker
Sw education and makerSw education and maker
Sw education and maker
 
소프트박스 라즈베리파이 교육키트 개발환경 설정
소프트박스 라즈베리파이 교육키트 개발환경 설정소프트박스 라즈베리파이 교육키트 개발환경 설정
소프트박스 라즈베리파이 교육키트 개발환경 설정
 
Expansion of maker culture and promotion of maker activity
Expansion of maker culture and promotion of maker activityExpansion of maker culture and promotion of maker activity
Expansion of maker culture and promotion of maker activity
 
2018년 따복공동체 활동 공유 - 과천 디지털 창작집단
2018년 따복공동체 활동 공유 - 과천 디지털 창작집단2018년 따복공동체 활동 공유 - 과천 디지털 창작집단
2018년 따복공동체 활동 공유 - 과천 디지털 창작집단
 
강사료 원천징수 관련 설명자료
강사료 원천징수 관련 설명자료강사료 원천징수 관련 설명자료
강사료 원천징수 관련 설명자료
 
Softbox review and quickstartguide-20180926
Softbox review and quickstartguide-20180926Softbox review and quickstartguide-20180926
Softbox review and quickstartguide-20180926
 
디지털창작집단 활동 소개문서
디지털창작집단 활동 소개문서디지털창작집단 활동 소개문서
디지털창작집단 활동 소개문서
 
Softbox arduino software education, softbox 소프트박스 제품소개서
Softbox arduino software education, softbox 소프트박스 제품소개서 Softbox arduino software education, softbox 소프트박스 제품소개서
Softbox arduino software education, softbox 소프트박스 제품소개서
 
Stuffed animals 20180605
Stuffed animals 20180605Stuffed animals 20180605
Stuffed animals 20180605
 
20180329 reco computer for maker
20180329 reco computer for maker20180329 reco computer for maker
20180329 reco computer for maker
 
2018 donga marathon training schedule
2018 donga marathon training schedule2018 donga marathon training schedule
2018 donga marathon training schedule
 
2017 marathob trainning schedule
2017 marathob trainning schedule2017 marathob trainning schedule
2017 marathob trainning schedule
 
Marathon safe guide
Marathon safe guideMarathon safe guide
Marathon safe guide
 
사물인터넷서비스와 클라우드
사물인터넷서비스와 클라우드사물인터넷서비스와 클라우드
사물인터넷서비스와 클라우드
 
4차 산업혁명과 io t 20170919
4차 산업혁명과 io t  201709194차 산업혁명과 io t  20170919
4차 산업혁명과 io t 20170919
 

Avr lecture6

  • 2. --22--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming ATMEGA128 USARTATMEGA128 USART 직렬통신직렬통신 1. USART의 개요 2. USART의 레지스터 3. USART 실습
  • 3. --33--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-1 USART의 개요 ⊙ 2개의 USART(Universal Synchronous and Asynchronous Receive and Transmitter) 구성 - 외부 디바이스와 직렬로 인터페이스를 통해 데이터를 송수신할 수 있게 해 줌 (외부 디바이스는 다른 마이컴 혹은 PC) ⊙ USART0, USART1 ⊙ 전이중 통신 및 멀티 프로세서 통신가능 ⊙ 동기식 전송 모드 - 마스터 동작의 경우 전송속도는 내부 클럭사용 - 슬레이브 동작의 경우 XCKn 단자로 입력되는 외부 클럭신호에 의해 동작한다. ⊙ 비동기식 전송 모드에서는 항상 내부의 시스템 클럭에 의하여 보레이트가 결정된다. ⊙ 송신 완료(TX Complete), 송신 데이터 레지스터 준비완료(TX Data Register Empty), 수신 완료(RX Complete) 등 3가지의 인터럽트 사용 가능
  • 4. --44--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-2 USART의 레지스터 ⊙ USART I/0 데이터 레지스터 (UDR0, UDR1) : USART0 또는 USART1 포트의 송수신 데이터 버퍼의 기능 RXB0[7..0]UDR0 (READ) Init Value UDR0 (Write) BIT 00000000 TXB0[7..0] 01234567 RXB1[7..0]UDR1 (READ) Init Value UDR1 (Write) BIT 00000000 TXB1[7..0] 01234567
  • 5. --55--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-2 USART의 레지스터 ⊙ USART 제어 및 상태 레지스터 A (UCSR0A, UCSR1A) : USART0, USART1 포트의 송수신 동작제어 ,송수신 상태 저장 기능 - RXCn (USARTn Receiver Complete): 수신버퍼의 상태 플래그 - TXCn (USARTn Transmit Complete): 송신버퍼의 상태 플래그 - UDREn (USARTn Data Register Empty) : 새로운 송신 데이터를 받기 위한 상태 플래그 - FEn (Frame Error) : 수신 프레임 에러 상태 플래그 - DORn (Data Overrun Error) : 수신동작 오버런 에러 상태 플래그 - UPEn (USARTn Parity Error) - U2Xn (Double the USARTn Transmission Speed) : 비동기 모드에서만 유효하며, 클럭의 분주비를 16에서 8로 낮추어 전송속도를 2배 높이는 기능 - MPCMn (USARTn Multi-Processor Communication Mode) MPCMnU2XnUPEnDORnFEnUDREnTXCnRXCnUCSRnA Init Value BIT 00000000 01234567
  • 6. --66--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-2 USART의 레지스터 ⊙ USART 제어 및 상태 레지스터 B (UCSR0B, UCSR1B) : USART0, USART1 포트의 송수신 동작제어, 전송데이터를 9비트로 설정한 경우에 전송 데이터의 9번째 비트값을 저장하는 기능을 수행 - RXCIEn (USARTn RX Complete Interrupt Enable): 수신완료 인터럽트 - TXCIEn (USARTn TX Complete Interrupt Enable): 송신완료 인터럽트 - UDRIEn (USARTn Data Register Empty Interrupt Enable) : 송신 데이터 레지스터 준비완료 인터럽트 - RXENn (USARTN Receiver Enable) : 수신부 동작허용, 직렬 데이터 수신단자로 동작하도록 설정하며, FEn , DORn, UPEn 의 동작을 유효하게 함 - TXENn (USARTn Transmitter Enable) : 송신부 동작허용 - UCSZn2 (USARTn Character Size) : UCSRnC 레지스터의 UCSZn1~0 비트와 함께 전송 문자의 비트수를 설정 - RXB8n (USARTn Receiver Data 8Bit) : 전송문자가 9비트로 설정된 경우 수신된 문자의 9번째 비트 (MSB)를 저장. 반드시 UDRn 레지스터 보다 먼저 읽어야 함 - TXB8n (USARTn Transmit Data 8Bit) : 전송문자가 9비트로 설정된 경우 송신할 문자의 9번째 비트 (MSB)를 저장. 반드시 UDRn 레지스터 보다 먼저 라이트되어야 함 TXB8nRXB8nUCSZn2TXENnRXENnUDRIEnTXCIEnRXCIEnUCSRnB Init Value BIT 00000000 01234567
  • 7. --77--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-2 USART의 레지스터 ⊙ USART 제어 및 상태 레지스터 C (UCSR0C, UCSR1C) : 송수신 동작 제어 - UMSELn (USARTn Mode Select) : 동기전송모드 시 1, 비동기 전송모드 시 0 - UPMn1~0 (USARTn Parity Mode) : 패리티 모드 설정 - USBSn (USARTn Stop Bit Select) USBSn = 0 , Stop Bit 1 USBSn = 1, Stop Bit UCPOLnUCSZn0UCSZn1USBSnUPMn0UPMn1UMSELn-UCSRnC Init Value BIT 00000000 01234567 ODD PARITY MODE11 EVEN PARITY MODE01 RESERVED10 NO PARITY MODE00 PARITY MODEUPMn0UPMn1
  • 8. --88--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-2 USART의 레지스터 ⊙ USART 제어 및 상태 레지스터 C (UCSR0C, UCSR1C) - UCSZn1~0 (USARTn Character Size) : UCSRnB 레지스터의 UCSZn2 비트와 함께 전송 문자의 데이터 비트수를 설정 - UCPOLn (USARTn Clock Polarity) : 동기 전송모드의 슬레이브 동작에서만 유효 UCPOLn = 0, 송신데이터는 XCKn 클럭의 상승 에지에서는 새로운 값이 출력되고, 수신 데이터는 XCKn 클럭의 하강 에지에서 검출 UCPOLn = 1 이면 송신 데이터는 XCKn 클럭의 하강 에지에서 새로운 값이 출력되고 수신 데이터는 XCKn 클럭의 상승 에지에서 검출 9bit111 Reserve011 Reserve101 Reserve001 8bit110 7bit010 6bit100 5bit000 Character SizeUCSZn0UCSZn1UCSZn2
  • 9. --99--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-2 USART의 레지스터 ⊙ USART BAUD RATE REGISTER (UBRR0H/L , UBRR1H/L) : 16비트 중 12비트 만 유효, 송수신 속도를 설정, 클럭의 분주비로 작용하여 직렬포트의 전송속도인 보레이트를 결정 UBRRn[11:8]----UBRRnH UBRRn[7:0]UBRRnL Init Value BIT 00000000 01234567 -0.79%34+2.12%1657,600 +0.16%51+0.16%2538,400 +0.64%68-0.79%3428,800 +0.16%103+0.16%5119,200 -0.08%138+0.64%6814,400 +0.16%207+0.16%1039600 -0.08%416+0.16%2074800 +0.04%832-0.08%4162400 ErrorUBRRnErrorUBRRn 비동기 2배속 모드 (U2Xn=1) 비동기 일반모드 (U2Xn=0)Baud Rate (bps) / 16MHz
  • 10. --1010--20062006--0404--0505 Embedded AVR ProgrammingEmbedded AVR Programming 1-3 USART0 실습 1 ☞ 송신은 폴링 방식, 수신은 인터럽트 방식으로 PC와 연결하여 USART0로 데이터를 받으면 그 받은 데이터를 전송하는 프로그램 void main(void) { // USART0 initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART0 Receiver: On // USART0 Transmitter: On // USART0 Mode: Asynchronous // USART0 Baud rate: 9600 UCSR0A=0x00; UCSR0B=0x98; UCSR0C=0x06; UBRR0H=0x00; UBRR0L=0x67; //16MHz일 때 //UBRR0L=0x33; //8MHz일 때 #asm("sei") while (1) ; // do nothing } #include <mega128.h> #include <delay.h> #define UDRE0 5 void TxData(char data) { while(!(UCSR0A & (1<<UDRE0)));// UDRE0 CHECK //while((UCSR0A & 0x20) == 0X00); UDR0 = data; } interrupt [USART0_RXC] void usart0_rx_isr(void) { char status,data; status=UCSR0A; data=UDR0; TxData(data); }