📄 uart_3.c
字号:
// this file is define the UART3 function prototype
/* created by bill.zhang */
#include "uart.h"
#define MODE_QUICKA
void delay_3()
{
int i=4000;
while (i--);
}
void UART3_Init (void)
{
T1TC = 0; /* 定时器设置为0 */
T1PR =0; /* 时钟不分频 */
T1MCR = 0x03; /* 设置T1MR1匹配后复位T1TC,并产生中断标志 */
T1MR0 = (Fcclk/16)/2520; //set baud rate
}
/**********************************UART get functions******************************************************/
//========================================getbyte================================
uint8 UART3_GetByte (void)
{
uint8 rcv_dat,Rvar;
uint32 UART_RX_3,Uart_Rvar;
Rvar=0x00;
UART_RX_3=(1<<25);//p0.25 as the UART3 RX
Uart_Rvar=(3<<18);
PINSEL1=PINSEL1&(~Uart_Rvar);
IO0DIR&=(~Uart_Rvar);
#ifdef MODE_QUICKA
// --------------------receive startbit------------------------------------------
while ((IO0PIN&UART_RX_3)!=0) ;// check the start style
// --------------------receive startbit------------------------------------------
//---------------------START TIMER0 template-------------------------------------
T1TCR = 0x01; //start timer0
//---------------------START TIMER0 template-------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ biT1-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x01;
else
rcv_dat|=0x01;
// --------------------READ biT1-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ biT1-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x02;
else
rcv_dat|=0x02;
// --------------------READ biT1-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ bit2-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x04;
else
rcv_dat|=0x04;
// --------------------READ bit2-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ bit3-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x08;
else
rcv_dat|=0x08;
// --------------------READ bit3-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ bit4-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x10;
else
rcv_dat|=0x10;
// --------------------READ bit4-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ bit5-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x20;
else
rcv_dat|=0x20;
// --------------------READ bit5-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ bit6-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x40;
else
rcv_dat|=0x40;
// --------------------READ bit6-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
// --------------------READ bit7-------------------------------------------------
if ((IO0PIN&UART_RX_3)==0)
rcv_dat&=~0x80;
else
rcv_dat|=0x80;
// --------------------READ bit7-------------------------------------------------
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
while((T1IR & 0x01) == 0) if(rcv_dat) break;
//---------------------end TIMER0 template------------------------------------
T1TCR = 0x00;
//---------------------end TIMER0 template------------------------------------
//return rcv_dat;
#else
unsigned char rch,ii;
//---------------------START TIMER0 template-------------------------------------
T1TCR = 0x01;
//---------------------START TIMER0 template-------------------------------------
ii=0;
rch=0;
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
while(ii<8)
{
rch>>=1;
if(rcv_dat) rch|=0x80;
ii++;
//---------------------TIMER processing template---------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template---------------------------------
}
while((T1IR & 0x01) == 0) if(rcv_dat) break;
//---------------------end TIMER0 template------------------------------------
T1TCR = 0x00;
//---------------------end TIMER0 template------------------------------------
return rch;
#endif
return rcv_dat;
}
//========================================getbyte================================
//========================================getstring==============================
void UART3_GetStr (uint8 *s, uint32 n)
{
for ( ; n>0; n--)
{
*s++ = UART1_GetByte();
}
}
//========================================getstring=============================
/**********************************UART get functions******************************************************/
/**********************************UART send functions******************************************************/
//========================================sendbyte==============================
void UART3_SendByte (uint8 dat)
{
uint8 ACC;
uint32 UART_TX_2,Uart_var1;
ACC=dat;
UART_TX_2=(1<<28);
Uart_var1=(3<<24);
PINSEL1=PINSEL1&(~Uart_var1);
IO0DIR=UART_TX_2;
delay_3();
#ifdef MODE_QUICKA
//---------------------START TIMER0 template------------------------------------
T1TCR = 0x01;
//---------------------START TIMER0 template------------------------------------
IO0CLR=UART_TX_2;//start bit
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------biT1-----------------------------------------------------
if ((ACC&0x01)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------biT1-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------biT1-----------------------------------------------------
if ((ACC&0x02)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------biT1-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------bit2-----------------------------------------------------
if ((ACC&0x04)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------bit2-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------bit3-----------------------------------------------------
if ((ACC&0x08)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------bit3-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------bit4-----------------------------------------------------
if ((ACC&0x10)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------bit4-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------bit5-----------------------------------------------------
if ((ACC&0x20)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------bit5-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------bit6-----------------------------------------------------
if ((ACC&0x40)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------bit6-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
// --------------------bit7-----------------------------------------------------
if ((ACC&0x80)==0)
IO0CLR=UART_TX_2;
else
IO0SET=UART_TX_2;
// --------------------bit7-----------------------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
IO0SET=UART_TX_2;//end bit
#else
unsigned char ii;
ii=0;
//---------------------START TIMER0 template------------------------------------
T1TCR = 0x01;
//---------------------START TIMER1 template------------------------------------
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
while(ii<8)
{
if(dat&1)
IO0SET=UART_TX_2;
else
IO0CLR=UART_TX_2;
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
ii++;
inch>>=1;
}
IO0SET=UART_TX_2;
//---------------------TIMER processing template--------------------------------
while ((T1IR & 0x01) == 0) ;
T1IR = 0x01;//clear the flag
//---------------------TIMER processing template--------------------------------
#endif
//---------------------end TIMER0 template------------------------------------
T1TCR = 0x00;
//---------------------end TIMER0 template------------------------------------
}
//========================================sendbyte==============================
//========================================sendstring============================
void UART3_SendStr (char *str)
{
while (1)
{
if (*str == '\0') break; /* 遇到结束符,退出 */
UART1_SendByte(*str++); /* 发送数据 */
}
}
//========================================sendstring============================
/**********************************UART send functions******************************************************/
//-------------------------------------end file----------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -