欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
STC12單片機(jī)按鍵控制PWM程序
[打印本頁]
作者:
2545010433
時(shí)間:
2021-11-10 14:42
標(biāo)題:
STC12單片機(jī)按鍵控制PWM程序
#include <reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit Key1=P3^0;
sbit Key2=P3^1;
sbit PWM=P1^0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar count,time,i;
void delayms(uint k)
{
uint i,j;
for(i=k;i>0;i--)
for(j=110;j>0;j--);
}
void Timer0Init() //100微秒@12.000MHz
{
TMOD |= 0x02; //設(shè)置定時(shí)器模式
TL0 = 0x9C; //設(shè)置定時(shí)初值
TH0 = 0x9C; //設(shè)置定時(shí)重載值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時(shí)器0開始計(jì)時(shí)
EA=1;
ET0=1;
}
void display()
{
static bit num=0;
P0 = 0x00;
if(num)
{
P2=~0xfe;
P0=table[i/10];
num=~num;
}
else
{
P2=~0xfd;
P0=table[i%10];
num=~num;
}
}
void main( )
{
Timer0Init();
count=99;
i=100-count;
while(1)
{
if(!Key1) //
{
delayms(10);
if(!Key1)
{
if(count>1)
count--;
while(!Key1);
i=100-count;
}
}
if(!Key2)
{
delayms(10);
if(!Key2)
{
if(count<99)
count++;
while(!Key2);
i=100-count;
}
}
}
}
void timer0() interrupt 1
{
time++;
if(count>=time)
PWM=1;
else PWM=0;
if(time>99)
time=0;
if(time%10==0)
display();
}
復(fù)制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1