You are on page 1of 7

Anurag Banerjee (ab39826)

Joseph Lubars(jpl754)

EE445L Lab 1 Report:

Objectives:
This lab was largely designed to teach us how to interface with a few key software and
hardware tools for the embedded systems lab. In particular on the software side, in this lab, we
learned how to operate the Keil development platform and standard C coding methodologies/
development standards. On the hardware side, we learned how to flash programs to the
Stellaris kit for an OLED fixed point display.

Questions:
In the following lab, we developed some basic fixed point display operations for OLED display.
In particular, we wrote routines for outputting fixed point numbers in a variety of precisions
and formats.
1. The call graph for an embedded software system graphically shows how all the associated
modules of the system are interconnected with procedural calls for inputs and outputs. Good
software design should seek to modularize as many components of the system as possible for
ease of debugging and implementation. the rit128x96x4.c module is the driver for the OLED
display on the hardware kit. While the fixed.c module is the software for handling input and
output for fixed point representation. Because the OLED display driver exclusively deals with
the hardware graphical interface of the system, it should not need any direct knowledge of how
fixed.c is operating. Rather, it should only seek to display whatever formatted string is passed in
as input through the printf function. This represents good modularized design and
2.This property aligns numbers for clarity in viewing and observing large amounts of data.

3. Ideally you would want to use fixed point operations over floating point operations if you
know a priori what the valid range of values should be. In addition, the fixed point standard
gives accuracy over the floating point standard in base 10. Finally, for the ARM cortex M3, fixed

point operations can be done in hardware and are therefore faster than floating point
operations which must be done on a software level.

4. Binary fixed point has the advantage of yielding quick bit shift operations while decimal fixed
point is ideal when you are exclusively dealing with decimal numbers and want to accurately
represent the numbers without floating point protocols.

5. In financial operations such as cash registers, we know beforehand that the smallest
denomination of currency is the penny. Multiple transactions of buying and selling goods must
be done quickly and accurately. Therefore, decimal fixed point arithmetic is ideal for this
situation with the resolution equal to .01.

6. Yes we can, however, the cost is additional software processing because there is no built-in
hardware suppport for floating point operations. *MMX instruction set reuses existing floating
point registers making the CPU unable to work on both floating point and SIMD data at the
same time without a slow switching operation.

Software
Test.c
#include <stdio.h>
#include "fixed.h"

const struct outTestCase{


unsigned long InNumber;
char OutBuffer[10];
};

// used to test routines


// test input number
// Output String

typedef const struct outTestCase outTestCaseType;


outTestCaseType outTests256[8]={
{

0, " 0.00" }, //

0/256 = 0.00

4, " 0.01" }, //

4/256 = 0.01

{ 505, " 1.97" }, // 505/256 = 1.97


{ 1070, " 4.17" }, // 1070/256 = 4.17
{ 5120, " 20.00" }, // 5120/256 = 20.00
{ 32768, "128.00" }, // 32768/256 = 128
{255998, "999.99" }, // 255998/256 = 999.99
{256000, "***.**" } // error
};

outTestCaseType outTests3[8]={
{-10000, "***.**" },
{ -9999, "-9.999" },
{ -1000, "-1.000" },
{ -50, "-0.050" },
{

0, " 0.000" },

{ 789, " 0.789" },


{ 9999, " 0.999" },
{ 10000, "***.**" }
};

outTestCaseType outTests2[8]={

0, " 0.00" },

9, " 0.09" },

{ 10, " 0.10" },


{ 100, " 1.00" },
{ 999, " 9.99" },
{ 9999, " 99.99" },
{ 99999, "999.99" },
{100000, "***.**" }
}

unsigned int Errors,AnError;


char Buffer[10];
void main(void){ // possible main program that tests your functions
unsigned int i;
Errors = 0;
AnError = -1;
for(i=0; i<8; i++){
Fixed_uDecOut2s(outTests2[i].InNumber,Buffer);
if(strcmp(Buffer, outTests2[i].OutBuffer) != 0){
Errors++;
AnError = i;
}
}
if (AnError != -1) {

printf("Error found in Fixed_sDecOut3s: %d", outTests2[AnError].InNumber);


AnError = -1;
}
for(i=0; i<8; i++){
Fixed_sDecOut3s(outTests3[i].InNumber,Buffer);
if(strcmp(Buffer, outTests3[i].OutBuffer) != 0){
Errors++;
AnError = i;
}
}
if (AnError != -1) {
printf("Error found in Fixed_sDecOut3s: %d", outTests3[AnError].InNumber);
AnError = -1;
}
for(i=0; i<8; i++){
Fixed_uBinOut8s(outTests256[i].InNumber, Buffer);
if(strcmp(Buffer, outTests256[i].OutBuffer) != 0) {
Errors++;
AnError = i;
}
}
if (AnError != -1) {
printf("Error found in Fixed_uBinOut8s: %d", outTests256[AnError].InNumber);
}

if (Errors == 0) {
printf("All tests passed!");
}

for( ; ; ) {}
}

Fixed.h
No changes were made from the starter fixed.h file.

Fixed.c
#include "fixed.h"
#include <stdio.h>

const char* stars = "***.**";


const char* stars2 = "**.***";

void Fixed_uDecOut2s(unsigned long n, char *string) {

if(n > 99999) {


sprintf(string, "%s", stars);
} else {
sprintf(string, "%3d.%.2d", n/100, n%100);
}
}

void Fixed_sDecOut3s(long n, char *string) {


int sign;
if (n > 9999 || n < -9999) {
sprintf(string, "%s", stars2);
} else {
if(n < 0) {
sign = -1;
} else {
sign = 1;
}
sprintf(string, "%2d.%.3d", n/1000, sign * n%1000);
}
}

void Fixed_uBinOut8s(unsigned long n, char *string) {


if(n >= 256000) {
sprintf(string, "%s", stars);
} else {
n = n*100/256;
sprintf(string, "%3d.%.2d", n/100, n%100);
}
}

You might also like