本文主要是介绍2020-10-27 51蛋骗鸡占空比和数码管,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
缘由占空比和数码管-CSDN论坛 由已发布的博客中选取需要的代码组合而成。
#include "reg52.h"
sbit duan = P2^6;//数码段
sbit wei = P2^7;//数码位
sbit Fb = P2^0;
sbit k1=P3^1;
sbit k2=P3^2;
bit k=0;
unsigned char Js=0;//中断计时
unsigned char code ShuMaGuan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00,0X80};//0~9隐.小数点
unsigned char code WeiXuanBiao[] = { 0x00,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f };
void ShuMaXianShi(unsigned char s,unsigned char w,unsigned char d)
{unsigned char YanShi=0;P0=WeiXuanBiao[w];wei=1;wei=0;P0=ShuMaGuan[s]|ShuMaGuan[d];//d显示小数点11,10关闭duan=1;while(++YanShi);P0=ShuMaGuan[10];//消隐duan=0;
}
void XianShi(unsigned char c)
{
// ShuMaXianShi(c/100%10,3,10);ShuMaXianShi(c/10%10,4,10);ShuMaXianShi(c%10,5,10);
}
void ZhongDuanSheZhi()
{TH0+=0X4c;/*定时器赋初值,定时50ms触发中断,自动补偿方式*/TL0+=0X00; TMOD=0X01;TR0=1; ET0=1; //开启定时器EA=1; //全局中断开关
}
void FanBo(unsigned char *c/*调节占空比*/)
{Fb=(Js>=*c?0:1);if(!Js)*c+=1;//演示自动调节观察占空比波形
}
void main()
{unsigned char JZhi=147, c=47;//调节按键消抖时间因为中断时间的加入影响消抖时间,调节占空比ZhongDuanSheZhi();while(1){FanBo(&c);XianShi(c);if(!k1&&!++JZhi){c+=4;JZhi=147;while(!k1)XianShi(c);}if(!k2&&!++JZhi){c-=4;JZhi=147;while(!k2)XianShi(c);}
// if(!k1/*由于中断的存在可以用于消抖50毫秒*/){c+=4;while(!k1)XianShi(c);}}
}
void ZhongDuan() interrupt 1
{++Js;TH0+=0X4c;TL0+=0X00;
}
这篇关于2020-10-27 51蛋骗鸡占空比和数码管的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!