하이퍼터미널 연결후
비트/초(B): 19200
#include "EHA.h"
//#include<avr/io.h>
#define FOSC 16000000
#define BAUD 19200
#define MYUBRR FOSC/16l/BAUD-1 //16l long
void USART_Init(unsigned int ubrr);
void USART_Transtmit(unsigned char data);
unsigned char USART_Receive(void);
int main(void)
{
DDRF=0XFF;
PORTF=0XFF;
//unsigned char REC;
//volatile int n;
//unsigned char len[10] = "hello";
//unsigned char* len = "hello";
USART_Init(MYUBRR);
while(1)
{
switch(USART_Receive())
{
case '1':
PORTF=0X00;
break;
case '2':
PORTF=0XFF;
break;
}
}
/*
for(n=0; len[n]!='\0'; ++n){
USART_Transtmit(len[n]);
}
while(1){
REC=USART_Receive();
REC++;
USART_Transtmit(REC);
}
*/
while(1);
return 0;
}
//USART 초기화
void USART_Init(unsigned int ubrr)
{
//Set baud rate
UBRR1H = (unsigned char) (ubrr>>8);
UBRR1L = (unsigned char)ubrr;
// Enabe receiver and transmitter
UCSR1B = (1<<RXEN) |(1<<TXEN); //UCSR1B = 0X18;
//UCSR1C = (1<<USBS) |(3<<UCSZ0); //UCSR1C = 0X0E;
UCSR1C = (3<<UCSZ0); //UCSR1C = 0X06;
}
void USART_Transtmit(unsigned char data)
{
while(!(UCSR1A & (1<<UDRE)))
;
UDR1= data;
}
unsigned char USART_Receive(void)
{
while(!(UCSR1A & (1<<RXC)))
;
return UDR1;
}
'ATmega128' 카테고리의 다른 글
| USART로 데이터 보내고 받기 (0) | 2009/04/29 |
|---|---|
| USART 제어 (0) | 2009/04/28 |
| DK128 Main (0) | 2009/04/23 |



Prev
