2021/05/01

Hit the pit

At the beginning of the installation of the driver there is a problem, the driver clearly has been installed, but can not identify the MCU interface, ask customer service, feel customer service is also very confusing, finally solved. Visual inspection is either USB line contact is bad, or the installation of Win10 drive did not work, because the back also installed an XP drive.

Single chip microcomputer related concepts

Single chip microcomputer isSingle chip microcomputerThe abbreviation of the commonly used English abbreviation _MCU_(Microcontroller Unit) refers to the Microcontroller.

The MCU I used isDIP encapsulationAlthough the size is large, it is convenient to disassemble, so that it is more convenient to replace the chip after damage.

The other two packages (PLCC, LQFP), although small in size, but the replacement is more troublesome. Manufacturers for _STC_, the manufacturer of single-chip burning procedures more convenient.

Although different manufacturers, but the kernel is the use of Intel company80C51Series kernel, _STC_ MCU naming rules are as follows:

Some scattered knowledge points (C language)

Since I have learned a lot about C language, I took some selective notes:

Chinese name English names Conversion relation
Bits (bits) bit 1B = 8bit
byte byte 1B = 8bit
kilobytes kibibyte 1KB = 1024B
megabytes Mebibyte 1MB = 1024KB
gigabyte Gigabyte 1GB = 1024MB

When you talk about 100 megabits, you don’t mean 100 megabits, you mean 100 megabits, so you have to divide the download speed by 8, which translates to 12.5 megabits in bytes.

The data type Of digits The scope of
bit 1 0 ~ 1
unsigned char 8 0 ~ 255
char 8 – 128 ~ 127
unsigned int 16 0 ~ 65535
int 16 – 32768 ~ 32767
unsigned long 32 0 ~ 429467295
float 32 E38 e-38 3.4 ~ 3.4
double 64 E308 e-308 1.7 ~ 1.7

The highest bit with a sign bit is the sign bit, where 0 represents a positive number and 1 represents a negative number.

Some scattered knowledge points (basic electronic circuit)

MCU is a digital integrated chip, there are only two levels in the digital circuit: high level and low level. The high level is 5V and the low level is 0V. TTL level signals are used more often because the data representation in digital circuits is usually binary, with 5V equivalent to logic 1,0 V equivalent to logic 0. The TTL level specifies the high level output voltage >2.4V and the low level output voltage <0.4V. This is because the precise value of high and low level may not be reached when the signal is actually sent, so as long as it is within this fluctuation range, it will be identified as high and low level. But the computer serial port uses the RS232 level. The high level is -12V, and the low level is +12V. When the SCM communicates with the serial port of the computer, it needs to use the level conversion chip. Only after the RS232 level is converted to the TTL level, can the SCM identify it. But the power supply port of the USB interface of the circuit is 5V, so is the charger, so you can use the charger and the computer USB interface to supply power to the SCM. The I/O port is the basic Input/ Output/Output interface. The microcontroller controls peripheral devices through the I/O port (Output high and low levels). Receiving external control is also through the I/O port to read external voltage signals. Selecting capacitance, the general selection of capacitor voltage value is 2-3 times higher than the application system. Polar capacitors with long pins are positive and short pins are negative. The portion of the capacitor with a small color area corresponds to the negative electrode, and vice versa (for direct plug and patch electrolytic capacitors). The opposite is true for tantalum capacitors. The MCU needs to run the most basic conditions are:

  1. The power supply
  2. Microcontroller chip
  3. Crystal resonance circuit
  4. Reset circuit

    The basic timing sequence of the single chip operation:

    Oscillation period: also known as clock period, refers to the period of the oscillator source that provides the clock pulse signal for the single chip microcomputer.

    Machine cycle: A machine contains12Clock cycles. In one machine cycle, the CPU can perform a single operation.

    In the circuit schematic diagram:

    The resistance of471The word means the resistance value isΩ 47 * 10 ^ 1

    On the capacitor105The word “capacitance” means the capacitance is10*10^5 pF

    Two points with the same network number indicate that the two points are actually connected electrically (with wires).

