Lights up an LED light on the ARV microcontroller Development Board
Schematic:
Analysis: The above figure shows the connection principle between the single-chip microcomputer and the LED lamp. Among them, J6 is a blocking function, which can throttling to prevent the LED from burning out when the current is too large.
The internal resistance is a set of parallel resistors:
Tip:
Calculate the size of the resistance. The operating current of the diode is 3mA, the operating voltage is 1.7 V, and the voltage of the VCC is 5 V. So the current on the resistance is 3mA, and the voltage is 3.3 V, so the resistance is 1.1kb.
Because all diodes are shared by a throttling resistor, you only need to assign a low level to the Q end to light up the emitting diode. The Q-side level is controlled by a 573 lock on the D-side level, that is, the Pb port of the microcontroller. In this way, we can write a program to control the high and low levels of the Pb port to enable the diode to crash.
The principle of 573 latches is also used here:
When the microcontroller uses this port to control other circuits, it needs to modify the port level value, which will affect the original level value. So we need to use latches to maintain the original level, and it will not be affected by the new level value of the port.
Light up a light emitting diode program code:
1 /************************************** **************************************** ** 2 * features: 3 * Light up the first light emitting diode 4*5 * header file: 6 * the I/O port of the original single chip microcomputer is a hexadecimal address, which is very inconvenient to remember, therefore, the header file 7 * is encapsulated to facilitate memory. During program compilation, the header file is pasted as it is, and restored to the original hexadecimal address for the hardware. 9 * <avrdef. h> is the new version of <macros. h>. 10*11 ************************************* **************************************** * **/12 # include <iom16v. h> 13 # include <macros. h> 14 15 void main (void) 16 {17 // set the pa2 port to the output high level, and control the lock end of the latch 573 to connect to 18 ddra | = bit (2 ); 19 Porta | = bit (2); 20 // The D port of the latch is controlled by the Pb port. Therefore, set the 0th bits of the Pb port to the output low level, other 7-bit output high 21 // light the first diode 22 ddrb = 0xff; 23 portb = 0xfe; 24}
The first light emitting diode flashes:
1 /************************************** **************************************** ** 2 * features: 3 * The First Light Emitting Diode flashes 4*5*6 **************************** **************************************** * ***********/7 # include <iom16v. h> 8 # include <macros. h> 9 10 # define uint unsigned int11 # define uchar unsigned char12 13 void main (void) 14 {15 uint C = 0; 16 17 // set the pa2 port to the output high level, connect the lock end of the control latch 573 to 18 ddra | = bit (2); 19 Porta | = bit (2 ); 20 21 // set the working mode of the Pb port to 22 ddrb = 0xff; 23 24 while (1) 25 {26 // light up the first led27 portb = 0xfe; 28 29 // here is the implementation of the delay function 30 c = 5000; 31 While (c --); 32 c = 5000; 33 while (c --); 34 35 // extinguish the first led36 portb = 0xff; 37 38 // here is the implementation of the delay function 39 c = 5000; 40 while (c --); 41 c = 5000; 42 while (c --); 43} 44}
Here, c -- can be implemented using a delay () function:
1 void delay(void)2 {3 uint x,y;4 for (x = 0; x < 500; x++ )5 {6 for(y = 0; y < 1000; y++);7 }8 }
Supplement
Record 51 microcontroller diode control circuit schematic diagram:
[003] AVR Microcontroller controls Light Emitting Diode