#include <reg51.h>
#include <absacc.h>
#define uint unsigned int
#define uchar unsigned char
#define ADDR1 XBYTE[0x8000]
#define ADDR2 XBYTE[0x8400]
#define ADDR3 XBYTE[0x8800]
#define STAA XBYTE[0x8c00]
#define STAB XBYTE[0x8d00]
#define STAC XBYTE[0x8e00]
#define STACMD XBYTE[0x8f00]
#define LEDA XBYTE[0x9000]
#define LEDB XBYTE[0x9100]
#define LEDC XBYTE[0x9200]
#define LEDCMD XBYTE[0x9300]
#define LDJ1 XBYTE[0x9400]
#define LDJ2 XBYTE[0x9800]
#define uchar unsigned char
#define uint unsigned int
/******* globle varibale defination *****/
uchar aa1=0xff;
unsigned char data led,st,trou1,trou2,ard,ld1,ld2;
uchar data kl_times,dl_times,fire_times,times=0,old_numfire=0,numfire=0,numtrou=0,ld_flag=0;
char minute=0,hour=0;
/**** timer interrupt variable zone ***/
uchar lednum1=1,lednum2=1; /* led display order */
bit bdata secflag=1;
uchar temp1,temp2; /* temperary variable */
uchar temp3,temp4;
/******** end of timer interrupt variable zone ****/
uchar data second=0,minutes=0,hours=0; /* init clock value */
unsigned int fire_tag,ld_tag;
unsigned char ld_mode=0;
bit ld_enable=0;
bit power_low;
bit power_high;
bit power_fail;
bit backup_fail;
bit pres_minute=0;
bit pres_second=0;
bit pres_ld=0;
bit pres_s1=0,pres_s2=0;
bit silence1=0;
bit silence2=0;
bit nt1=0,nt2=0,nt3=0,nt4=0;
bit soft_reset=0;
uchar data old_ld1=0x00,old_ld2=0x00;
uchar data cc1,cont,fire1,fire2,old_fire1,old_fire2,old_trou1=0x00,old_trou2=0x00;
uchar code ledtable[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
sbit wdi=P1^7;
sbit p3_3=P3^3;
uchar data nfire[16], ntrou[16];
/********* init do hardware initilization ********/
void init(void)
{
SCON=0x50; /* serial port mode 1,8 bit uart; ren bit set to 1 */
TMOD=0x21; /* counter1 mode 2,8 bit timer; counter0 mode 1,16 bit timer*/
TH0=-(5000/256); /* timer 100ms preload */
TL0=-(5000%256);
TH1=0xe6; /* baud rate is set to 1200 bps */
TR0=1; /* enable counter0 counting */
TR1=1; /* enable counter1 counting */
EA=1; /* enable all interrupt */
ET0=1; /* enable counter0 interrupt */
PT0=1;
/***********************************************************
8255 command format
d7 : =1 work mode tag
d6d5 : A port work mode 00 to 10
d4 : A port I/O mode 1=input; 0=output;
d3 : C high 4 bit I/O mode 1=input; 0=output;
d2 : B port work mode 0 to 1;
d1 : B port I/O mode 1=input; 0=output;
d0 : C low 4 bit I/O mode 1=input; 0=output;
***********************************************************/
}
void clock_display(void)
{
if (pres_second==0)
{
if(lednum1>0x08) lednum1=1;
if ((hour<10)&&(lednum1==0x08)) lednum1=1;
if ((minute<10)&&(lednum1==0x02)) lednum1=4;
switch (lednum1) /* determine which shoud be lighted */
{
case 1: temp1=minute%10; /* low 4bit of hour */
break;
case 2: temp1=minute/10; /* high 4bit of hour */
break;
case 4: temp1=hour%10; /* low 4bit of minute */
break;
case 8: temp1=hour/10; /* high 4bit of minute */
break;
}
temp2=ledtable[temp1];
if(secflag==0)
{
if((lednum1==1)||(lednum1==4))
temp2=temp2^0x80;
}
}
else
{
if ((second<10)&&(lednum1==0x02)) lednum1=1;
if(lednum1>0x02) lednum1=1;
switch (lednum1)
{
case 1: temp1=second%10; /* low 4bit of second */
break;
case 2: temp1=second/10; /* high 4bit of second */
break;
}
temp2=ledtable[temp1]; /* look up the led table for led 7 segment*/
}
LEDA=temp2; /* output to 8255 for displaying */
LEDB=lednum1;
lednum1=lednum1<<1; /* lednumber shift */
}
void stop_display(void)
{
if(lednum2>0x08) lednum2=1;
if ((hour<10)&&(lednum2==0x08)) lednum2=1;
if ((minute<10)&&(lednum2==0x02)) lednum2=4;
switch (lednum2) /* determine which led shoud be lighted */
{
case 1: temp3=minutes%10; /* high 4bit of minutes */
break;
case 2: temp3=minutes/10; /* low 4bit of minutes */
break;
case 4: temp3=hours%10; /* high 4bit of hours */
break;
case 8: temp3=hours/10; /* low 4bit of hours */
break;
}
temp4=ledtable[temp3]; /* look up the led table for led 7 segment*/
LEDA=temp4; /* output to 8255 for displaying*/
LEDB=lednum2;
lednum2=lednum2<<1; /* lednumber shift */
}
void status_check(void)
{
uchar i,j;
uchar b1,b2;
b1=STAB;
b2=STAC;
/* check power status */
if(b1&0x40) power_fail=1;
else power_fail=0;
if(b1&0x80) backup_fail=0;
else backup_fail=1;
if(b2&0x40) power_low=1;
else power_low=0;
if(b2&0x80) power_high=1;
else power_high=0;
/* check keybord status */
if(!(b2&0x01)) pres_ld=1;
else
{
if(pres_ld) ld_enable=1;
pres_ld=0;
}
if (numfire<1)
{
if( !(b2&0x08) && (b2&0x04) && (b2&0x02) )
{
for (i=0;i<150;i++)
{ for (j=0;j<150;j++);}
if(hour<23) hour++;
else hour=0;
}
hours=hour;
if (pres_minute==0)
{
if(!(b2&0x04))
{
for (i=0;i<150;i++)
{ for (j=0;j<150;j++);}
if (minute<59) minute++;
else
{ minute=0; }
}
}
minutes=minute;
if (!(b2&0x02)) /* display second */
{
pres_second=1;
pres_minute=1;
if (!(b2&0x04)) /* set second */
{
for (i=0;i<150;i++)
{ for (j=0;j<150;j++); }
if (second<59) second++;
else second=0;
}
}
else
{
pres_second=0;
pres_minute=0;
}
}
if(!(b2&0x10)) pres_s1=1;
else
{
if(pres_s1) silence1=1;
pres_s1=0;
}
if(!(b2&0x20)) pres_s2=1;
else
{
if(pres_s2) silence2=1;
pres_s2=0;
}
if(p3_3==0)
{ for (i=0;i<200;i++)
{ for (j=0;j<100;j++); }
if(p3_3==1) soft_reset=1;
}
}
/*void service_int1(void) interrupt 2 using 2
{
uchar i,j;
soft_reset=1;
for (i=0;i<200;i++)
{ for (j=0;j<100;j++); }
} */
void counter0_int_timer(void) interrupt 1 using 1
{
TR0=0; /* stop the counter0 */
TH0=-(5000/256);
TL0=-(5000%256);
TR0=1;
times++;
wdi=!wdi; /* watchdog */
if(times%21==0)
{
if (numfire>0)
{
aa1=aa1^0x01;
aa1=aa1|0x02;
}
else
{
if(numtrou>0) aa1=aa1^0x02;
}
}
if(times<105) /* half a second */
{
secflag=0;
aa1=aa1^0x80;
ADDR3=aa1;
}
else secflag=1; /* reset the secflag after 500 ms of setting secflag*/
if(times%210==0) /* increase second counter */
{
times=0;
second++;
if(second>59) /* increase minute counter*/
{
second=second-60;
if(minute<59)
{
minute++;
if(minute%14==0) second=second+1;
}
else
{
hour++;
minute=0;
}
if (hour>23) hour=0;
if(numfire<1)
{
hours=hour;
minutes=minute;
}
}
}
if (numfire<1) clock_display(); /* display clock every 5 ms*/
else stop_display(); /* if first fire then stop time display */
}
void hardware_init(void)
{
uchar i,b1;
ard=STAB&0x3f;
b1=STAA;
b1=~b1;
ld_mode=((b1>>4)&0x0f);
LDJ1=0x00;
LDJ2=0x00;
old_ld1=0x00;
old_ld2=0x00;
ld1=0x00;
ld2=0x00;
cont=b1&0x0f;
led=0xff;
cc1=0x00;
BJQ.rar_消防
版权申诉
66 浏览量
2022-09-23
07:22:16
上传
评论
收藏 4KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/3542a6830a364bf6a0adb34bfd72ce9d_weixin_42662605.jpg!1)
APei
- 粉丝: 65
- 资源: 1万+
最新资源
- python-leetcode python题解之第482题密钥格式化
- python-leetcode python题解之第479题最大回文数乘积
- python-leetcode python题解之第475题供暖器
- python-leetcode python题解之第463题岛屿的周长
- python-leetcode python题解之第461题汉明距离
- python-leetcode python题解之第458题可怜的小猪
- python-leetcode python题解之第457题环形数组是否存在循环
- python-leetcode python题解之第453题最小操作次数使数组元素相等
- python-leetcode python题解之第448题找到所有数组中消失的数字
- python-leetcode python题解之第443题压缩字符串
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)