Lit LED lights

LED, light emitting diode. Its advantages are low power consumption, high brightness, bright color, long life.

Similarly, LED lights are long plus short minus. It is packaged in a similar way to capacitive resistors, and the smallest 0603 package is used on the development board. A chip LED with a small green dot on one end is a negative pole and the other is a positive pole.

The working voltage drop of ordinary LED is1.6 V to 2.1 V. Working current is1~20mA. The voltage drop of ordinary LED is usually0.7 V. Because its operating current is small, it is usually a current limiting resistor.

The principle of



According to the schematic diagram, in order to light the LED lamp, the diode needs to be in the conduction state. Since the signal input from the power supply to the anode is always at a high level, then the cathode can be conduction at a low level, so input to the cathode0Can.

practice

Pit in: When compiling files for projects under construction, remember to compile them inoutputTick Output inhexFile.

Violent lighting

Directly assign a value of 0 to the position where the light needs to be lit.

#include <reg52.h>

sbit LED2 = P1^1;
sbit LED3 = P1^2;
sbit LED5 = P1^4;

void main()
{
    LED2 = 0;
    LED3 = 0;
    LED5 = 0;
}

Multi-port operation The light operates on the 8 ports of P1 together. Since the operation is bitwise, the number assigned to it is binary. The 0 and 1 on the binary digit represent the low level and the high level respectively. Binary high to low corresponds to the eight serial numbers of P1, from the largest to the smallest

#include <reg52.h> void main() { P1 = 0xE9; / / 1110 1001}

2021/05/02

Achieve LED light flashing

Principle Because of the program, the main function will automatically cycle, so if you do not add delay, directly let the LED light on and then off, for people is not to see the flicker. Therefore, in view of the visual retention effect of the human eye, it is necessary to add a delay to make the time interval between the LED light on and off within the visible range of the human eye. The delay is divided into software delay (occupy CPU resources) and timing delay (use registers, do not waste CPU resources). Here, because of beginners, it is adopted to achieve a relatively simple software delay. Practice achieving general flicker

#include <reg52.h> #define uint unsigned int void delay() {uint I = 65535; while(i--); } void main() // Main automatically loops through {P1 = 0; Delay (); delay(); delay(); P1 = 0xFF; Delay (); Delay (); Delay (); }

Achieving controllable delay flicker

#include <reg52.h> #include <reg52.h> #define uint unsigned int void delay_ms(uint z) for(x = z; x > 0; x--) for(y = 114; y > 0; y--) ; } void main() {P1 = 0;} void main(); Delay_ms (100); delay_ms(100); delay_ms(100) P1 = 0xFF; Delay_ms (100); delay_ms(100); delay_ms(100) }

Achieve water light flashing

#include <reg52.h> #include <intrins.h> #define uint unsigned int #define uchar unsigned char void delay_ms(uint z) { uint x, y; for(x = z; x > 0; x--) for(y = 114; y > 0; y--) ; } UCHAR temp;} UCHAR temp;} UCHAR temp; void main() { temp = 0xFE; P1 = temp; P1 = temp; delay_ms(500); while(1) { temp = _crol_(temp, 1); // Loop P1 = temp; delay_ms(500); }}

Finally, I tried to write a little bit of cool light: fancy light

