Hardware Reference
In-Depth Information
#include “c:\cwHCS12\include\convert.h”
#include “c:\cwHCS12\include\stdio.h”
int main (void)
{
const char *ptr 5 “ seconds passed!”;
char buf[20];
int cnt;
DDRB 5 0xFF; /* configure port B for output */
cnt 5 0;
/* initialize count to 0 */
while(1) {
delayby100ms(5);
int2alpha(cnt,buf);
putsr(&buf[0]);
puts(ptr);
cnt 11 ;
PORTB 5 cnt;
newline();
}
return 0;
}
L5.2 Write a C program that will generate every third integer, beginning with i 5 2 and continu-
ing for all integers that are less than 300. Calculate the sum of those integers that are divisible by
5. Store those integers and their sum in an array and as an integer variable, respectively.
L5.3 Write a C function that calculates the least common multiple (lcm) of two integers m and
n . Integers m and n are parameters to this function. Also write a main program to test this func-
tion with several pairs of integers. Use the library functions to convert and output the results.
L5.4 Use the seven-segment display circuit shown in Figure 4.18 and write a program to
display the following sequence of digits with each sequence lasting for half a second:
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
(6)
7 6 5 4 3 2
8 7 6 5 4 3
9 8 7 6 5 4
0 9 8 7 6 5
1 0 9 8 7 6
2 1 0 9 8 7
3 2 1 0 9 8
4 3 2 1 0 9
5 4 3 2 1 0 (15)
After displaying these 15 sequences once, repeat sequence 6 to 15 forever.
L5.5 Write a program to generate a four-tone siren using the PP5 pin with each tone lasting for
half a second. The frequencies of these four tones are 100 Hz, 250 Hz, 500 Hz, and 1000 Hz. The
PP5 pin is connected to a buzzer via a jumper on the Dragon12-Plus demo board.
 
Search WWH ::




Custom Search