请教大家一个问题,我用51和STM32进行通信,51只用接收数据然后在1602上显示,STM32发送数据。TXD和RXD错开连接,共地。为什么我现在51收不到STM32的数据呢?STM32是用的MINI
51程序:
#include<reg52.h>
#include"1602.h"
unsigned char read_flag =0;
unsigned char i = 0;
void init_com()
{
TMOD |= 0X20;
TH1 = 0XFD;
TL1 = 0XFD;
TR1 = 1;
REN = 1;
SM0 = 0;
SM1 = 1;
EA = 1;
ES = 1;
}
void send_char(unsigned char ch)
{
SBUF = ch;
while(TI==0);
TI = 0;
}
int main()
{
unsigned char ch[5] = {'w','s','d','a'};
init_com();
LCD_init();
while(1)
{
write_com(0x80);
if(read_flag)
{
read_flag = 0;
write_date(ch[i - '0']);
}
}
}
void re_com() interrupt 4
{
if(RI)
{
RI = 0;
i = SBUF;
read_flag = 1;
}
}
STM32程序:
#include "delay.h"
#include "sys.h"
#include "key.h"
#include "usart.h"
int main(void)
{
u8 t,i = 0;
u8 ch[5]={'1','2','3','4'};
SystemInit();
delay_init(72);
NVIC_Configuration();
uart_init(9600);
KEY_Init();
while(1)
{
t = KEY_Scan();
if(t == 1)
{
USART_SendData(USART1,ch[i]);
i++;
if(i>=4)
{
i = 0;
}
}
}
}
STM32采用的是原子哥的串口程序,用的是串口一。波特率设置的是9600,usart.c没有改变就是原子哥的程序。请大神指点一哈问题在哪里啊?!!谢谢了
|