菜鸟又来求经了,关于STC15W4K32系列单片机的串口3和串口4不能通讯
时间:10-02
整理:3721RD
点击:
现在想用STC15的串口4进行触摸屏的通讯,但是在实验时串口1和2通讯完全没问题,但是到了串口4就不能通讯了,试了串口3也不行,不知道程序都是按照手册上的寄存器设置写的,不知道是不是串口3和4还有什么特殊的设置?串口3和4都是用的默认接口,串口3是P0,0 P0,1 串口4是P0,2 P0,3
#include "STC15.h"
#define uchar unsigned char
#define uint unsigned int
#define FOSC 11059200
#define BAUD 9600
#define S3RI 0x01
#define S3TI 0x02
#define TM (65536-(FOSC/4/BAUD))
uchar flag,num;
void INIT(void)
{
//TMOD=0x10;
P_SW2&=0x00;
S3CON=0x10;
T2L=TM;
T2H=TM>>8;
AUXR=0x14;
IE2=0x08;
EA=1;
}
void main(void)
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P6M0 = 0x00;
P6M1 = 0x00;
P7M0 = 0x00;
P7M1 = 0x00;
INIT();
while(1)
{
if(flag==1)
{
flag=0;
IE2=0x00;
S3BUF=num;
while((S3CON&S3TI)==0);
S3CON&=~S3TI;
IE2=0x08;
}
}
}
void UART() interrupt 17
{
if((S3CON & S3RI) != 0x00)
S3CON&=~S3RI;
num=S3BUF;
flag=1;
}
#include "STC15.h"
#define uchar unsigned char
#define uint unsigned int
#define FOSC 11059200
#define BAUD 9600
#define S3RI 0x01
#define S3TI 0x02
#define TM (65536-(FOSC/4/BAUD))
uchar flag,num;
void INIT(void)
{
//TMOD=0x10;
P_SW2&=0x00;
S3CON=0x10;
T2L=TM;
T2H=TM>>8;
AUXR=0x14;
IE2=0x08;
EA=1;
}
void main(void)
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P6M0 = 0x00;
P6M1 = 0x00;
P7M0 = 0x00;
P7M1 = 0x00;
INIT();
while(1)
{
if(flag==1)
{
flag=0;
IE2=0x00;
S3BUF=num;
while((S3CON&S3TI)==0);
S3CON&=~S3TI;
IE2=0x08;
}
}
}
void UART() interrupt 17
{
if((S3CON & S3RI) != 0x00)
S3CON&=~S3RI;
num=S3BUF;
flag=1;
}
实现出口通讯,首先得把一些参数给填充好,然后把发出去得数据到示波器上看一看,看看时序对不对。
这个我测试过串口3,串口4没有试过。串口3用自发自首是可以的,是用的中断方式,STC标准的例程改的。