新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 基于单片机的彩灯设计

基于单片机的彩灯设计

作者:时间:2011-10-12来源:网络收藏

3.软件

图3 控制LED调光电路流程图

  4.程序

  #includereg52.h>

  sbit LED1=P1^0;

  sbit LED=P1^1;

  sbit LED2=P1^2;

  unsigned char CYCLE;

  unsigned char PWM_ON;

  void delay (unsigned int cnt)

  {

  while(--cnt);

  }

  main()

  { bit flag;

  TMOD=0x01;

  TH0=(65536-100)/256;

  TL0=(65536-100)%256;

  IE=0x82;

  TR0=1;

  CYCLE=50;

  while(!flag)

  { delay(20000);

  PWM_ON++;

  if(PWM_ON==CYCLE)

  { flag=1;

  }

  }

  while(flag)

  { delay(20000);

  PWM_ON--;

  if(PWM_ON==0)

  { flag=0;

  }

  }

  }

  void time(void) interrupt 1

  { STatic unsigned char count;

  TH0=(65536-100)/256;

  TL0=(65536-100)%256;

  if(count==PWM_ON)

  { LED1=1;

  LED=1;

  LED2=1;

  }

  count++;

  if(count==CYCLE)

  { count=0;

  if(PWM_ON!=0)

  LED1=0;

  LED=0;

  LED2=0;

  }}

  *


上一页 1 2 下一页

评论


相关推荐

技术专区

关闭