当前位置:网站首页>How to use printf of 51 single chip microcomputer

How to use printf of 51 single chip microcomputer

2022-06-25 07:42:00 Assassin ari

    Today, a netizen in the group mentioned 51 Use of single chip microcomputer printf Why did the compiler pass , But it didn't work . Here are my notes to share , The experiment itself doesn't make much sense , Mainly records 51 How should SCM be used Printf function .


Name of the experiment : Single chip microcomputer and serial port communication PC Calculate the trapezoidal area

MCU model :STC12C5A60S2(12T Pattern )

Crystal oscillator :11.0592MHZ

Experimental content : Using single chip microcomputer and PC The working mode of serial port communication 1( The baud rate is variable ),( Crystal vibration has been 11.0592MHZ) Set the baud rate to 9600B/S, Combined timer 1 How it works 2(TH1=0xfd,TL1=0xfd), Input the top and bottom of trapezoid 、 Bottom 、 high , Output trapezoidal area


design sketch :

Reference procedure :

/*
	 file name : Serial port communication value SCM and PC The computer calculates the trapezoidal area .c
	 founder : Yang Rui 
	 Creation time :2013 year 2 month 20 Japan 
	 development environment :HOT51 Enhanced MCU development board 
	 Program function : Using single chip microcomputer and PC Serial port communication of computer , Calculate the trapezoidal area 
	
	 attach : Using single chip microcomputer and PC The working mode of serial communication of the computer 1( The baud rate is variable ),( The crystal oscillator is known to be 11.0592MHZ) Set the communication baud rate to 9600b/s, Combined timer 1 How it works 2(TH1=0xfd,TL1=0xfd), Enter the bottom 、 Bottom 、 high , Output trapezoidal area 
	
	 Tips : After downloading the program , Open the serial port tool , It needs to be reset .
*/

#include<reg52.h>
#include<stdio.h>

#define uint unsigned int 
#define uchar unsigned char

void uart(void)					// Serial communication initialization 
{
	SCON=0x40;					// Working mode of serial communication 1
	REN=1;						// Allow to receive 
	TMOD=0x20;					// Timer 1 How it works 2
	TH1=0xfd,TL1=0xfd;		
	TI=1;                       // It's important to be careful here 
	TR1=1;						// Turn on timer 
}								
void main(void)
{
	uint up=0,down=0,high=0;
	uint result ;
	uart();
	while(1)
		{ 	
			printf("********************************\r\n");
			printf("Please input up,dowm,high:\r\n");
			scanf("%d%d%d",&up,&down,&high)	;
			printf("\r\nResult=%d\r\n",result=(up+down)*high/2);
		}
}



原网站

版权声明
本文为[Assassin ari]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200602559843.html