태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.
 

 


 

'Programming/Avr128'에 해당되는 글 2

  1. 2009/12/21 AVR128 UART Baud Rate 레지스터 설정
  2. 2009/03/03 AVR128 USART0 예제
 

AVR128 UART Baud Rate 레지스터 설정

Programming/Avr128 | 2009/12/21 00:34 | Posted by 엉이엉이
//avr 클럭 16MHz 일때!!
//UCSRnA = 0  일때 (U1X로 표기) Baud Rate
//사용예)UBRRnH = 0   ; UBRRnL = 요기다 저걸 표기 9600인경우 103

#define U1X_4800 207 //Error  0.2%
#define U1X_9600 103 //Error  0.2%
#define U1X_14400 68 //Error  0.6%
#define U1X_19200 51 //Error  0.2%
#define U1X_28800 34 //Error  -0.8%
#define U1X_38400 25 //Error  0.2%
#define U1X_57600 16 //Error  2.1%
#define U1X_76800 12 //Error  0.2%
#define U1X_115200 8 //Error  -3.5%
#define U1X_230400 3 //Error  8.5%
#define U1X_250000 3 //Error  0.0%
#define U1X_500000 1 //Error  0.0%
#define U1X_1000000 0 //Error  0.0%

//avr 클럭 16MHz 일때!!
//UCSRnA = 1  일때 (U2X로 표기) Baud Rate
//사용예)UBRRnH = 0   ; UBRRnL = 요기다 저걸 표기 9600인경우 207
//즉 두배란소리!!

저작자 표시 비영리

'Programming > Avr128' 카테고리의 다른 글

AVR128 UART Baud Rate 레지스터 설정  (0) 2009/12/21
AVR128 USART0 예제  (0) 2009/03/03

TRACKBACK ADDRESS : http://smartiz.co.kr/trackback/76 관련글 쓰기

댓글을 달아 주세요

AVR128 USART0 예제

Programming/Avr128 | 2009/03/03 20:31 | Posted by 엉이엉이

//PC의 키보드로 10개를 순차적으로 보내면 AVR이 통째로 10개를 PC에게 보내는 소스

 

#include <avr/io.h>
#include <avr/interrupt.h>


typedef unsigned char BYTE;
typedef unsigned int WORD;

#define BUFF_SIZE 10

BYTE receive_data[BUFF_SIZE], num, program_stop;

#define SW0     0x01
#define CHECK_SERIAL    '@'     //ascii code 0x40
#define CLEAR_ALL    0x00
#define SELECT_TXD    0x20

#define BAUD_HIGH    00
#define BAUD_LOW    16  //57600 bps
#define ALL_FLAG_CLEAR    0x00
#define USATR_RECEIVER_ENABLE   0x10
#define USATR_TRANSMITTER_ENABLE  0x08
#define USATR_CHARACTER_SIZE   0x06   //8bit
#define RX_INT_EN    0x80
#define TX_INT_EN    0x40


#define NO_OF_CHAR 10
#define TRUE  1
#define FALSE  0

void delay(void);
void initialize_serial(void);
void serial_check(void);
void transmit_interrupt(void);

void delay(void){
 
 BYTE i,j;
 WORD ta;

 j=4;
 ta = 65535;
 
 for(i=0; i<=j; i++){
  while(ta--);
  }
}

void initialize_serial(void){

  UBRR0H = BAUD_HIGH;
  UBRR0L = BAUD_LOW;
  UCSR0A = ALL_FLAG_CLEAR;
  UCSR0B = USATR_RECEIVER_ENABLE | USATR_TRANSMITTER_ENABLE | RX_INT_EN | TX_INT_EN;
  UCSR0C = USATR_CHARACTER_SIZE ;
}
void serial_check(void){

 PORTA = 0x33;
 while((PIND & SW0)==0x00);
 while((UCSR0A & 0x20) == 0x00);
 UDR0 = CHECK_SERIAL;
}

void transmit_interrupt(void){

 if(num < NO_OF_CHAR){
   while((UCSR0A & 0x20) == 0x00);
   UDR0 = receive_data[num];
   num++;
        }
 else if(num == NO_OF_CHAR) num = 0;

}

SIGNAL(SIG_USART0_RECV){
 
 
 receive_data[num] = UDR0;
 if(receive_data[num] == '#') program_stop = TRUE;
 num++;

 if(num == NO_OF_CHAR){
    num=0;
    transmit_interrupt();
         }

}

SIGNAL(SIG_USART0_TRANS){

 transmit_interrupt();
 
}

int main(void){

 DDRA = 0xff;
  
 num = 0;
 initialize_serial();
 serial_check();
 PORTA = CLEAR_ALL;
 sei();

 while(1){

  PORTA = 0x33;
  delay();
  PORTA = 0xcc;
  delay();
  if(program_stop == TRUE) break;
 }return 0;
}

 


저작자 표시 비영리

'Programming > Avr128' 카테고리의 다른 글

AVR128 UART Baud Rate 레지스터 설정  (0) 2009/12/21
AVR128 USART0 예제  (0) 2009/03/03

TRACKBACK ADDRESS : http://smartiz.co.kr/trackback/13 관련글 쓰기

댓글을 달아 주세요