circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

August 2004, Issue 169

Ham Radio Repeater Locator


by Glen Worstell

MODULAR CODE

It’s possible to write modular code in C language, even though not all the capabilities of languages like Modula-II are available. Much of the popularity of object-oriented code comes from the fact that it’s easy to write modular code in object-oriented languages. For many embedded applications, you don’t need objects and won’t derive any benefits by using them. However, understandability and maintainability are benefits derived by using modular code, even for fairly small projects like this one. One of my goals was to present the code in an easy-to-understand format.

Listing 1 is an example of a module used to calculate the distance between a station and the current GPS position. When a routine is in a module, its name is prefixed by the module name. The funcs module contains various functions, so the routine is called funcs_u16milesBetween().

Listing 1—You can calculate the distance between a station and the current GPS position. Note that when a routine is in a module, its name is prefixed by the module name.

In C language it’s extremely important to keep track of the integer variable sizes because the compiler sometimes performs conversions that you don’t want. To emphasize the sizes of variables, I often use definitions such as U8 for an 8-bit unsigned variable. These definitions are collected in a #include file for use by all modules.

Occasionally, when it’s important for clarity, I use Hungarian notation, which includes the type information in a variable or function name. The milesBetween() function returns an unsigned 16-bit integer, so the function name emphasizes that important fact. A square-root function named i32Sqrt() is called and to make it clear that the function returns a 32-bit integer.

Warning: there are bugs in the compiler that are likely to show up when complicated expressions are used. Hence the otherwise unnecessary temporary variables like index and temp. The code would be harder to read without the temporary variables, so it’s probably better that it’s written this way. The compiler bugs force good coding practice! 

IN OPERATION

The Ham Radio Repeater Locator breadboard is now in use. It performs just as I had envisioned.

If there is sufficient interest, a PCB could be provided, perhaps with a preprogrammed microcomputer. It would be nice if you could obtain the ARRL’s permission to include its repeater database, or if you could find another source of repeater information. A switch-selectable interface to various popular transceivers would be a worthwhile addition.