blewisjr:
The Clock
I think you said that you were doing an AVR based clock an switched to PIC so you had more pins.
So have you asked your self if C works on an AVR and C works on a PIC why are you rewriting the C code?
Even if you have stopped all work on the AVR based clock, Thinking of this could help you write better C code for the current clock.
Your basic clock code needs to run once a second, so in C it could be the same. You just need to get the inputs from the AVR & PIC to look the same to the basic code. Then do same with the outputs.
Now if you think about it, the more code you can put in the basic clock section, the less programing you have to do to have two clocks one on PIC and one on AVR.
So on the input side you have the differences in reading the switches and how to get to the once a second running of basic clock. On the output side the display and other outputs.
So as you write the basic clock, keep asking your self, is there a better way to do this part so it works on more clock hardware, Is there a better way to do this part so you do not need to make changes to the special C code for each clock.
Display:
I think you are using a multiplexed display on both clocks. What changes could you make to put more code in the basic clock section so that it is not needed to be done in the two different display sections. What changes could you make so that in the display part you have more C code in common between the clocks?
Looking at your code I see that you have made a choice that instead of having separate digit to 7 segment decoder chip(a) to have the mpu do it.
Lets look at the costs.
4 pins for a digit output vs 7 or 8 pins for a segment output.
digit to segment decoder chip vs Software
Note: by using a segment output can now display any segment output you want so you have more options.
I see a lot on the good side for a cost of 3-4 pins.
So Looking at your display code why are you using digit data an not segment data?
Digit data does not change fast so it would be less work for the mpu to display segment data then create segment data from digit data on each scan. Think you said alarm, so if you want to switch to display alarm time or something else you have to change display code section again for each new display data. If display section just displayed an array of segment data, you could change segment data almost any where and display section would display it with no changes. If you wanted to change from a 4 digit clock to a 6 digit clock, you would just need to change the array size and how much of the array is displayed counter. So in basic clock section create segment data for the display section to use for display and The display section of code gets simpler.
If you look at croberts hardware, there are 5 digits not 4. The colon for the display is treated as if it were a digit. You could also add a fake digit where you just treated 7-8 leds like they were a digit, This would just cost one pin instead of 7-8 pins. With display code displaying segment data, you would only need to change how many digits the display code was to display. You could build the segment data for the colon or the fake digit leds anywhere.
mux Switch Input:
If you look at my other post, I was not trying to get fancy, just using a normal input pin like you are using for one switch. In simple terms, some would call this a wired or gate. When a switch is pressed it connects that digit output pin to your input pin. When not pressed the pull-up or pull-down resistor sets the level the input pin sees. So the input pin is going up and down and to find out which switch caused the change you need to know which digit output pin is currently active. The function of your cap will need to be done in software.
You currently have an input with a resistor pull up. First step is to look at your digit outputs. One of your digit outputs will be at a different state. If that state is high then the input pin of your mpu needs a pull down resistor connected. If that state us low then the pull up resistor you have will work. You will need to remove the cap as it's function will need to be done in software. You just connect a switch & diode in series between your current input pin and one of the digit output pins. Each switch to a different digit output pin. To keep things simple just put a diode in series with each switch, With out diode you could have problems when two switches were pressed at the same time or push-pull digit outputs.
Now it takes time for the signal to go out a digit output pin and through the wires, switch, ____ so the best place to read the input pin is just before you change to the next digit on output. Unless you are short of ram, it easer in software to just pretend that you have a switch connected to each digit output pin even if you do not.
for software debounce look for idea in previous post
NOTE: A lot of mpu's can do a test for number = 0 with a lot less code then a test for number = ____ the same is true if the mpu is testing for less that or greater than.
Long post and A lot of things so in summary:
Display code just displays an array of segment data.
Just before switching to a new digit it reads input pin for switches and stores the result in an array of switch data.
read the input pin something like this.
If input pin is 0 then
if abs (switch_array_data.)< bounce_count then
switch array data. = switch array data -1
If input pin is 1 then
if abs (switch_array_data.)< bounce_count then
switch array data. = switch array data +1
Note: the above gives you a byte size integer use in your main code. It will be a negative number for one switch state and positive number for other switch state.
The above gives you two arrays for main clock code to use.
Segment array containing what to display.
Input switch array for current status of switches.
If you think I goofed or have questions, Ask
C