⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alarm.c

📁 用C编程实现的一个单片机报警系统!已经调试可以使用!是单片机大作业的一个!
💻 C
字号:
#include <reg52.h>

#define uint unsigned int 
#define uchar unsigned char 

sbit ring = P1^0;
sbit bClk = P3^0;
sbit bDin = P3^1;

//led显示特殊符号
#define SPAC 10//led code blank
#define NEG  11//         -
#define ON   12//         n
#define OFF  13//         F
#define CUR  14//         C
#define DEW  15//         d
#define TEM  16//         t
uchar code ucFont[17]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09,0xff,0xfd,0x13,0x71,0x63,0x85,0xe1};
                      //  0    1    2    3    4    5    6    7    8    9         -    n    f   C    d    t
uchar idata ucLed[2];

/**************************************************
**
**显示基本函数
**
***************************************************/
void OnLed(void)
{
	uchar i,j,a;

	    bClk=0;
		for(i=0;i<2;i++)
		{
			a=ucFont[ucLed[i]];
			for(j=0;j<8;j++)
			{
				bDin=(a>>j)&0x01;
				bClk=1;
				bClk=0;
			}
		}
}

/**************************************************
**
**显示整数
**
***************************************************/
void DisInt(int n)
{
	uchar i;

	for(i=2;i>0;i--)
	{
		ucLed[i]=n%10;
		n=n/10;
	}
    for(i=1;i<2;i++)
	{
    	if( ucLed[i]==0 ) ucLed[i]=SPAC;
		else i=2;
	}

	OnLed();
}

/*              */
/*  Wait i ms   */
/*              */
void Waitms(uint i)
{
  uint j,k;
  for(j=0;j<i;j++)
     for(k=0;k<128;k++)
	   {;}
}

void main(void)
{
  uchar KeyData1,KeyData2;
  uchar count;
  uint KeyData=0;
  while(1)
  {
    KeyData1=P0;                                //scan the switch S1-S8
	KeyData2=P2;                                //Scan the switch S9-S16
	KeyData=KeyData2;  
	KeyData=(KeyData<<8)|KeyData1;
	if( KeyData!=0xffff )                       //if there is a switch's state is low
	{
	  ring=0;                                   //start alarm
	  for(count=0;count<16;count++)             //scan the switch form S1 to S16
	   {
	     if( !((KeyData<<count)&0x8000) )       //if this switch is low(door is open)
           {
		   DisInt(count);                       //show this door's number 
		   Waitms(2000);                        //show last 2 seconds and scan the next
		   }
	   }
	}
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -