C51 commonly used data types
Data type |
Key words |
The number of occupied positions |
Represents a range of numbers |
unsigned character type |
unsigned char |
8 |
0~255 |
Signed character type |
Char |
8 |
-128~127 |
Unsigned integral type |
unsigned int |
16 |
0~65535 |
Signed Integral type |
Int |
16 |
-32768~32767 |
unsigned long integer type |
unsigned long |
32 |
0~2^32-1 |
Signed Long integer type |
Long |
32 |
-2^31~2^31-1 |
Single-precision Real |
Float |
32 |
3.4e-38~3.4e38 |
Double-precision Real |
Double |
64 |
1.7e-308~1.7e308 |
Bit type |
Bit |
1 |
0~1 |
2.c51 data type extension definition
There are many special function registers inside the MCU, each register has a unique address within the SCM, and it is generally given different names according to the function of the register. operation, you need to declare, the address number is assigned to this name. (See Reg52.h header file)
SFr |
Declaration of a special function register, declaring a 8-bit register |
Sfr16 |
Data declaration for 16-bit special function registers |
Sbit |
A special function bit declaration, that is, declaring one of the special function registers |
Bit |
Bits declare variables that can be used when a bit variable is defined |
3. Why light-emitting diodes are connected to 1kω resistors
Light emitting diode, through the current I is 5mA can be illuminated, general control in the 3~20ma, the current is too large to burn.
The light-emitting diode has a voltage drop of 1.7V and a power supply of 5 v. 3.3 = 5-1.7.
3.3v/1000ω= 3.3mA
When the 1kω resistor is approximately connected, the diode glows normally, and this resistor is also known as the current-limiting resistor.
4. Single chip microcomputer next to the crystal vibration of two capacitor action
① The crystal oscillator of the general monolithic microcomputer works in the parallel resonant state, also can be understood as part of the resonant capacitance. (symmetry is needed to satisfy the resonance condition)
It is according to Crystal oscillator manufacturers to provide the crystal vibration required load capacitance selection, in other words, the crystal oscillator frequency is measured under the load capacitance it provides, can maximize the frequency of the error. can also guarantee temperature drift and other errors.
From the principle of direct crystal vibration to a single-chip microcomputer, single-chip microcomputer can work. However, in this form of oscillation circuit will produce harmonics (that is, unwanted other frequencies of the wave), this wave has little effect on the circuit, but will reduce the circuit clock vibration
Stability of the swing device. That is, only when the external capacitor is matched with a capacitor, the oscillation frequency is guaranteed to be within the error range near the nominal frequency. The capacitor acts as a filter (DE-clutter).
② due to the single-chip microcomputer power supply for switching power supply, instability, the two decoupling capacitors play a role of buffering regulator.
More commonly used for 15P-30PF. The value of two capacitance is the same, or the difference is not small, if the difference is too large, prone to the imbalance of resonance, easy to cause a stop vibration or simply do not start the vibration.
5. Latch device
74hc573
OE (dash) out enable enable: low-efficient. The direct grounding here means that it is valid. High Q shows a high impedance state, that is, its level depends on the circuit connected to it.
Le is controlled by single-chip microcomputer, when Le High, q=d, can control the light-off of the LED lamp in real time. At Le Low, the d=q0,q0 is the last level state.
Because the single-chip microcomputer PIN is limited, the same IO port is used to control different circuits. When the Le is low, the LEDs do not change with the IO level, ignoring them and reducing their impact.
6. Light the first LED
Bit Operation method
1 #include <reg52.h>2 sbit LED0 = p1^0; 3 4 int Main () 5 {6 0 ; 7 return 0 ; 8 }
Bus method
1 #include <reg52.h>23int main ()4{5 0xFE; // from high to low p1^7 ... P1^06 return0; 7 }
10-day Learning single-chip microcomputer Day0 lit LED