?? 1uart.c
字號:
//1UART.c : source file for the 1 UART
//
#include "1.h"
#include "1UART.h"
#include <delay.h>
#include <math.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
#define BUFF_SIZE 32
/////////////////////////////////////////////////////////////////////////////
//1UART
extern uchar input;
extern uchar output;
void uart_init(void)
{
//{{WIZARD_MAP(UART)
// Baud Rate: 19200
// Character Size: 8-bit
// Mode: Asynchronous
// Parity: Disabled
// Stop Bit: 1-bit
UBRRL = 0x19; //00011001
UBRRH = 0x00; //波特率19200
UCSRA = 0x00;
UCSRC = 0x86; //控制和狀態寄存器10000110;bit7選擇,bit2,1數據位8位,bit0上升沿輸出,下降沿輸入
UCSRB = 0x48; //01001000,bit6發送結束中斷使能;bit3發送使能,TXD腳發送數據
//}}WIZARD_MAP(UART)
}
void send_char(unsigned char a)
{
UDR=a;
delay(1,8000);
}
SIGNAL(SIG_UART_TRANS) //USART發送完一個字節中斷
{
if(test_send())
{
UDR=get_send();
}
}
void put_send(uchar a)
{
send_buff[input]=a;
if(input<BUFF_SIZE-1)
input++;
else
input=0;
}
uchar test_send(void)
{
if(output==input)
return 0;
else
return 1;
}
uchar get_send(void)
{
uchar temp;
if(output==input)
return 0;
else
{
temp=send_buff[output];
if(output<BUFF_SIZE-1)
output++;
else
output=0;
return temp;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -