How does AVR microcontroller Realizes LED Flashing?

ATmega16 has four 8-bit bidirectional I/O ports PA, PB, PC, PD. They correspond to 32 I/O pins externally. Each bit can be used independently for the input and output of logic signals. Working at 5V At the voltage, when the output is high, each pin can output a drive current of 20mA. When the output is low, each pin can absorb a maximum of 40mA.

All I/O registers of the AVR microcontrollers can be accessed in two different ways: using IN and OUT dedicated instructions that access the I/O registers or using instructions that are accessed to the SRAM. The IN, OUT instruction cycle is 1 clock. In addition, registers with the I/O register address range between $00 and $1F (the first 32) can also be used to implement bit operations and bit judgment jumps. For example: SBI (I/O register designation location 1), CBI (I/O register designation bit is cleared to 0), SBIS (I/O register designation bit is 1 jump), SBIC (I/O register designation bit is 0 jump). The detailed manual is king.

Simulation circuit diagram (LED may not be visible, save as or open a new window):



Test procedures, changes can observe different phenomena, help understand. The difference between 51 and 51 is the direction control of the IO port.



/*

* AVRGCC.c

*

* Created: 2012/5/27 18:09:54

* Author: KISSMonX

*/

#define F_CPU 4000000UL

#include

#include

Int main(void)

{

PORTC = 0x80; // Bit 0/7 of the PC port outputs "0"/"1", both LED1 and LED2 are on.

DDRC = 0x81; // Define the 0th and 7th bits of the PC port as the output mode

_delay_ms(2000); // Both LEDs will be on at the beginning, and will enter the loop after 2s.

While(1)

{

_delay_ms(200); // library function ms delay function, 0.2s

PORTC = ~PORTC; // The 0/7 bit of the PC port is inverted and output

}

Return 0;

}

留言

這個網誌中的熱門文章

Vicor Introduces the Latest 800V bus Converter Module

Why Computer/Cell Phone manufacturer, TSMC support Huawei?

Top 8 Semiconductor Companies in the World