程序1为查询通信方式接口程序,为一典型的数据采集例程。其中bioscom()函数初始化COM1(此函数实际调用BIOS
INT
14H中断0号功能)。这样在程序中就避免了具体设置波特率因子等繁琐工作,只需直接访问发送/接收寄存器(3F8H)和线路状态寄存
我用的新唐芯片,8051内核,跟51差不多,望采纳void UART_Initial (void)
{
P02_Quasi_Mode //Setting UART pin as Quasi mode for transmit
P16_Quasi_Mode //Setting UART pin as Quasi mode for transmit
SCON_1 = 0x50 //UART1 Mode1,REN_1=1,TI_1=1
T3CON = 0x08 //T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1), UART1 in MODE 1
clr_BRCK
RH3= HIBYTE(65536 - (1000000/u32Baudrate)-1) /*16 MHz */
RL3= LOBYTE(65536 - (1000000/u32Baudrate)-1) /*16 MHz */
set_TR3//Trigger Timer3
}
以上是初始化的
void Send_Data_To_UART1(UINT8 c)
{
TI_1 = 0
SBUF_1 = c
while(TI_1==0)
}
这个是发送
void UART_isr (void) interrupt 4 //串行中断服务程序
{
if (RI_1==1)
{ /* if reception occur */
clr_RI_1/* clear reception flag for next reception */
Receive_Date[c] = SBUF_1
if (Receive_Date[0] == First_Date)
{
c++
}
else if(Receive_Date_Size >0 &&Receive_Date_Size <4)
{
c++
}
else if(Receive_Date[c] == Last_Date &&Receive_Date_Size ==4)
{
c = 0
Flag_Receive_One = 1
}
else
{
c = 0
}
}
}
接收
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)