Achievement No. 21

Openmv outputs 0 through the serial port, but the output is not simple, but a string of codes. How to make 51 recognize these codes is the next task.

import time
from pyb import UART

uart = UART(3, 9600)

while(True):
    uart.write("0")
    time.sleep(1000)

51 MCU serial communication code

	   //静态数码管显示+PC串口通信
#include<reg51.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 code smgduan[]={
    
    0x3f,0x30,0x4f};

void UsartInit()
{
    
    
       SCON=0X50;               //设置为工作方式1
       TMOD=0X20;                    //设置计数器工作方式2
       PCON=0X80;               //波特率加倍
       TH1=0Xfa;                         //计数器初始值设置,注意波特率是300的
       TL1=0Xfa;
       ES=1;                                        //打开接收中断
       EA=1;                                        //打开总中断
       TR1=1;                               //打开计数器
}

void main()
{
    
    
	UsartInit();
	while(1);
}

void Usart() interrupt 4
{
    
    
       u8 m;
       m=SBUF;
       LSA=0;
	   LSB=0;
	   LSC=0;			
       if(m=='0') 		//pc端hex模式输入0,则显示0,smgduan[0]=0
	   P0=smgduan[0];
	   else if(m=='1')	//pc端hex模式输入1,则显示1,smgduan[1]=1
	   P0=smgduan[1];
	   else				//pc端hex模式输入任意,则显示3, s[2]=3
	   P0=smgduan[2];	//但输入文本的数据,都显示3
       RI= 0;//清除接收中断标志位
       SBUF=m;//将接收到的数据放入到发送寄存器
       while(!TI);                    //等待发送数据完成
       TI=0;
}

Guess you like

Origin blog.csdn.net/m0_48808835/article/details/109908273
Recommended