累计主循环次数使LED灯闪烁

#include "REG52.H"
#define const_time_level 10000
void initial_myself();
void initial_peripheral();
void delay_long(unsigned int uiDelaylong);
void led_flicker();
sbit led_dr=P3^5;
unsigned char ucLedStep=0;
unsigned int uiTimeCnt=0;
void main()
{
 initial_myself();
 delay_long(100);
 initial_peripheral();
 while(1)
 {
  led_flicker();
 }
}
void led_flicker()
{
 switch(ucLedStep)
 {
  case 0:
   uiTimeCnt++;
   if(uiTimeCnt>=const_time_level)
   {
    uiTimeCnt=0;
    led_dr=1;
    ucLedStep=1;
   }
   break;
  case 1:
   uiTimeCnt++;
   if(uiTimeCnt>=const_time_level)
   {
    uiTimeCnt=0;
    led_dr=0;
    ucLedStep=0;
   } 
   break;
 }
}
void delay_long(unsigned int uiDelaylong)
{
 unsigned int i;
 unsigned int j;
 for(i=0;i<uiDelaylong;i++)
 {
  for(j=0;j<500;j++)
   ;
 }
}
void initial_myself()
{
 led_dr=0;
}
void initial_peripheral()
{
 ;
}
 /*---------------------------------------------转自吴坚鸿程序框架*/
posted @ 2019-11-24 17:20  烟火流沙  阅读(235)  评论(0编辑  收藏  举报