历时一周,做的四路低频方波脉冲输出,可调脉宽。
附件包括c程序以及Proteus仿真
原创,多多指教,谢谢
下面是proteus仿真原理图:
51单片机源程序:
- #include <REG52.H>
- #define uchar unsigned char
- #define uint unsigned int
- sbit LEVEL00=P1^0;//LEVEL,P1.2引脚上的电平值
- sbit LEVEL01=P1^1;//LEVEL,P1.2引脚上的电平值
- sbit LEVEL02=P1^2;//LEVEL,P1.2引脚上的电平值
- sbit LEVEL03=P1^3;//LEVEL,P1.2引脚上的电平值
- sbit P14=P1^4;//LEVEL,P1.2引脚上的电平值
- sbit P15=P1^5;//LEVEL,P1.2引脚上的电平值
- uchar highcount00,highcount01,highcount02,highcount03; //记录高电平定时次数
- const uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,}; /*显示0~9*/
- uint x,y,z,m;
- uint n0,n1;
- uint count;
- void delay()
- {
- uint i,j;
- for(i=0;i<256;i++);
- for(j=0;j<256;j++);
- }
- void stop(void) interrupt 0 using 1
- {
- TR0=!TR0;
- if(TR0==1)
- {x=x+10;y=y+10;z=z+10;m=m+10;count=count+5;
- if(count==95){x=0;y=0;z=0;m=0;count=0;}}
- }
- void sto(void) interrupt 2 using 3
- {
- if(TR0==1)
- {x=x-10;y=y-10;z=z-10;m=m-10;count=count-5;
- if(count<=0){x=0;y=0;z=0;m=0;count=0;}}
- }
- void timer0isr(void) interrupt 1 using 2
- {
- TH0 = 0xD8;
- TL0 = 0xF0; //重置计数初值
- highcount00++; //溢出次数加1
- if(highcount00== x)
- LEVEL00 = 0;
- if(highcount00== 200)
- {
- LEVEL00 = 1;
- highcount00 = 0;
- }
- highcount01++; //溢出次数加1
- if(highcount01== y)
- LEVEL01 = 0;
- if(highcount01== 200)
- {
- LEVEL01 = 1;
- highcount01 = 0;
- }
- highcount02++; //溢出次数加1
- if(highcount02== z)
- LEVEL02 = 0;
- if(highcount02== 200)
- {
- LEVEL02 = 1;
- highcount02 = 0;
- }
- highcount03++; //溢出次数加1
- if(highcount03== m)
- LEVEL03 = 0;
- if(highcount03== 200)
- {
- LEVEL03 = 1;
- highcount03 = 0;
- }
- }
- void main(void)
- {
- x=10;y=20;z=30;m=40;
- count=5;
- IT0=1;
- IT1=1;
- EX1=1;
- EX0=1;
- highcount00 = 0; //记录高电平定时次数
- highcount01 = 0;
- highcount02 = 0;
- highcount03 = 0;
- TMOD = 0x01; //设定T/C0工作在定时器方式1
- LEVEL00 = 1; //初始电平为高
- LEVEL01 = 1; //初始电平为高
- LEVEL02 = 1; //初始电平为高
- LEVEL03 = 1; //初始电平为高
- TH0 = 0xD8;
- TL0 = 0xF0; //装载计数初值
- EA = 1; //开总中断
- ET0 = 1; //开T/C0中断
- TR0 = 1; //启动T/C0
- while(1)
- {n0=count/10;
- n1=count%10;
- P2=tab[n0];
- P14=1;
- delay();
- P14=0;
- P2=tab[n1];
- P15=1;
- delay();
- P15=0;
- }
-
- }
复制代码
所有资料打包下载:
四路低频方波脉冲可调脉宽.rar
(64.76 KB, 下载次数: 28)
|