avr programming: digital i/o september 10, 2010
DESCRIPTION
AVR Programming: Digital I/O September 10, 2010. What is Digital I/O?. Digital – A 1 or 0 Input – Data (a voltage) that the microcontroller is reading from an external source Output – Data (a voltage) that the microcontroller is setting to be used by an external source. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/1.jpg)
AVR Programming:
Digital I/OSeptember 10, 2010
![Page 2: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/2.jpg)
What is Digital I/O?
Digital – A 1 or 0 Input – Data (a voltage) that
the microcontroller is reading from an external source
Output – Data (a voltage) that the microcontroller is setting to be used by an external source
2
![Page 3: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/3.jpg)
Where does this happen?
I/O Ports 6 8-bit I/O ports
(A-F) 1 4-bit I/O port (G) Most have an
alternate purpose
3
![Page 4: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/4.jpg)
How do I access these pieces of metal in software?
They are memory mapped Certain memory addresses are reserved for I/O
Registers A few examples (Ports A-D):
4
![Page 5: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/5.jpg)
55
Do I need to memorize those addresses? No! #include <avr/io.h> Each register and bit within it is defined for you
![Page 6: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/6.jpg)
6
How does this look in code?
//set the bottom three bits of Port A to outputDDRA |= _BV(DDA0) | _BV(DDA1) | _BV(DDA2);
//output high on pins 0 and 2 of port APORTA |= _BV(PA0) | _BV(PA2);
//output low on pin 1 of port APORTA &= ~(_BV(PA1));
//set Port B to input DDRB = 0x00;
//read Port Bchar x = PINB;
![Page 7: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/7.jpg)
7
What can we do with this on the robots?
Note: Pin 33 and 34 are PG0 and PG1
![Page 8: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/8.jpg)
8
Stuff to try out
Reading from the push buttons – make sure to enable internal pull up (PORTG |= 3;)
Turning on the orbs Rapidly turning the orbs on and off
– Maybe even in patterns (off off on off off on…) Rapidly switching orb colors
– e.g. (blue green off blue green off…) Combinations of above You should not need the dragonfly library
![Page 9: AVR Programming: Digital I/O September 10, 2010](https://reader035.vdocuments.site/reader035/viewer/2022062305/56816134550346895dd08f42/html5/thumbnails/9.jpg)
9
Help/More Info
Datasheet:http://www.atmel.com/dyn/resources/prod_documents/doc2467.pdf