这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 51study实例-C51闹铃程序

共7条 1/1 1 跳转至

51study实例-C51闹铃程序

工程师
2021-05-19 00:01:39     打赏

#包括

#包括

#定义comdir P3_2

#定义扬声器P1_3

#定义wiret0 T0

#定义wiret1 T1

#define adr_delay1s 0x1086

#define adr_print10ms 0x1000

#定义adr_print80ms 0x101A

#define adr_screen_black 0x10BA

#define adr_screen_clear 0x10CD

#define adr_key_search 0X10EB

#define adr_sound500hz 0x109E

#定义max_timer的24 * 3

void (* pFunc)(void); //定义指向函数的指针

void(* Print80ms)(无效);

int CodeChange(int i);

/ *定义一个结构* /

struct time_str {

未签名的字符小时;

未签名的字符最小值;

unsigned char sec;

}今天;

int depart = 20;

int t0int_flag = 0;

unsigned char data dispbuf [8] _at_ 0x30;

unsigned char code Sound_Date[max_timer]={

0x00 0 0 0 0 0 0 0 0 0 0 0

0x0b 0 0 0 0 0 0 0 0 0 0 0

0x0b 0 0 0 0 0 0 0 0 0 0 0

0x0b 0 0 0 0 0 0 0 0 0 0 0

0x0b 0 0 0 0 0 0 0 0 0 0 0

0x0b 0 0 0 0 0 0 0 0 0 0 0

};

/*TIMER0 INTERRUPT*/

void timer0(void)interrupt 1 {

wiret1 =!wiret1;

TH0 = 0X3C;

TL0 = 0XB0;

出发-= 1;

如果(离开%10 == 0){

t0int_flag =!t0int_flag;

}

如果(出发== 0){

出发= 20;

today.sec + = 1;

wiret0 =!wiret0;

如果(today.sec == 60){

today.sec = 0;

今天。分钟+ = 1;

if(today.min == 60){

today.min = 0;

今天。小时+ = 1;

if(today.hour == 24){

今天。小时= 0;

          }

        }

      }

   }

}

/ *串行端口中断* /

无效序列(无效)中断4 {

}

主要的()

{

字符* P;

int j = 0;

int i = 0;

int k = 0;

P3_4 = 0;  // T0 = 0

P3_4 = 1;  // T0 = 1

P3_5 = 0;  // T1 = 0

P3_5 = 1;  // T1 = 1

pFunc = adr_screen_black;  //黑屏

(* pFunc)();

pFunc = adr_screen_clear;  // clrar屏幕ram

(* pFunc)();

/ * P = 0X30;

(* P)= 0X79;

P ++;

(* P)= 0X71; * /

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//SP=0XD0;

TMOD=0X21;

//TH1=0XF3;

//TL1=0XF3;

//PCON=0;

//SCON=0X40;

//TR1=1;

ET1=0;

//REN=1;

TH0=0X3C; /* 50ms interrupt */

TL0=0XB0;

TR0=1;

ET0=1;

EA=1;

//TI=0;

//SBUF=0XAA; //MON51 占用串口

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pFunc=adr_sound500hz;

(*pFunc)(); /*发声音一秒*/

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

today.hour=0;

today.min=0;

today.sec=0;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

for(;;)

{

pFunc=adr_print10ms;

(*pFunc)(); /*screen out*/

j=CodeChange(today.hour/10);

k=CodeChange(today.hour%10);

k = k | 0x80;

P = 0x30;

(* P)= j;

P ++;

(* P)= k;

P ++;

j = CodeChange(today.min / 10);

k = CodeChange(today.min%10);

(t0int_flag == 1)?(k = k | 0x80):( k = k&0x7f);

(* P)= j;

P ++;

(* P)= k;

P ++;

j = CodeChange(today.sec / 10);

k = CodeChange(today.sec%10);

(* P)= j;

P ++;

(* P)= k;

对于(i = 0; i if((today.hour == Sound_Date [i * 3 + 1])&&(today.min == Sound_Date [i * 3 + 1])&&(today.sec == Sound_Date [i * 3 + 2])){

pFunc = adr_sound500hz;

        (* pFunc)(); /*发声音一秒*/

}

}

    pFunc=adr_key_search;

    (* pFunc)();

    i=ACC;

    if (CY==1) {

      //while (CY==1){ /***等待放手***/

pFunc = adr_print80ms;

(* pFunc)();

(* pFunc)();

(* pFunc)();

// pFunc = adr_key_search;

//(* pFunc)();

      //}

切换(i){

情况7:

今天。小时+ = 1;

if(today.hour> 23){today.hour = 0;}

休息;

情况6:

今天。小时-= 1;

if(today.hour == 255){today.hour = 23;}

休息;

情况5:

今天。分钟+ = 1;

if(today.min> 59){today.min = 0;}

休息;

情况4:

今日。分钟-= 1;

if(today.min == 255){today.min = 59;}

      break;

情况3:

today.sec + = 1;

if(today.sec> 59){today.sec = 0;}

休息;

情况2:

today.sec- = 1;

if(today.sec == 255){today.sec = 59;}

休息;

      }

}

  }

}

//时钟表:6:00:00 6:30:00 7:00 7:45:00 0:2:08 0:3:09

int CodeChange(int i){

// 3fh 6 5 4 66 6 7 7 7 67 {

案例0:

i = 0X3F;

休息;

情况1:

i = 0X6;

休息;

情况2:

i = 0X5b;

  break;

  case 3:

  i=0X4F;

  break;

  case 4:

  i=0X66;

  break;

情况5:

i = 0X6d;

休息;

情况6:

i = 0X7d;

休息;

情况7:

i = 0X7;

休息;

情况8:

i = 0X7f;

休息;

案例9:

i = 0X67;

休息;

  };

返回我

}





专家
2021-05-19 00:02:48     打赏
2楼

感谢楼主的分享,很实用了。


工程师
2021-05-19 00:11:19     打赏
3楼

感谢楼主的分享,很实用了。


专家
2021-05-19 06:41:55     打赏
4楼

感谢分享


专家
2021-05-19 07:19:41     打赏
5楼

感谢


专家
2021-05-19 08:39:40     打赏
6楼

学习


工程师
2021-05-20 23:57:02     打赏
7楼

代码写的非常不错的


共7条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]