英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流
标题:
为何如下程序不对,老是显示254(测试数)没有AD转换?
[打印本页]
作者:
winnie
时间:
2009-4-25 23:41
标题:
为何如下程序不对,老是显示254(测试数)没有AD转换?
#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;
}
作者:
winnie
时间:
2009-4-25 23:43
AD中断有问题//一直在中断了,ADIF没有清0.
void interrupt mcu(void)
{
}
//中断服务程序
void interrupt adint(void)
{
ADIE=0;//---应该是ADIF=0;才对吧~~
adresult.adre[0]=ADRES;
add=adresult.y1;
delay1();
INTCON=0X00;
GIE=1;
PIE1=0X00;
ADIE=1;
ADGO=1;
}
欢迎光临 英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 (http://enroobbs.com/)
Powered by Discuz! X3.2