Sharing of debugging experience of 51 single-chip microcomputer

Publisher:廿由人Latest update time:2021-06-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction: A full-duplex UART (Universal Asynchronous Receiver Transmitter) serial I/O port, used to realize serial communication between MCUs or between MCU and microcomputer;

on-chip oscillator and clock generation circuit, quartz crystal and fine-tuning capacitor need to be connected externally. The maximum oscillation frequency depends on the MCU model and performance.


1. The composition of the microcontroller:


CPU: It consists of operation and control logic, as well as an interrupt system and some external special function registers;


RAM: used to store data that can be read and written, such as intermediate results of calculations, final results, and data to be displayed;


ROM: used to store programs, some original data and tables;


I/O port: Four 8-bit parallel I/O ports, which can be used as both input and output;


T/C: Two timers/counters, which can work in both timing mode and counting mode;


Interrupt control system with five interrupt sources;


A full-duplex UART (Universal Asynchronous Receiver Transmitter) serial I/O port for serial communication between MCUs or between MCU and microcomputer;


The oscillator and clock generation circuit are built in, and the quartz crystal and fine-tuning capacitor need to be connected externally. The maximum oscillation frequency depends on the model and performance of the microcontroller.


2. Composition and working principle of I2C serial bus


At first, the light is not on because there is no delay between the write signal and the read signal. Add delay1(100). Note that this time cannot be too short. Then add delay1(1) after the SDA and SCL assignments. There seems to be no time limit here.


3. Composition and working principle of I2C serial bus - debugging of power-off saving display program


1. Now warn that there is a problem with AT24C02, which is caused by the input method problem during programming. At this time, you should pay attention to input in English format. In addition, the position of the digital tube is not displayed correctly


2. The LED display tens digit flickers unsteadily. The problem is alleviated to some extent by adjusting the delay time in the LED program, but the problem still exists. If the value is changed to a very small value, problem 3 will occur;


3. The ten digits have the same afterglow as the ones digits? The problem is solved by modifying the delay time in the main function, but the digits are still flashing.


4. Clock Program


#include <> format: reference the standard library header file, the compiler starts searching from the standard library directory


#incluce "" format: references header files of non-standard libraries, and the compiler starts searching from the user's working directory


1. The seconds displayed on the LCD changes too slowly?


The problem is that the if statement below while is written as if(count==0), which should be if(count==20)


2. The LCD time is incorrect when there is a carry. When the time is set to 23:59:30, it is displayed as 23:59:00. After the second carries, the minute is displayed as 1, and the clock does not carry.


Cause of the problem: The initialization display is unsuccessful, and it starts at 00:00:00 by default;


Solution: Initialization shi=23, fen=59, miao=30 is written in the display sub-function, which should be written in the main function.


5. Clock Program


1. The initial debugging of keyscan() did not work because keyscan() was not written under the large while(1) loop.


2. In keyscan, if(s1num!=0) should be written at the same level as if(s1==0). If it is written inside if(s1==0), it will appear that two keys must be pressed at the same time for a change to occur, which obviously does not meet the requirement, so there is no response.


3. In keyscan, miao.fen,shi should be set to 0 when it is -1, but at the beginning, miao.fen,shi is set to uchar type, so it should be changed to char type.


4. After writing the year-month-day display function, when the date has a carry, a distorted screen occurs at 23;59;59;. It is probably because the address pointer is not set in time after writing the data? It needs to be solved?


The problem lies in the year-month-day function that I wrote, which cannot read the data normally? The data write function was written as a command write function, that is, lcdwrite_date() was written as lcdwrite_date(); after the change, the year, month and day can be displayed, but the year display time is incorrect.


The year is a four-digit number, which cannot be expressed correctly using the uchar type. Instead, the unsigned long type should be used. In the write_nian() function, it should also be noted that the date type should also be an unsigned long type.


6. Perpetual Calendar Clock Program


1. After initialization, the initial debugging of year, month and day is successful.


2. When writing the month and the year separately, there is a debugging problem. The cursor keeps flashing on the seconds position and does not move.


Reference address:Sharing of debugging experience of 51 single-chip microcomputer

Previous article:Extended memory circuit design
Next article:How to simulate the counting method of serial port in 51 single chip microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号