본문 바로가기

AVR 8BIT/통신(USART)

블루투스(FB155BC)를 이용한 CDS센서 값 USART 찍기


#include 
#include 
#include 
                
char rx;
char  str[50];
int ADC1;
float ADC_F;
interrupt[USART0_RXC]void usart0_rxc(void){
    rx=UDR0;   
    
    if(rx=='1')PORTC=1,delay_ms(300);  
    if(rx=='2')PORTC=2,delay_ms(300); 
    if(rx=='3')PORTC=4,delay_ms(300); 
    if(rx=='4')PORTC=8,delay_ms(300); 
    if(rx=='5')PORTC=16,delay_ms(300); 
    if(rx=='6')PORTC=32,delay_ms(300); 
    if(rx=='7')PORTC=64,delay_ms(300); 
    if(rx=='8')PORTC=128,delay_ms(300);
    
  }      
          

void TX0_CHAR(char Sdata){ while ((UCSR0A&0x20)==0); UDR0=Sdata; }

void main(void)
{                              
    char i;
    DDRC=0xff; 
    UCSR0B=0x98; //RXEN , TXEN Enable
    UCSR0C=0x06; //8bit mode
    UBRR0H=0;
    UBRR0L=95;   
    ADCSRA=0xE7;
    #asm("sei")     
    
    while(1)   
    {
        delay_us(104); ADC1=ADCW;       
        ADC_F=(float)ADC1*5.0/1023.0;
        sprintf(str,"volt = %f \n", ADC_F);
        i=0; while(str[i])TX0_CHAR(str[i++]); // TXD1
      
        }
}    

 

 

 

 

 

'AVR 8BIT > 통신(USART)' 카테고리의 다른 글

블루투스(FB155BC) LED 제어  (18) 2011.05.22
ATMEGA USART 이론  (0) 2011.05.20