Order:
Previously, we used the stc51 + feisikar xs128 combination, which is simple to write with 51, and complicated to use xs128. For the AVR, PIC, and STM series, we only heard their voices and did not see anyone. Recently, the first contact with the AVR was started due to the use of the electromagnetic magnetic field generator of the flykar system.
To put it simply, there are internal pull-up resistors, 30ma pull-up current and fill current on the pin, PWM and ADC on the internal hardware, and the price is not expensive. I officially decided to use atmege8 instead of 51.
Port Operations:
The AVR port is a real two-way port, unlike the 51 pseudo two-way port. This is also an advantage of AVR, but you can pay attention to ddrn during operations. Real bidirectional ports are not as convenient as pseudo bidirectional ports in analog timing.
Ddrn portn PINN explanation: n is the port number: ABCDE
Ddrn: whether the control port is input or output. 0 indicates input, and 1 indicates output. Personal memory method: it is bigger than zero, so it is crowded out, that is, 1 is the output, 0 is the input.
Portn: output signal from the pin. When ddrn is 1, you can assign values to the output through port operation statements such as portn = x.
PINN: Read the input signal from the pin, regardless of ddrn value, the external level of port N can be obtained through X = PINN.
Description of ddxn portxn pud (in sfior) I/O pull-up Resistance
0 0 X Input no high impedance (hi-Z)
0 1 0 input Yes output current when the external circuit is low
0 1 1 input no high impedance (hi-Z)
1 0 x output no output low level (leakage current)
1 1 x output no output high (pulling current)