ECE2801_hw2_C08_sol

ECE2801_hw2_C08_sol -...

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

View Full Document Right Arrow Icon
(DUE Thursday 1/24/08 At the BEGINNING of class) SHOW ALL WORK !    To ensure proper grading and return, include the  following information at the top of each  assignment you submit:  Name,  Course # and HW#, WPI e-mail, ECE Box #. 1)  Finish commenting the following C code segment succinctly describing what  each line does.  Then, in a few well written sentences, describe what the whole  code segment does.   (20 pts) #include "msp430x44x.h"     // msp430F header file           #include <stdlib.h>         // C standard library   #include <stdio.h>          // C standard IO library #define ASCII_0  0x30   // ASCII code for ‘0’ = 30h #define ASCII_9  0x39   // ASCII code for ‘9’ = 39h #define MAX_DIGITS  4   // read a maximum of 4 digits per number // Returns ASCII representation of last key  // pressed '0'-'9' or '+','-'  int myGetKey();   // Function prototype  /* This code gets 2 numbers and an operator, either  + or –  */  void main() { // declare variables      unsigned char    ascii_num1[4], ascii_num2[4];      unsigned char    operator=0, hitKey=0;      unsigned int     num1=0, num2=0, digit=0; /* This first while loop gets up to 4 digits from the keypad. It  assumes that the digits are entered left to right. The number is  stored both as ASCII and as an integer because the LCD display  routines use ASCII number representations while math operations  require integer representation */      while (hitKey==0)      {     hitKey = myGetKey();    // check for key press     /* While key is digit 0-9 and number of digits less than 4 */    {
Background image of page 1

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

View Full DocumentRight Arrow Icon
/* Shift arrays of ascii digits to the “left” */  for (i = 0; i < digit; i++)    ascii_num1[digit-i] = ascii_num1[digit-i-1];
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/24/2009 for the course ECE 2801 taught by Professor Jarvis during the Spring '08 term at WPI.

Page1 / 5

ECE2801_hw2_C08_sol -...

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

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