代码拉取完成,页面将自动刷新
同步操作将从 OvO/SnowLight_STC8 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "reg51.h"
#include "intrins.h"
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xc9;
sfr P5M0 = 0xca;
sfr AUXR = 0x8E;
sfr INTCLKO = 0x8f;
#define EX4 0x40
sbit LED1 = P3^2;
sbit LED2 = P3^3;
sbit LED5 = P3^1;
sbit IN_TOUCH = P3^0;
sfr P5 = 0xC8;
sbit LED3 = P5^4;
sbit LED4 = P5^5;
#define IDL 0x01 //PCON.0
#define PD 0x02 //PCON.1
char flag_mode[5]={0};
char mode=0;
char run_flag=1;
int cnt=0;
int cnt_t=0;
int i=0;
int n=1;
int time_ms;
int pwm_change_time=0;
void LEDn_No(int LED_n);
void LEDn_Off(int LED_n);
void LED_PWM_Set(int LED_n,int PWM_Percentage);
void light_mode_1(void) ;
void TM0_Isr() interrupt 1
{
if(flag_mode[1]==1) //模式1
{
cnt++;
time_ms=1500;//1.5s亮一个
if(cnt>100)
{
cnt=0;
pwm_change_time++;
}
if(n<=5)
{
if(pwm_change_time<(time_ms/10))
i=(int)(pwm_change_time/(time_ms/1000));
switch(n)
{
case 1:LED_PWM_Set(1,i);break;
case 2:LED_PWM_Set(1,100),LED_PWM_Set(2,i);break;
case 3:LED_PWM_Set(1,100),LED_PWM_Set(2,100),LED_PWM_Set(3,i);break;
case 4:LED_PWM_Set(1,100),LED_PWM_Set(2,100),LED_PWM_Set(3,100),LED_PWM_Set(4,i);break;
case 5:LED_PWM_Set(1,100),LED_PWM_Set(2,100),LED_PWM_Set(3,100),LED_PWM_Set(4,100),LED_PWM_Set(5,i);break;
default:break;
}
}
if(n>5)
{ if(pwm_change_time<(time_ms/10))
i=100-(int)(pwm_change_time/(time_ms/1000));
switch(n)
{
case 6:LED_PWM_Set(5,i);break;
case 7:LED_PWM_Set(5,0),LED_PWM_Set(4,i);break;
case 8:LED_PWM_Set(5,0),LED_PWM_Set(4,0),LED_PWM_Set(3,i);break;
case 9:LED_PWM_Set(5,0),LED_PWM_Set(4,0),LED_PWM_Set(3,0),LED_PWM_Set(2,i);break;
case 10:LED_PWM_Set(5,0),LED_PWM_Set(4,0),LED_PWM_Set(3,0),LED_PWM_Set(2,0),LED_PWM_Set(1,i);break;
default:break;
}
}
if(pwm_change_time>(time_ms/10))
{
pwm_change_time=0;
i=0;
n++;
}
if(n>10)
n=1;
}
if(flag_mode[2]==1) //模式2
{
time_ms=3000; //可设定几秒
cnt++;
if(cnt>100)
{
cnt=0;
pwm_change_time++;
}
if(pwm_change_time<(time_ms/10))
i=(int)(pwm_change_time/(time_ms/1000));
if(pwm_change_time>=(time_ms/10))
i=200-(int)(pwm_change_time/(time_ms/1000));
LED_PWM_Set(1,i);
LED_PWM_Set(2,i);
LED_PWM_Set(3,i);
LED_PWM_Set(4,i);
LED_PWM_Set(5,i);
if(pwm_change_time>(time_ms/5))
{
pwm_change_time=0;
i=0;
}
}
if(flag_mode[3]==1) //模式3
{
cnt++;
time_ms=100;
if(cnt>100)
{
cnt=0;
pwm_change_time++;
}
if(pwm_change_time<time_ms/10)
{
LED_PWM_Set(1,10);
LED_PWM_Set(2,10);
LED_PWM_Set(3,10);
LED_PWM_Set(4,10);
LED_PWM_Set(5,10);
}
else
{
LED_PWM_Set(1,0);
LED_PWM_Set(2,0);
LED_PWM_Set(3,0);
LED_PWM_Set(4,0);
LED_PWM_Set(5,0);
}
if(pwm_change_time>time_ms/5)
pwm_change_time=0;
}
}
void Delay_500ms(void) //@11.0592MHz 500ms
{
unsigned char data i, j;
_nop_();
_nop_();
i = 6;
j = 93;
do
{
while (--j);
} while (--i);
}
void Delay2500ms(void) //@11.0592MHz
{
unsigned char data i, j, k;
_nop_();
_nop_();
i = 106;
j = 15;
k = 131;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
//触摸检测中断
void INT4_Isr() interrupt 16
{
//1000微秒@11.0592MHz 启动定时器1
if(run_flag==1)
{
if(IN_TOUCH==0)
{Delay_500ms();
if(IN_TOUCH==0)
mode++;
}
if(mode>6)
mode=1;
}
if(run_flag==0)
{
if(IN_TOUCH==0)
{
Delay2500ms();
if(IN_TOUCH==0)
{
run_flag=1;
LED1=0;
Delay_500ms();
LED1=1;
mode=1;
}
}
}
}
void main()
{
void LEDn_No(int LED_n);
void LEDn_Off(int LED_n);
void LED_PWM_Set(int LED_n,int PWM_Percentage);
P3M0 = 0x00;
P3M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
INTCLKO = EX4; //使能 INT4 中断
//定时器0用于pwm以及模式
TMOD = 0x00; //模式0
AUXR = 0x80; //1T模式
TL0 = 0xAE; //设置定时初始值 10khz T=100us
TH0 = 0xFB;
TR0 = 1; //启动定时器
ET0 = 1; //使能定时器中断
//定时器1用于计时
// AUXR |= 0x40; //定时器时钟1T模式
// TL1 = 0xCD; //设置定时初始值 1ms
// TH1 = 0xD4; //设置定时初始值
// TR1 = 1; //定时器1开始计
// ET1 = 1;
EA = 1;
LED1=1;
LED2=1;
LED3=1;
LED4=1;
LED5=1;
while (1)
{
// if(run_flag==1)
// {
switch(mode)
{
case 0:LED1=1,LED2=1,LED3=1,LED4=1,LED5=1; break;
case 1:flag_mode[0]=0,flag_mode[1]=1,flag_mode[2]=0,flag_mode[3]=0,flag_mode[4]=0;TR0=1;break;
case 2:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=1,flag_mode[3]=0,flag_mode[4]=0;TR0=1;break;
case 3:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=0,flag_mode[3]=1,flag_mode[4]=0;TR0=1;break;
case 4:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=0,flag_mode[3]=0,flag_mode[4]=1,TR0=0;light_mode_1();break;
// case 5:flag_mode[0]=0,flag_mode[1]=0,flag_mode[2]=0,flag_mode[3]=0,flag_mode[4]=1,TR0=0;light_mode_1();break;
default: LED1=1,LED2=1,LED3=1,LED4=1,LED5=1,run_flag=0,cnt=0,n=0,PCON = PD;break;
}
//}
}
}
void LEDn_No(int LED_n) //led亮
{
switch(LED_n)
{
case 1:LED1=0;break;
case 2:LED2=0;break;
case 3:LED3=0;break;
case 4:LED4=0;break;
case 5:LED5=0;break;
default: break;
}
}
void LEDn_Off(int LED_n) //led灭
{
switch(LED_n)
{
case 1:LED1=1;break;
case 2:LED2=1;break;
case 3:LED3=1;break;
case 4:LED4=1;break;
case 5:LED5=1;break;
default: break;
}
}
void LED_PWM_Set(int LED_n,int PWM_Percentage) //led的pwm占空比控制
{
if(cnt<PWM_Percentage) //0-100
LEDn_No(LED_n);
else
LEDn_Off(LED_n);
// if(cnt>100)
// {
// cnt=0;
// }
}
void light_mode_1(void) //常亮
{
LED1=0,LED2=0,LED3=0,LED4=0,LED5=0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。