📄 usart.c~
字号:
#include "usart.h"
void UsartInit(void)
{
UBRRH = (unsigned char)(((unsigned int)((unsigned long)CRYSTAL/(16*(unsigned long)BAUD)-1)) >> 8); //
UBRRL = (unsigned char)((unsigned int)((unsigned long)CRYSTAL/(16*(unsigned long)BAUD)-1));
UCSRC = 0xA6; //设置偶校验,1位停止位,8位数据位
UCSRA = 0x00; //不设置倍速,波特率分频器分频系数为16
UCSRB = 0x98; //使能接收中断,使能接收和发送
usartCounter = 0;
DDRD.0 = 0;
DDRD.1 = 1;
}
interrupt [USART_RXC] void UsartReceive (void)
{
unsigned char status;
unsigned char data;
unsigned char iCycle;
status = UCSRA;
data = UDR;
if((status & 0x1C) == 0x00)
{
if (data == 0xBB)
{
dataReceiveOK = 1;
usartCounter = 0;
}
else if (data == 0xEE)
{
dataReceiveOK = 0;
if (usartCounter == 8)
{
UDR = 0x01;
for (iCycle = 0; iCycle < 8; iCycle++)
{
DS1302Data[iCycle] = reBuffer[iCycle];
}
DS1302checkDataOve();
FindDataOfWeek();
DS1302WriteTimeData();
}
else
{
UDR = 0x00;
}
}
else
{
if (dataReceiveOK)
{
reBuffer[7-usartCounter] = data;
++usartCounter;
}
}
}
}
//interrupt [USART_TXC] void UsartTransmit (void)
//{
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -