![]() ![]() The bounce behavior will differ from switch to switch, but 20-30 milliseconds is typically quite sufficient. The debounce time needs to be adjusted to the time it takes the switch to go from a digital high to a digital low after all the bouncing. The final two define statements setup times, in millisecond, to debounce the switch and the time to wait before allowing another press of the button. #define LED3 2 // Led3 connected to port D pin 2 #define LED2 1 // Led2 connected to port C pin 1 #define LED1 0 // Led1 connected to port B pin 0 #define BUTTON1 1 // button switch connected to port B pin 1 ![]() Using the defines statements like this allows us to only need to modify 3 easy-to-find lines if we move the LED to a different I/O pin or use a different AVR. We use defines to declare our button and LED's ports and pins. The function we'll be using, is _delay_ms(). The library util/delay.h contains some routines for short delays. #include // header to enable delay function in program It simply defines the constants for all your pins, ports, special registers, etc. io.h will determine the CPU you're using (which is why you specify the part when compiling) and in turn include the appropriate IO definition header for the chip we're using. The first include file is part of avr-libc and will be used in pretty much any AVR project you work on. #endif #include // header to enable data flow control over pins. #define F_CPU 16000000UL // telling controller crystal frequency (16 MHz AVR ATMega328P) #How to code assembly in avr studio 5 how toIn this case it is used by the delay routines to determine how to calculate time delays. The first few lines we have some compiler defines.į_CPU defines the clock frequency in Hertz and is common in programs using the avr-libc library. If you don’t have Atmel Studio, you should download and install it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |