高级会员 
 
主题
回帖0
积分1382
阅读权限30
注册时间2011-10-23
最后登录1970-1-1
在线时间 小时
 
 
 
 
 | 
GCC编译器 
 
 
#include <avr/io.h> 
#define mcu_f 8000000 
#define baud  9600 
void uart_init(unsigned long int ,unsigned long int  ); 
//int uart_receive(void); 
void uart_send(unsigned char ); 
void uart_send_string(unsigned char *s);//发送字符串 
 
int main(void) 
{ 
  int d ; 
//  int i,j; 
  d=5; 
  uart_init( mcu_f ,  baud ); 
//  while(!(UCSR1A&(1<<RXC1))) 
//  { 
//  for(i=0;i++;i<=1000) 
//  for(j=0;j++;j<=1000); 
//  } 
//  data = uart_receive(); 
//  uart_send(data); 
//  DDRB=0xff; 
//  PORTB=data; 
  uart_send_string("经度:");//发送字符串 
  uart_send(d); 
  uart_send_string("\n\r");//换行 
  uart_send_string("纬度:");//发送字符串 
  uart_send_string("\n\r");//换行 
  uart_send_string("速度:");//发送字符串 
  uart_send_string("\n\r");//换行 
   
   
   
    
  while(1); 
} 
 
 
 
void uart_init(unsigned long  int MCU_F ,unsigned long int BAUD ) 
{ 
/*设置波特率高8位*/ 
UBRR1H =((MCU_F/(16*BAUD))-1)>>8;  
/*设置波特率低8位*/ 
UBRR1L = ((MCU_F/(16*BAUD))-1); 
/* 接收器与发送器使能 */  
UCSR1B |= 0b00011000; 
/* 设置帧格式  : 8个数据位  , 1个停止位 */  
UCSR1C |= 0b00000010;  
} 
 
 
void uart_send_string(unsigned char *s) 
  {  
  while(*s) 
  { 
  uart_send(*s++); 
  } 
  } 
 
//int uart_receive(void) 
//  { 
//  while(UCSR1A&(1<<RXC1)) 
//  return UDR1; 
//  } 
void uart_send(unsigned char c) 
  { 
  while( !(UCSR1A & (1<<UDRE1)) ); 
  UDR1=c; 
  } |   
 
 
 
 |