求助avr串口通讯的相关问题

2019-07-15 08:02发布

程序如下:但是通过串口助手就是接收不到数据。(8MHZ内部RC振荡器,波特率9600)
#include <iom64v.h>
#include <macros.h>
//#include <stdio.h>




#define uchar unsigned char




void uart0_init(void)
{
        UCSR0B = 0x00;
        UCSR0A = 0X00;
        UCSR0C = 0x06;
        UBRR0L = 51;
        UBRR0H = 0x00;
        UCSR0B = 0x18;
}






void rs232send(uchar c)
{
        while(!(UCSR0A&(1 << UDRE0)));
        UDR0 = c;
}


void puts0 (char *s)
{
        while(*s)
        {
                     rs232send(*s);
                   s++;
        }
        rs232send(0x0a);
        rs232send(0x0d);
}




void main (void)
{
        uchar i;
        PORTE = (1 <<PE0) | (1 <<PE1) ;
        DDRE = (1<<PE1);
        uart0_init();
       
        //puts0("HELLO!");
        while(1)
     {   
      
                puts0("test ok!");        
        }
}




0条回答

一周热门 更多>