#include <reg52.h> #include <intrins.h> #define uint unsigned int #define uchar unsigned char uchar temp; uint i; void delay_ms(uint z) { uint x, y; for(x = z; x > 0; x--) for(y = 114; y > 0; y--) ; Void left() {temp = 0xFE; void left() {temp = 0xFE; void left() {temp = 0xFE; P1 = temp; P1 = temp; delay_ms(100); for(i = 0; i < 7; i++) { temp = _crol_(temp, 1); // Loop P1 = temp; delay_ms(100); } P1 = 0xFF; delay_ms(150); } void right() {temp = 0x7F;} void right(); P1 = temp; P1 = temp; delay_ms(100); for(i = 0; i < 7; i++) { temp = _cror_(temp, 1); // Move the loop right P1 = temp; delay_ms(100); } P1 = 0xFF; delay_ms(150); } void side_to_mid() {P1 = 0x7E;} void side_to_mid(); delay_ms(200); P1 = 0xBD; delay_ms(150); P1 = 0xDB; delay_ms(100); P1 = 0XE7; delay_ms(100); P1 = 0xFF; delay_ms(150); Void mid_to_side() {P1 = 0XE7;} void mid_to_side(); delay_ms(200); P1 = 0xDB; delay_ms(150); P1 = 0xBD; delay_ms(100); P1 = 0x7E; delay_ms(100); P1 = 0xFF; delay_ms(150); } void all() {P1 = 0x7E;} void all(); delay_ms(200); P1 = 0x3C; delay_ms(150); P1 = 0x18; delay_ms(100); P1 = 0X00; delay_ms(150); } void main() { left(); right(); side_to_mid(); mid_to_side(); all(); while(1); // leave all on}

Debugging tools in Keil

A magnifying glass – like debug function in the toolbar, can see IO port after the execution of the statement changes. Before debug, I remember to click the magic wand icon to set the frequency of crystal oscillator. The frequency of the development board I used was 11.0592MHz. Compile first and then enter the debug mode. After entering the debug mode, you can select the IO port to monitor the state. At the same time, the left window has the program running time and other information, and the lower right window can select specific variables for monitoring. In the upper left corner, you can select debug mode.

buzzer

Principle MCU is used for control, not suitable for driving power devices, so it is not directly connected to the IO port on the buzzer, because its output current is very small, but with a transistor as a switch tube, and then add a current limiting resistor, to control whether the honey machine sound. The DC motor cannot be directly connected to the development board power supply because it has a high backelectromotive force at the end of its rotation and may damage the development board. The practice is to simply modify the code of the water lamp slightly. The buzzer is at port P23. If you directly assign a logic 0 to BEEP, it will emit a continuous beeping sound.

#include <reg52.h> #include <intrins.h> #define uint unsigned int #define uchar unsigned char uchar temp; sbit beep = P2^3; void delay(uint z) { uint x, y; for(x = z; x > 0; x--) for(y = 114; y > 0; y--); } void main() { temp = 0xF0; P1 = temp; delay(100); while(1) { temp = _crol_(temp, 1); P1 = temp; beep = ~beep; // The sound delay(100) is delayed every 100ms; }}

Digital tube

The principle of

Digital tube by 8 LED internal composition, want to display what kind of character, control want to display part of the light, other parts can be extinguished. Generally divided into two kinds, common cathode and common anode. They differ only in the common foot, which isVCCIs a common anode, and isGNDIt’s a common cathode. The type of digital tube can be measured by connecting the common pin with any other pin with a multimeter.

The common leg of the digital tube is calledA selectedThe other feet are calledsegment. The bit selection is used to select which digital tube lights up, and the segment selection is used to select which LED lights on the digital tube.

In the development board I used, the digital tube is of common cathode type. Since the common pin of their cathode connection is grounded and at a low level, the LED tube can be electrified by inputting a high level into the digital tube.

Digital tube display is divided intoStatic displayandDynamic display. Let’s learn more about static display here.

Static display takes more IO port, because each digital tube segment selection must be connected to an 8-bit data line to maintain the displayed glyph, the glyph displayed can be maintained until a new glyph is sent.

latch

Data input and output can be isolated or connected.

In order to74HC573For example:





Output Q to output high and low levels, OE pin must be connected to GND.

When LE pin is high, the output Q changes with the data of the input D. When the pin of LE is low, the data of Q at the output end remains unchanged, while the data of D at the input end will not change the data of Q.

Pull-up resistors

To pass an uncertain signal through a current limiting resistor (typically10 k to 4.7 kOhm resistance) clamp at high level, pull down the same, clamp at low level.Quasi two-way IOWith a pull-up resistor in the output circuit, it can output both high and low levels, while a drain open-circuit output circuit, which has no pull-up resistor, can only output low levels. Inputting a high level leaves it open.

2021/05/03