Reply by Bob Smith December 13, 20042004-12-13
Here is a response to an almost identical question (posted from an almost
identical from address???) that was recently posted on the Freescale
mc68hc11 email group. Clock projects must be popular that semester --- In , "aznxstryder1" <aznxstryder1@y...>
wrote:
>
> Can anyone explain to me how to write this kind of program. I got
> the display on the lcd down, just need to write to program in. Any
> algorithm or suggestions on how I would go about on writing this
> program. Any suggestions would be very helpful. thanks

Below I've provided some C-like pseudocode that shows how to keep
time once you've created a 1-second timing routine.

The first thing you have to do is figure out a way to generate a
periodic signal that is activated once per second. You could use
the RTI (Real-Time-Interrupt) source, although this typically
generates intervals that are not even multiples of 1 second. A
better solution would be to use one of the Output Compare channels
(configured such that it does not utilize the output pin associated
with it) to generate a timing signal that is an even fraction of 1
second. This is not overly difficult to do, but it does require
some understanding of the HC11 timer/output compare subsystem.
Review these sections in the HC11 Reference Manual, and if you still
can't figure out how to go about setting up the output compare to
generate periodic interrupts/timing signals, I'll do what I can to
help you.

Once you have a 1 second timing source, call a routine based on the
pseudocode below to update your clock. I have designed this routine
to use individual RAM locations/variables for each digit to make
conversion for display easy. This is less efficient than, say,
maintaining the 'two digit' seconds counter in one byte location,
but is much easier to convert for display.

Here's the pseudocode for the timekeeping routine:

Increment [unit seconds]
if [unit seconds] > 9 then
[unit seconds] = 0
Increment [tens seconds]
If [tens seconds] > 5 then
[tens seconds] = 0
Increment [unit minutes]
If [unit minutes] > 9 then
[unit minutes] = 0
Increment [tens minutes]
If [tens minutes] > 5 then
[tens minutes] = 0
Increment [unit hours]
If [unit hours] > 9 then
[unit hours] = 0
Increment [tens hours]
endif
If ([tens hours] = 2) and ([unit hours] = 4) then
[unit hours] = 0
[tens hours] = 0
Call date update routine (if needed)
endif
endif
endif
endif
endif --- Avoid computer viruses, Practice safe hex ---

-- Specializing in small, cost effective
embedded control systems --

http://www.smithmachineworks.com/embedprod.html Robert L. (Bob) Smith
Smith Machine Works, Inc.
9900 Lumlay Road
Richmond, VA 23236 804/745-2608
----- Original Message -----
From: "asianxstryder1" <>
To: <>
Sent: Sunday, December 12, 2004 7:23 PM
Subject: [m68HC11] Not sure about how to write this program on a clock >
> Can anyone suggest somne kind of algorithm or a flowchart( which I
> dont know how to make) on a program that keeps track of a 24 hour
> time period that is displayed onto the LCD screen of the EVB board.
> I dont really know the algorithm to use to be able to write this
> program nor how to make a flowchart. Any kind of help would be great. >
>
> --
------
> Yahoo! Groups Links
>
> a.. To


Reply by David Kelly December 13, 20042004-12-13

On Dec 12, 2004, at 8:08 PM, wrote:

> In a message dated 12/12/04 7:24:57 P.M. Eastern Standard Time,
> writes:
>
>> Any kind of help would be great.
> > ==============================
> Change majors. Soon.

Yeah, it sure did sound like Yet Another Homework Assignment.

Maybe we need a list FAQ, or if one exists add an entry covering
homework assignments? The HC11 is widely used in classrooms. This same
thing comes up all the time.

Thought of suggesting one purchase an LCD clock at Walmart. Would be
cheaper than the HC11 alone. Would learn just as much that way as one
would if others did the assignment.

Dear ,

If you are having that much problem with the assignment then contact
the instructor/professor outside of the classroom. Your tuition pays
for one-on-one time with the instructor outside of class. Make use of
it. If you make a total fool of yourself then maybe the instructor will
approve of a "drop" whereby some or most of your tuition is refunded
and you do not get an "F".

