⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.c

📁 万能遥控器解码
💻 C
字号:
//ICC-AVR application builder : 2008-8-5 14:38:41
// Target : M8515
// Crystal: 8.0000Mhz

#include <iom8515v.h>
#include <macros.h>

#define uchar unsigned char
#define uint unsigned int
void delay_nus(unsigned int n)//n微秒延时函数 
{ 
unsigned int i; 
for (i=0;i<n;i++) 
  { 
      asm("nop"); 
  } 
} 
void delay_nms(unsigned int n)//n毫秒延时函数 
{ 
  unsigned int i; 
  for (i=0;i<n;i++) //执行n次1毫秒延时 
  delay_nus(1000);  
}             
void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x00;
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00;
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00; 
 PORTE = 0x00;
 DDRE  = 0x00; 
}

//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x00;
 UCSRC = BIT(URSEL) | 0x26;
 UBRRL = 0x33; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0x18;
}


void sendchar(uchar num)
  { 	   
      UDR=num;
      while(!(UCSRA&(1<<TXC)));
	  UCSRA |= (1<<TXC);
  }
int PutChar(char c)
{
    if(c == '\n')
    {
        PutChar('\r');
    }
    UDR = c;
    while(!(UCSRA &(1<<UDRE)));
    UCSRA |= (1<<UDRE);
    return 0;
}

void main(void)
{
    uchar i,j;
    uart0_init();
while(1)
   {
     delay_nms(500);
	 sendchar(0xaa);
   }
	;
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -