⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 da.c

📁 89c2051 D/A数字转模拟 单片机程序
💻 C
字号:
/************************************************/

/************************************************/
#include <REG52.H>
#include <stdio.h>

#ifdef MONITOR51                         /* Debugging with Monitor-51 needs   */
char code reserve [3] _at_ 0x23;         /* space for serial interrupt if     */
#endif                                   /* Stop Exection with Serial Intr.   */
                                         /* is enabled                        */
const char Ledbuf[18]=/*digit convert table*//* 共阴*/
	{ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,		
	/* 0     1     2     3     4     5     6     7     8     9 */
	 0x77, 0x7C, 0x39, 0x500E, 0x79, 0x71, 0x00, 0x40 };
	/* a    b     c     d     e     f           - */

sbit SERIALIN=P0^0;
sbit CLOCK=P0^2;
sbit LATCH=P0^1;
sbit P10=P1^0;
sbit P11=P1^1;
sbit P12=P1^2;
sbit P15=P1^5;
sbit P16=P1^6;
sbit P17=P1^7;
sbit P33=P3^3;
sbit P32=P3^2;
sbit din=P3^0;
sbit clk=P3^1;
unsigned int kl=0,kh=0;
unsigned int Hout;

unsigned int da;


void Delay(unsigned int DelayTime)
	{
	if (DelayTime == 0)return;
	 	while(DelayTime != 0)
			{DelayTime--; }
	}

void display(ledtim)
		char ledtim[4];
{unsigned char i,j,temp;
  	   for (i=0; i<4; i++) {
      temp=ledtim[i];
      for (j=0;j<8;j++){
         temp=temp<<1; SERIALIN=CY; CLOCK=1; CLOCK=0;
		}
	}LATCH=0; LATCH=1;	
}

void computer(unsigned int dt)
{	char cledtim[4];
		int dth,dtm;
		 cledtim[3]=Ledbuf[dt/1000];
	   	 dth=dt%1000;
		 cledtim[2]=Ledbuf[dth/100];
		 cledtim[2]|=0x80;
		 dtm=dth%100;
		 cledtim[1]=Ledbuf[dtm/10];
		 cledtim[0]=Ledbuf[dtm%10];
		 display(cledtim);
}



void main()
	{  	CLOCK=0; 
		LATCH=1;
		P1=0x00;
		P33=0;
		clk=0;
		din=0;
for(;;)
		{		unsigned int i;
		 unsigned int temp;	

		computer(Hout);

if(P10==1){Delay(1000);if(P10==1){Hout++;}}
if(P11==1){Delay(1000);if(P11==1){Hout--;}}
		 P33=1;
		 da=Hout;
		 temp=da;
		 P33=0;
		 for(i=0;i<16;i++)
		 {
		  clk=1;
		  temp=temp&0x8000;
   		  if (temp==0x8000)
			{din=1;}
		    else{din=0;}
			P15=1;
		temp=da;
        temp=temp<<1;
		clk=0;
		da=temp;
		 	}P15=0;	 Delay(500);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -