Learning microcontroller series based on Proteus (7) - AD conversion and its application--ADC0832

Project download

    click to download

    1. Circuit diagram


     2. Procedure

        Only the main function is posted here, and the rest, please click on the above (click to download) to download, it is too troublesome.

main function

 
#include<reg51.h>
#include<intrins.h>
#include<adc0832.c>
code uchar seven_seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x82,0xf8,0x80,0x90};
uchar cp1, cp2, dat_ad;
void timer0_init() //Interrupt initialization function
{
	TMOD = 0x01;					
	TL0 = 0x78;
	TH0 = 0xec;
	EA = 1;
	TR0 = 1;
	ET0 = 1;
}
void timer0_isr()interrupt 1 //Interrupt service function
{
	TL0 = 0x78;
	TH0 = 0xec;
	cp1++;
	if(cp1>100)						//0.5s
	{
		cp1 = 0;
		dat_ad=adc0832_ch0(); //adc0832 is converted once
	}
	P0 = 0xff; //blanking
	switch(cp2)
	{
		case 0:P0 = seven_seg[dat_ad%10];P2 = 0x01;break;
	    case 1:P0 = seven_seg[dat_ad%100/10];P2 = 0x02;break;
		case 2:P0 = seven_seg[dat_ad/100];P2 = 0x04;break;
	}
	cp2++;
	if(cp2>=3)
	cp2 = 0;
}
void main()
{
	timer0_init ();
	adc0832_init();
	while(1);
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324599634&siteId=291194637