You are on page 1of 1

EE 354 October 24, 2012

ARM C Examples

1. Given below is a program in C which does nothing but call a subroutine named Delay
which uses empty for loops to create a software delay. The software delay uses an empty
for loop with an integer counter.
A) Run the program as is in the debugger and determine the length of the time delay.
B) Change the delay loops from using integer variables to unsigned char variables
and determine what difference that makes in the time delay. Explain.

//Delay.c
//This program illustrates a software delay.
#include <lpc213x.h>
void Delay(unsigned char);
void main()
{while(1)
Delay(1);
}
//
void Delay(unsigned char x)
{int c;
int i;
for(i=0;i<x;i++)
for(c=0;c<255;c++);
return;
}

2. Write a program in C to toggle bit P1.31 as fast as possible using IOSET and IOCLR.
Repeat this program using IOPIN.

3. Write a program to input from P1.31. If P1.31 is a 1 count up on pins P1.16-1.23.
Otherwise, count down on those pins. Demonstrate that your program works using the
debugger.

4. Write a program in C that shows how to use the switch statement to select one of four
different subprograms based on the state of bits P1.30 and P1.31.

5. Given a signal which ranges from -12 to +12 volts. Write the equation to scale this
signal and send it to the D to A converter and produce an output signal in the range 1 to 3
volts. Assume the D to A reference voltage is 3.3 volts.

6. If
)
`

=
6
) 3 sin(
) sin(
4
) (
x
x x f
t
write a program to send this function to the D to A
converter. f(x) will vary from -1 to +1 and will have a period of 2. Use 100 increments
per period and run forever.

You might also like