manufacturer of I/O-rich SBCs, operator interfaces, handheld instruments, and development tools for embedded control low cost single board computers, embedded controllers, and operator interfaces for scientific instruments & industrial control development tools for embedded control order our low cost I/O-rich embedded control products embedded controller manufacturer profile single board computers & embedded controllers development tools & starter kits for your embedded design operator interfaces with touchscreens and graphical user interface plug-in expansion modules for digital & analog I/O C language & Forth language integrated development tools, IDE single board and embedded computer accessories embedded controller enclosures, bezels, environmental gaskets

The C Programmerís Guide to the QVGA Controller

Table of Contents


Introduction. How to Use This Manual

Chapter 1: Getting to Know Your QVGA


Chapter 2: Your First Program

Chapter 3: The IDE: Writing, Compiling, Downloading and Debugging Programs

Chapter 4: Making Effective Use of Memory

Chapter 5: Programming the Graphical User Interface

Chapter 6: Real Time Programming

Chapter 7: Failure and Run-Time Error Recovery


Chapter 8: Digital and Timer-Controlled I/O

Chapter 9: Data Acquisition Using the QVGA Controller

Chapter 10: Outputting Voltages with Digital to Analog Conversion

Chapter 11: Serial Communications

Chapter 12: The Battery-Backed Real Time Clock


Chapter 13: A Turnkeyed Application


Appendix A: QVGA Electrical Specifications

Appendix B: Connector Pinouts

Appendix C: Physical Dimensions

Appendix D: Schematics (pdf)

Chapter 12

<< Previous | Next>>

Chapter 12: The Battery-Backed Real-Time Clock

The battery backed real time clock is set and read using the Control-C functions ReadWatch() and SetWatch()functions READ.WATCH and SET.WATCH.† In C, these two routines access a fixed pre-allocated structure in the 68HC11's on-chip RAM using structure macros defined in the WATCH.H header file.† For example, the following code reads the watch and stores the current minute (after the hour) in the variable named current_minute:


static int† current_minute;


current_minute = WATCH_MINUTE;

Because the structure that is written to by ReadWatch() is at a fixed location, this code is not re-entrant.† This is not a problem in single-task applications or applications where only one task uses the watch.† But it can cause problems if multiple tasks are executing ReadWatch().† For example, assume that task #1 calls ReadWatch(), but before it can access the contents of the structure using the assignment statement, the timeslice interrupt occurs and task#2 proceeds to call ReadWatch(), then the contents of WATCH_MINUTE could be changed before task#1 is able to execute its assignment statement.† To avoid this situation, the multitasking application can be configured so that only one task calls ReadWatch() and SetWatch() and shares the data with other tasks.†

Another option is to define a resource variable to mediate access to the watch.† The routines needed to accomplish this are declared in the MTASKER.H file and described in detail in the Control-C Glossary. The following brief example illustrates how to design a re-entrant function that returns the current WATCH_MINUTE:


RESOURCE watch_resource;†††† // declare resource variable: controls

†††††††††††††††††††††††††††† // watch access

† _Q int CurrentMinute(void) // reads watch, returns current minute

†† {† int minute;

††††† GET(watch_resource);†† // get access to watch; Pause() if

†††††††††††††††††††††††††††† // another task has it

††††† ReadWatch();†††††††††† // updates contents of watch structure

††††† minute = WATCH_MINUTE;

†††††††††††††††††††††††††††† // you can also transfer other contents

†††††††††††††††††††††††††††† // from the watch structure to

†††††††††††††††††††††††††††† // "task-private" variables here

††††† RELEASE(watch_resource); // release access to watch so other

†††††††††††††††††††††††††††† // tasks can use it

††††† return minute;

†† }

The CurrentMinute() function can be simultaneously called from multiple tasks without causing any conflicts.† The GET() and RELEASE() macros automatically mediate access to the watch, ensuring that only one task has access at a time.

Interrupts are disabled during the entire operation of the functions ReadWatch() and SetWatch()READ.WATCH and SET.WATCH for approximately 0.5 and 0.45 msec respectively.†

All of the input and output parameters of SET.WATCH and READ.WATCH are passed on the Forth data stack.† Because they are re-entrant they can be simultaneously called from multiple tasks in a single QED-Forth application without producing any conflicts.

The words that access the watch use the top 16 bytes of the 68HC11F1ís on-chip RAM (at addresses 0xB3F0-0xB3FF) as a buffer to hold intermediate results during the data transfers.† You may use these locations for other purposes when the watch is not being accessed.

<< Previous | Next>>

Home|Site Map|Products|Manuals|Resources|Order|About Us
Copyright (c) 2006 Mosaic Industries, Inc.
Your source for single board computers, embedded controllers, and operator interfaces for instruments and automation