Lab One - Lab One - ATmega644 Microcontroller and Digital...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab One - ATmega644 Microcontroller and Digital Input/Output Wallace Kerrigan, 1541317 wallace.kerrigan@uconn.edu 26 September 2011 Part One
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Figure 1. Flow Chart for Microcontroller LED Delay Program Explanation An unsigned character and two unsigned long variables were defined as “i”, “j”, and “slendy”, respectively at the beginning of the program following the header. These were all used later in the code. Pins 2, 3, 4, and 6 were then defined from PORTD, which enabled use of the LEDs. The switches from PINB were then defined right after so they were accessible. Following a “for” statement, PINB was assigned to an unsigned character “b”. For an unknown reason, simply using PINB to refer to it did not work as the LEDs did not function as intended. A switch case was implemented to set up a different case for the sixteen combinations. The sixteen different combinations each had their own input from PINB, which was written in hexadecimal. The unsigned long “slendy” was then used to determine exactly how fast the LEDs would blink when a different combination of switches was used. Each case would then end with a “break”. The remaining “for” statements were from the original sample code and simply toggle the LEDs on and off at the defined frequency; in this case, the default frequency is set as “slendy” at a value of 5000. Code #include <avr/io.h> void wait (void) { asm volatile ("nop"::); } int main (void) { unsigned char i; unsigned long j; unsigned long slendy;
Background image of page 2
DDRD = 0x5C; // Configure PORTD pins 2, 3, 4, 6 as output DDRB = 0xF0; for(;;) { unsigned char b = PINB; // Assign PINB as the char b switch (b) // Set up a switch case for b { case 0x00: slendy = 100000; break; case 0x01: slendy = 95000; break; case 0x02: slendy = 90000; break; case 0x03: slendy = 85000; break; case 0x04: slendy = 80000; break; case 0x05:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/21/2011 for the course ECE 3411 taught by Professor Park during the Fall '11 term at UConn.

Page1 / 9

Lab One - Lab One - ATmega644 Microcontroller and Digital...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online