《单片机实践项目》《电子DIY》基于51单片机+DAC0808的数字调压设计,Proteus仿真

程序:

//B站搜索“逗比小憨憨”
#include 

#define uint unsigned int
#define uchar unsigned char

#define OUTPUT_PORT P2

sbit K1 = P3^0;
sbit K2 = P3^1;
sbit K3 = P3^2;
sbit K4 = P3^3;
sbit K5 = P3^4;
sbit K6 = P3^5;
sbit K7 = P3^6;
sbit K8 = P3^7;

void delay_mS(uint ms);

void delay_mS(uint ms)
{
 	uchar i;
	while(ms--)
	{
	 	for(i=0;i<125;i++);
	}
}

void main(void)
{
 	P2 = 0x00;
	while(1)
	{
	 	if(K1 == 0) OUTPUT_PORT = 0;
		if(K2 == 0) OUTPUT_PORT = 35;
		if(K3 == 0) OUTPUT_PORT = 70;
		if(K4 == 0) OUTPUT_PORT = 105;
		if(K5 == 0) OUTPUT_PORT = 140;
		if(K6 == 0) OUTPUT_PORT = 175;
		if(K7 == 0) OUTPUT_PORT = 210;
		if(K8 == 0) OUTPUT_PORT = 255;
		delay_mS(5);
	}
}

你可能感兴趣的:(电子DIY,DAC0808,Proteus仿真,程序,51单片机实践,数字调压设计)