In previous video, we learnt to make a LED blink.
In this video, we will learn to make a LED blink using a button.
To pick up a button, click on “P” in proteus 8.
Use PINA.0 to connect button.
Use pull-up circuit for button.
Pay attention how to insert pull-up circuit.
For a pull-up circuit, a button, power source and resistor are required.
Set initial value equal to “0” and data direction as input. So:
In AVR CodeVision:
“PORTA=0x00;“. “00” in BCD mode is “0000 0000”.
“DDRA=0x00;”. PINA.0 is utilized as input.
PINA.0 is used as input and has initial value of “0”.
In AVR CodeVision
“PORTA=0x00;” and “DDRA=0x00;”
When button is pressed, LEDs will blink.
Conditional expressions.
When conditions inside brackets () are met, statements inside curly brackets {…} are performed.
If ()
{…}
In this example, PINA.0 must have logic value of “0” until LEDs blink.
If (PINA.0 == 0) // condition
{
PORTD.0 = 0; //expressions inside {} curly brackets will perform
PORTD.7 = 0;
delay_ms(500);
PORTD.0 = 1;
PORTD.7 = 1;
delay_ms(500);
}
If PINA.0 has logic value of 0, expressions inside { } will perform.
In proteus 8
In projet tab select “build all”.
Double click on ATMEGA16.
Download EXE file to ATMEGA16.
In proteus click on play.
▶️ DTube
▶️ BTFS