// Lab1.c : Skeleton file for Lab 1 C code ////////////////////////////////////////////////////////////// // Authors: Lab member 1 lab1@iastate.edu // Lab member 2 lab2@iastate.edu // // Lab: 7-9 AM, Monday // // TA: Cpr E 211 TA // // Instructor: Cpr E 211 Instructor // ////////////////////////////////////////////////////////////// // Description: // // Print out the hex and binary values of the DIP switches ////////////////////////////////////////////////////////////// #include "defines.h" // Memory addresses for I/O ports #include "QTerm.h" // Output to QTerm LCD void PrintSwitch (char); void Go_Lab1 () { char * pDIPSwitch1; char * pDIPSwitch2; char * pBargraph1; char * pBargraph2; // Initialize pointers (i.e. point them somewhere) // // Defined in defines.h // pDIPSwitch1 = (char *) IO_DIGITAL_INPUT_DIP_1; pDIPSwitch2 = (char *) IO_DIGITAL_INPUT_DIP_2; pBargraph1 = (char *) IO_DIGITAL_OUTPUT_LED1; pBargraph2 = (char *) IO_DIGITAL_OUTPUT_LED2; // Set up the LCD screen LCD_Init(); // Do an infinite loop since 1 is always non-zero (TRUE) while(1) { LCD_Clear(); PrintSwitch(*pDIPSwitch1); LCD_PutString("\r"); PrintSwitch(*pDIPSwitch2); // Write the DIP switches out to the bargraphs // // *(IO_DIGITAL_OUTPUT_LED1) = *(IO_DIGITAL_INPUT_DIP1); *pBargraph1 = *pDIPSwitch1; // *(IO_DIGITAL_OUTPUT_LED2) = *(IO_DIGITAL_INPUT_DIP2); *pBargraph2 = *pDIPSwitch2; msleep(4000); } } void PrintSwitch (char byVal) { char szTemp[60]; // Print the result to a string first, then send the string // to the LCD // sprintf = string printf sprintf(szTemp, "DIP Switch: 0x%02X\r", (unsigned char) byVal); LCD_PutString(szTemp); LCD_PutString(" Bin = "); // INSERT CODE HERE // Write the code to dump the binary value of byVal to the // LCD screen. // // Hints: // - Use LCD_PutChar to send an individual character // LCD_PutChar('1'); // - The char size is 8 bits, what kind of a loop lets // you run a fixed number of times // - To test each bit, you can either change the position // of the tester or the variable itself // - What type of bitwise test lets you see if a bit // is on? // Bitwise AND & - single ampersand // // Psuedocode // Loop 8 times // If the MSB (Most Significant Bit) of byVal is set // Print a 1 // Else // Print a 0 // Shift over byVal once to the left }