历史上的今天
今天是:2024年11月11日(星期一)
2019年11月11日 | STC15w4k58s4单片机4串口同时收发例程
2019-11-11 来源:51hei
STC15w4k58s4 芯片的4串口同时收发例程
单片机源程序如下:
#include "intrins.H"
#include "uart.H"
#define uchar unsigned char
#define uint unsigned int
uchar uart1buf[6]={0xa5,0x5a,0x4a,0xf8,0xff,0xff};
uchar uart2buf[6]={0xa5,0x5a,0x4a,0xf8,0xff,0xff};
uchar uart3buf[6]={0xa5,0x5a,0x4a,0xf8,0xff,0xff};
uchar uart4buf[6]={0xa5,0x5a,0x4a,0xf8,0xff,0xff};
uchar uart2_i,uart3_i,uart4_i;
bit flag2=0,flag3=0,flag4=0; //flag of reveived new packs 收到新数据包标志
void delay(uint k)
{
uint i,j;
for(i=0;i for(j=0;j<121;j++) {;}} } void main() { uchar i; uint l1,l2,l3; Uart1Init(); Uart2Init(); Uart3Init(); Uart4Init(); while(1) { if(flag3==1||flag2==1||flag4==1) { flag4=0; flag3=0; flag2=0; for(i=0;i<6;i++) uart1buf[i]=uart3buf[i]; l1=256*uart2buf[2]+uart2buf[3]; l1=l1/10*7; l2=256*uart3buf[2]+uart3buf[3]; l2=l2/10*7; l3=256*uart4buf[2]+uart4buf[3]; if(l1<=l2&&l1<=l3) { uart1buf[2]=l1/256; uart1buf[3]=l1%256; } if(l2<=l1&&l2<=l3) { uart1buf[2]=l2/256; uart1buf[3]=l2%256; } if(l3<=l1&&l3<=l2) { uart1buf[2]=uart4buf[2]; uart1buf[3]=uart4buf[3]; } if(uart1buf[2]>=0xea) { uart1buf[2]=0xea; uart1buf[3]=0x00; } for(i=0;i<6;i++) UART1_SendData(uart1buf[i]); } // delay(500); } } void Uart2() interrupt 8 using 1 { if (S2CON & S2RI) { S2CON &= ~S2RI; //清除S2RI位 uart2buf[uart2_i]=S2BUF; uart2_i++; if(uart2_i==6) { uart2_i=0; flag2=1; if(uart2buf[2]==0&&uart2buf[3]==0) { uart2buf[2]==0x2a; uart2buf[3]==0xf8; } } } if (S2CON & S2TI) { S2CON &= ~S2TI; //清除S2TI位 } } void Uart3() interrupt 17 using 1 { if (S3CON & S3RI) { S3CON &= ~S3RI; //清除S2RI位 uart3buf[uart3_i]=S3BUF; uart3_i++; if(uart3_i==6) { uart3_i=0; flag3=1; if(uart3buf[2]==0&&uart3buf[3]==0) { uart3buf[2]==0x2a; uart3buf[3]==0xf8; } } } if (S3CON & S3TI) { S3CON &= ~S3TI; //清除S3TI位 } } void Uart4() interrupt 18 using 1 { if (S4CON & S4RI) { S4CON &= ~S4RI; //清除S2RI位 uart4buf[uart4_i]=S4BUF; ……………………
史海拾趣
|
1 启动一个硬件开发项目 原始的推动力会来自于很多方面,比如市场的需要,基于整个系统架构的需要,应用软件部门的功能实现需要,提高系统某方面能力的需要等等,所以作为一个硬件系统的设 ...… 查看全部问答> |
|
头文件不需要自己定义,一般情况下是这样,但是奇怪的是我们常常不知道那些定义了,先来一起看一看吧! 现在把楼下的所有资源在这里回个总。哪一模块不熟悉欢迎交流。。。。 O(∩_∩)O~ [ 本帖最后由 gaoxiao 于 2009-8-24 20:45 编辑 ]… 查看全部问答> |
|
1)登录博客后,进入个人空间,点击上方的“分享”,如下图所示 2)进入分享界面,在这里可以分享很多东西,比如网址、视频、音乐等等,还可以查看自己和大家的分享, 3)发布分享在“我的分享”界面的右侧,如下图所示, … 查看全部问答> |
|
各位大侠,哪位手里有针对ST2410移植好的u-boot?最近做的项目急用,哪位好心帮帮忙!小弟多谢了! 邮箱haishi-qhm@163.com QQ154634556 不胜感激!… 查看全部问答> |
|
viod main() { char str[1024]; .... return; } 这样的程序在嵌入式设备下可能会出现什么问题 应该如何改进 面试题 堆栈小,堆栈溢出的问题?… 查看全部问答> |