One-on-one with the instructor may be exactly what you need to find the
switch in your brain which was not toggled during the instructor's bulk
downloads to the class. It may be the only way the instructor can
discover what the lecture lacked. Only way you'll find out is to try.

Coding a clock only requires technical skills. Problem solving and
learning how to code a clock is the essence of being an engineer.

You did ask for "any kind of help", and the above is the best I have to
offer.

--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.


Reply by Jim Peterson December 13, 20042004-12-13
1. find out how to make flowcharts....
{
Find a web browser, enter www.google.com in the address field. enter
flowchart in the search field. click some of the displayed links and read.
}
2. make a 24 hour clock algorithm.....
{
a. read prior posts to this board regarding the same topic
or
b. google search as above for "nested loops".
}

3. If that doesn't help, take Bob Gardner's advice very seriously.

Jim asianxstryder1 wrote:

>Can anyone suggest somne kind of algorithm or a flowchart( which I
>dont know how to make) on a program that keeps track of a 24 hour
>time period that is displayed onto the LCD screen of the EVB board.
>I dont really know the algorithm to use to be able to write this
>program nor how to make a flowchart. Any kind of help would be great. >
>
>Yahoo! Groups Links >
>




Reply by December 12, 20042004-12-12

In a message dated 12/12/04 7:24:57 P.M. Eastern Standard Time,
writes:

Any kind of help would be great.
==============================
Change majors. Soon.



Reply by asianxstryder1 December 12, 20042004-12-12

Can anyone suggest somne kind of algorithm or a flowchart( which I
dont know how to make) on a program that keeps track of a 24 hour
time period that is displayed onto the LCD screen of the EVB board.
I dont really know the algorithm to use to be able to write this
program nor how to make a flowchart. Any kind of help would be great.




Reply by Bill Walker December 6, 20042004-12-06
Here is a clock program that one of my students wrote for Digital
Electronics Class.

He was rather tricky, though. He used a 3 digit module for the display, so
he had to use the decimal point on the first LED as the tens of hours digit.
Also, the clock's timing does not use an interrupt. His plans was to add a
circuit to provide a time base from the 60 hertz power line, but he never
got that far. But all the logic to provide a twelve hour clock is there.

Prof. W. S. Walker
West Virginia State University
==================================================
* This program drives a 3 digit LED as a clock. The dp on the 1st LED
* will indicate a "1"; hence, 12:34 = '234. The a - g segments plus
* the dp are connected to PB0 thru PB7. PA4, 5, and 6 are used to
* multiplex the LEDs; they are connected to the common anode for
* LED1 , 2 and 3, resp. Uses the Fox 11 board.

* Equates

PORTB11 EQU $1404 * FOX 11 board's Port B address
PORTA EQU $1000 * Port A
LED1ON EQU $10 * +5v pin LED 1 (left)
LED2ON EQU $20 * +5v pin LED 2 (middle)
LED3ON EQU $40 * +5v pin LED 3 (right)

* Data

ORG $00
TABLE FCB $C0 * bit pattern for a 0
FCB $F9 * 1
FCB $A4 * 2
FCB $B0 * 3
FCB $99 * 4
FCB $92 * 5
FCB $82 * 6
FCB $F8 * 7
FCB $80 * 8
FCB $90 * 9

TIME FDB $0958 * Time as 4 decimal digits
COUNT FDB 0000 * Counter

* Main

ORG $C000 * FOX 11 RAM
START LDD COUNT * Decrement counter
SUBD #1
STD COUNT
BEQ UPDATE * When count is depleted, update time
JMP TOK * else go display the time as is
UPDATE LDAA TIME+1 * get minutes
ADDA #1 * bump it up one
DAA * must be decimal
STAA TIME+1
CMPA #$60 * top of the minute?
BNE TOK * nope, go display time
CLRA * yep, put a 0 in minutes
STAA TIME+1 * bump up hours
LDAA TIME
ADDA #1
DAA * decimally
STAA TIME
CMPA #$13 * can't allow 13th hour
BNE TOK * if ok, go display time
LDAA #1 * if not, set hours to 1
STAA TIME
BRA START * do some more counting
TOK LDD TIME * land here to display time
JSR DISPD * go to subroutine to do it
BRA START * do some more counting

