Demo entry 6624787

system code

   

Submitted by anonymous on Jun 18, 2017 at 04:30
Language: C. Code size: 2.1 kB.

#include<reg51.h>
#include<intrins.h>
sbit L1=P3^0;
sbit L2=P3^1;
sbit L3=P3^2;
sbit L4=P3^3;
sbit kaiguan=P3^4;
sbit CS=P1^0;
sbit CLK=P1^1;
sbit DO=P1^2;
sbit red=P3^5;
sbit green=P3^6;
void delay(int t);
void fenli();
void xuehao();
void wendu();
int jisuan();
int Read_ADC0831() ;
int num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; 
char save[4];
int temp;


void main()
{
	while(1)
	{
	if(kaiguan==1)  //¿ª¹Ø±ÕºÏÏÔʾζÈ
		{temp=Read_ADC0831();
			temp=jisuan();
			if(temp>720)
			{red=1;green=0;} //ºìµÆÁÁ
			else
			{red=0;green=1;} //Â̵ÆÁÁ
			fenli();
			wendu();
		}
	else	xuehao(); //¿ª¹Ø¶Ï¿ªÏÔʾѧºÅ
	}
}

void delay(int t) //ÑÓ³Ùº¯Êý
{
	int i,j;
	for(i=10;i>0;i--)
		for(j=10;j>0;j--)
	   for(t;t>0;t--);
}

void wendu() //½«Î¶ȱ£´æÔÚsaveÖÐ
{
	L1=0;
	P2=num[save[0]];
	delay(10);
	L1=1;
		
	L2=0;
	P2=num[save[1]];
	delay(10);
	L2=1;
		
	L3=0;
	P2=num[save[2]];
	delay(10);
	L3=1;
		
	L4=0;
	P2=num[save[3]];
	delay(10);
	L4=1;
	}
	
void xuehao() //ѧºÅÏÔʾº¯Êý
{
	L1=0;
	P2=num[5];
	delay(10);
	L1=1;
		
	L2=0;
	P2=num[0];
	delay(10);
	L2=1;
		
	L3=0;
	P2=num[7];
	delay(10);
	L3=1;
		
	L4=0;
	P2=num[9];
	delay(10);
	L4=1;
		}
	
int Read_ADC0831()   //¶ÁÈ¡ADC0831 
{
	int i,temp;
	DO=1;
	_nop_();              
	_nop_();
	CS=0;
	_nop_();
	_nop_();
	CLK=0;
	_nop_();
	_nop_();
	CLK=1;
	_nop_();
	_nop_();
	CLK=0;
	_nop_();
	_nop_();
	CLK=1;
	_nop_();
	_nop_();
	CLK=0;
	_nop_();
	_nop_();
	for(i=0;i<8;i++)	  
	{	
	  	
		CLK=1;
		_nop_();
     	_nop_();
		
	       temp<<=1;	  
	if(DO)
		{
		  temp++; 		   
		}
	      CLK=0;
		_nop_();
     	_nop_();
		
   	}
	CS=1;
	_nop_();
       _nop_();
	   ;
	return(temp);		
}

void fenli() //½«Î¶Ȱ´¸öÊ®°Ùǧ±£´æ
{
	save[3]=temp%10;		  
	temp=temp/10;			   
	save[2]=temp%10;		  
	temp=temp/10;			   
	save[1]=temp%10;          
	temp=temp/10;			   
	save[0]=temp%10;		
}

int  jisuan() //²âÁ¿Î¶Ⱦ«¶È¿ØÖÆ
{
	return (4*temp-20);
}
	

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).