Professional Documents
Culture Documents
2005 */
/* 5 keys, Hour set, minute set, Set Bell time, Clear Bell time, View Bell time */
#include <reg51.h>
/* P0.7 - dt g f e d c b a P0.0 */
/* 0 1 2 3 4 5 6 7 8 9 */
/* ----------------------------------------------------------------------------------------------------------*/
count++;
presscount = 1;
/* the reload count value is 0, so counter will count for 256. with 11.0592 MHz crystal,
clock period is 90.4 ns, multiply by 12 machine cycles, again multiplied by 256 hardware
counter comes to 0.2777 ms, multiplied by 3600 by software counter, comes to exactly 1 sec */
count = 0;
sec1 = 1;
if (itime > 0)
itime--;
x++;
x = 0;
y++;
if (y == 5)
y = 0;
P2 = p2r;
{
digit++;
if (digit == 4)
digit = 0;
/* P2.7 6 5 4 3 2 1 0 */
/* c4 c3 c2 c1 - - - - */
switch (digit)
case 0: /* enable C1 */
P2 = p2r;
if (belltimeshow == 1 )
p0r = seg[ubellmnt];
else
p0r = seg[umnt];
if (pm == 0)
else
P0 = p0r;
break;
case 1: /* enable C2 */
P2 = p2r;
if (belltimeshow == 1 )
p0r = seg[tbellmnt];
else
p0r = seg[tmnt];
P0 = p0r;
break;
case 2: /* enable C3 */
P2 = p2r;
if (belltimeshow == 1 )
p0r = seg[ubellhr];
else
p0r = seg[uhr];
P0 = p0r;
break;
case 3: /* enable C4 */
P2 = p2r;
if (belltimeshow == 1 )
p0r = seg[tbellhr];
else
p0r = seg[thr];
if (p0r == 0xc0) /* mask leading zero */
p0r = 0xff;
P0 = p0r;
break;
/* ----------------------------------------------------------*/
void control_buz_ring(void)
sec1 = 0;
secs++;
if (dot == 0xff)
else
dot = 0xff;
if (buzzeron == 1)
P2 = p2r;
}
if (bellon == 1)
buzzeron = 0;
P2 = p2r;
P2 = p2r;
else
bellon = 0;
P2 = p2r;
/* ----------------------------------------------------------*/
/* every minute update mnt counter and check whether it is ring time */
secs = 0;
mnt++;
umnt = mnt%10;
tmnt = mnt/10;
uhr = hr%10;
thr = hr/10;
ringtime = ringtable[i];
if (currenttime == ringtime - 1)
buzzeron = 1;
if (currenttime == ringtime)
bellon = 1;
bellontime = 5;
if (longbell[i] == 1)
bellontime = 10;
/* ----------------------------------------------------------*/
/* every minute update mnt counter and check whether it is ring time */
mnt = 0;
hr++;
hrm++;
hr = 1;
if (pm == 0)
pm = 1;
else
pm = 0;
hrm = hr;
umnt = mnt%10;
tmnt = mnt/10;
uhr = hr%10;
thr = hr/10;
/* ----------------------------------------------------------*/
/* hour_set called if micro switch is pressed */
secs = 0;
hr++;
hrm++;
if (hr == 13)
hr = 1;
if (pm == 0)
pm = 1;
P3 = 0;
else
pm = 0;
P3 = 0xff;
hrm = hr;
set = 1;
/* ----------------------------------------------------------*/
/* minute_set is called if micro switch is pressed */
void minute_set(void)
secs = 0;
mnt++;
if (mnt == 60)
mnt = 0;
set = 1;
/* ----------------------------------------------------------*/
/* P1.7 6 5 4 3 2 1 0 */
void longbell_set(void)
itime = 5000;
oncount = 0;
if (presscount == 1)
presscount = 0;
oncount++;
}
longbell[(maxentry-1)] = 1;
P2 = p2r;
P2 = p2r;
/* ----------------------------------------------------------*/
itime = 5000;
oncount = 0;
if (presscount == 1)
presscount = 0;
oncount++;
}
maxentry++;
maxentry = 0;
P2 = p2r;
P2 = p2r;
/* ----------------------------------------------------------*/
P2 = p2r;
belltimeshow = 1;
ringtime = ringtable[i] ;
if (ringtime > 0)
bellhr = ringtime/60;
bellmnt = ringtime%60;
ubellhr = bellhr%10;
tbellhr = bellhr/10;
ubellmnt = bellmnt%10;
tbellmnt = bellmnt/10;
P2 = p2r;
P2 = p2r;
belltimeshow = 0;
/* ----------------------------------------------------------*/
/* interrupt initialize */
TR0 = 1;
ET0 = 1;
EA = 1;
count = 0;
sec1 = 0;
digit = 0;
dot = 0xff;
secs = 0;
mnt = 53;
hr = 8;
hrm = hr;
pm = 0;
P3 = 0xff;
uhr = hr%10;
thr = hr/10;
umnt = mnt%10;
tmnt = mnt/10;
P1 = 0xff; /* P1 is input */
p2r = 0x02;
P2 = p2r;
buzzeron = 0;
bellon = 0;
maxentry = 0;
ringtable[i] = 0;
while (1)
if (sec1 == 1)
control_buz_ring();
update_mnt ();
update_hr ();
/* every loop read the control switches to set time and bell time */
hour_set();
minute_set();
if (set == 1)
uhr = hr%10;
thr = hr/10;
umnt = mnt%10;
tmnt = mnt/10;
secs = 0;
itime = 1300;
set = 0;
/* P1.7 6 5 4 3 2 1 0 */
longbell_set();
belltime_set();
belltime_view();
}