PC机每隔0.5秒向单片机发射一串字符"EFG",共发射5次,要求单片机将收到的字符保存在STRINGL中
来源:百度知道 编辑:UC知道 时间:2024/05/19 20:58:04
谢谢 把程序写下
是6次 不是5次
是6次 不是5次
我有类似的,改改给你。。但不保证100%正确,自己调调吧。。
单片机程序,for 51 only: 晶振11.0592M。。如果你不是,需要调SCON,TH1。。看看教程吧
#include <reg.h>
#define BUF_LEN (0x20)
char buf[BUF_LEN];
void InitUart(void)
{
SCON=0x50; //mode 1
TMOD=0x21; //timer0 --> 16 bits counter
//timer1 --> 8 bits auto load for UART
//TH1=0xE8; //1200bps
TH1=0xfd; //9600bps
TR1=1; //time1 start
}
char ReceiveChar()
{
while(RI==0);
RI=0;
return SBUF;
}
void main(void)
{
int cnt = 0;
while (cnt < BUF_LEN)
{
buf[cnt++] = ReceiveChar();
}
while(1);
}
PC程序:
// uart_write.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "uart_write.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static