The Clock Controller V1.1was designed to be an exemplary of using 'C' language to control timer0interrupt, 7-segment LED and keypad scanning. It provides 1-bit sink currentdriving output, for driving a relay, opto-triac, say. Many projects requiring7-segment display and keypad interfacing may get the idea from the Clockcircuit and software.
Hardware
Figure 1 shows a circuitdiagram of the Clock Controller V1.1. P10-P1.7 drives 7-segment commonanode LED with sink current. P3.0-P3.3 also drives a base pin of 4-PNPtransistor, 2n2907 with sink current. As shown in the figure, the 2nd 2-digitLED that connected to P3.2 and P3.3 is rotated 180 degrees to the 1st 2-digitallowing the pt. segment to be used for 1 second blinking. P3.0-P3.3 alsoconnects four momentary switches while the other legs are tied to inputport P3.4. During display and key switch scanning, a logic '0' is shiftedfrom P3.0 to P3.3, if there was a key pressed, P3.4 then became low.P3.7 is a 1-bit sink current driving, an example in the circuit uses a2n2907 to drive a small electromechanical relay 5V, say.
Figure 1: Schematic Diagramof the Clock V1.1
Software
The program clock.cwas written in ‘C’ language and was complied by Micro-C Compiler from DunfiledDevelopment Systems. The memory model is TINY. The hex file of clock.csuitable for downloading by Easy-Downloaderis clock.hex.
The Clock1.cwas modified for C51 compiler. The function that updates real-time clockwas moved into timer0 interrupt service routine. The HEX file is Clock1.hexsmaller than compiled by Micro-C.
I got many requests askingmodification of the source code. Now you can modify the source code byyourself with the free compiler sdcc for 8051. Here is the source codeof new firmware, clock2.c and the hex file, clock2.hex.Please test it and let me know the result. I haven't tested my hardwareyet, because I cannot find it now. This project is quite long time ago.You may add your code or modify whatever you like to have using sdcc! Youmay download the sdcc here, sdcc.zip.
Practice
The function time( ) in clock.cwas not put in the timer0 service routine, there's a bit delay at scanLED() function making the clock delay, try write a function that make adjustmentof the clock.
With C51 compiler, there's aspace for more functions to put in, write a function that saves a secondtime on and off.
Heavy Load Driving
I suggest to use a zero switchsolid-state relay for driving heavy loads (>10A). Most solid state relay'sinput can be driven with 3-30Vdc without any problems.
Contribution to Clock ControllerProject
Sridhar Vittalrao designedthe PCB layout (Protel), Clock.zip.
One day I found a small 7-segment LED with multiplex connection. It is nice to be used as the display for clock controller. So I spent my weekend built the board. Below are the pictures for outlook and internal. The board is quite small. The output has small relay for 0.5A AC load.
This version has only three buttons. We can set current hour and min easily. The preset time on/off for relay control output are defined in the program.
// preset set time on/off are predefined in rom, user may change it here
#define onHour1 19
#define onMin1 00
#define offHour1 21
#define offMin1 30
Also if you need more period to turn on/off you can add, say onHour2, onMin2, offHour2, and offMin2. And provide the function that compares such period. It will be the same as function comparetime. Or you may insert at if statements. When reset, the board will turn output off, until user set current time, the clock will run again. This prevent improper output firing.
void comparetime()
{
if(flag1 & 0x40) // compare time only when user enter new time
{
if(flag1 & 0x01)
{
flag1 &= ~0x01;
if(hour == onHour1 && min == onMin1)
opto = 0x7f; /* clear P3.7 turning opto on */
if(hour == offHour1 && min == offMin1)
opto = 0xff; /* set bit P3.7 turning opto off */
}
}
}
Updated Schematic
http://electronics-diy.com/schematics/1148/clock2.pdf
| #include <reg52.h> /* special function register declarations */ |
| unsigned char sec100,sec,sec5,min,hour,flag1,command,temp,opto; |
| unsigned char i,digit, buffer[4]; |
| char cputick,key,delay,count1; |
| unsigned char convert[10] = {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; |
| void timer0int ( void ) interrupt 1 using 1 { |
| buffer[0] = convert[min%10]; |
| buffer[1] = convert[min/10]; |
| buffer[2] = convert[hour%10]; |
| buffer[3] = convert[hour/10]; |
| if ( ++hour== 24) hour = 0; |
| if ( ++min == 60 ) min = 0; |
| if (delay == 0) flag1 &= ~0x80; |
| if (hour == onHour1 && min == onMin1) |
| if (hour == offHour1 && min == offMin1) |
| for (i = 0; i < j; i++) continue ; |