51单片机A/D转换接口扩展,做一个16进制显示的电压表
扫描二维码
随时随地手机看文章
遇到的问题如下:第二个数码管不亮,电平跳变都是对的。
如果在中断的P1,P2赋值那一块加上死循环两个数码管就都能亮了,
但是不能时刻测电压值了,纠结。
道编程如下:
#include
unsigned char tab[16] = {
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char xdata *ADC;
unsigned char num, s, g, sum;
void delay(unsigned int Delay)
{
unsigned int i;
for(;Delay;Delay--) for(i=0;i<54;i++);
}
void main()
{
IT0 = 1; EX0 = 1; EA = 1;
ADC = 0xf8fb;
*ADC = 0;
while(1) {
P2 = 0x02; P1 = tab[s]; delay(1); P2 = 0xf9;
P2 = 0x04; P1 = tab[g]; delay(1); P2 = 0xf9;
}
}
void A() interrupt 0
{
num = *ADC;
s = num / 16;
g = num % 16;
*ADC = 0;
}
试试看。