* Subroutine to display the time to the LEDs
* the decimal point on LED 1 is used for the 1 in hours after 9

DISPD PSHA * Save D
PSHB
ANDB #$0F * mask to units min digit
CLRA * make it a word
XGDX * put it in X
LDAA 0,X * load the LED pattern for this digit
LDAB #LED3ON * turn on 3rd LED
STAB PORTA
STAA PORTB11 * light up the LED
BSR DELAY * delay a short time
PULB * minutes back
LSRB * shift right for tens min digit
LSRB
LSRB
LSRB
ANDB #$0F * get its bit pattern
CLRA
XGDX
LDAA 0,X
LDAB #LED2ON * turn on 2nd LED
STAB PORTA
STAA PORTB11 * light it up
BSR DELAY * delay
PULB * get hours byte
PSHB * save it back again
ANDB #$0F * units hours digit
CLRA * make it a word
XGDX * put in X
LDAA 0,X * get the bit pattern
LDAB #LED1ON * turn on 1st LED
STAB PORTA
STAA PORTB11 * light it up
BSR DELAY * delay
PULA * hours back
ANDA #%00010000 * mask out the tens hours (0 or 1)
LSLA * shift it to bit 7
LSLA
LSLA
EORA #%10000000 * flip the bit (gnd it to light dp)
ORAA #%01111111 * turn off all other bits
STAA PORTB11 * light up dp if tens of hours a 1

* Subroutine to delay a short time

DELAY LDX #60 * change this value to adjust timing
TLUP DEX
BNE TLUP
NOP * add/remove nops to fine tune
NOP
NOP
NOP
RTS ----- Original Message -----
From: "David Kelly" <>
To: <>
Sent: Sunday, December 12, 2004 11:07 PM
Subject: Re: [m68HC11] Not sure about how to write this program on a clock >
> On Dec 12, 2004, at 8:08 PM, wrote:
>
> > In a message dated 12/12/04 7:24:57 P.M. Eastern Standard Time,
> > writes:
> >
> >> Any kind of help would be great.
> >>
> >
> >
> > ==============================
> > Change majors. Soon.
>
> Yeah, it sure did sound like Yet Another Homework Assignment.
>
> Maybe we need a list FAQ, or if one exists add an entry covering
> homework assignments? The HC11 is widely used in classrooms. This same
> thing comes up all the time.
>
> Thought of suggesting one purchase an LCD clock at Walmart. Would be
> cheaper than the HC11 alone. Would learn just as much that way as one
> would if others did the assignment.
>
> Dear ,
>
> If you are having that much problem with the assignment then contact
> the instructor/professor outside of the classroom. Your tuition pays
> for one-on-one time with the instructor outside of class. Make use of
> it. If you make a total fool of yourself then maybe the instructor will
> approve of a "drop" whereby some or most of your tuition is refunded
> and you do not get an "F".
>
> One-on-one with the instructor may be exactly what you need to find the
> switch in your brain which was not toggled during the instructor's bulk
> downloads to the class. It may be the only way the instructor can
> discover what the lecture lacked. Only way you'll find out is to try.
>
> Coding a clock only requires technical skills. Problem solving and
> learning how to code a clock is the essence of being an engineer.
>
> You did ask for "any kind of help", and the above is the best I have to
> offer.
>
> --
> David Kelly N4HHE,
> ========================================================================
> Whom computers would destroy, they must first drive mad. >
> Yahoo! Groups Links > **************************************************************
> Scanned by VisNetic MailScan for SMTP Servers.
> Visit http://www.deerfield.com/products/visnetic_mailscan.
> ************************************************************** >