|
#include <pic.h>
#include <pic16f7x.h>
#include <math.h>
void delay();
const char table[]={0xc0,0xf9,0xa4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff};
unsigned char add;
unsigned int l;
union adres
{int y1;
unsigned char adre[1];
}adresult;
//A/D转化初始化子程序
void adinitial()
{
ADCON1=0b00000111;
ADCON0=0b11000001;
INTCON=0X00;
GIE=1;
PIE1=0X00;
ADIE=1;
ADGO=1;
}
void display()
{
int j,k;
j=add/100;
PORTA=0X00;
if(j==0){j=10;}
PORTB=table[j];
PORTA=0X08;
delay();
PORTA=0X0;
k=j;
j=(add%100)/10;
if ((k==10)&&(j==0)){j=10;}
PORTB=table[j];
PORTA=0X04;
delay();
PORTA=0X0;
j=add%10;
PORTB=table[j];
PORTA=0X02;
delay();
PORTA=0X0;
}
void delay1()
{
for(l=0;l<=5535;l++)
continue;
}
//中断服务程序
void interrupt adint(void)
{
ADIE=0;
adresult.adre[0]=ADRES;
add=adresult.y1;
delay1();
INTCON=0X00;
GIE=1;
PIE1=0X00;
ADIE=1;
ADGO=1;
}
main ()
{
TRISB= 0b00000000; //设置B口为输出。
TRISA= 0b11000001; //B'11000001'
PORTA=0X00;
add=0xfe;
adinitial();
loop: while (1)
{
display();
}
}
void delay()
{
int i;
for(i=0;i<=6;i++)
continue;
} |
|