本帖最后由 江南七叶 于 2011-5-7 22:47 编辑
下面是我的程序和电路图。
故障:仿真时只在开始时进入过一次中断服务程序,然后就一直没法进入中断了!!!!
#include "reg52.h"
#include "stdio.h"
#include "intrins.h"
#include "math.h"
#define uchar unsigned char
uchar m;
uchar AD=0x00;
uchar j2[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //X段扫描
uchar j1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
sbit cs=P3^0;
sbit wr=P3^6;
sbit rd=P3^7;
sbit xin=P3^1;
/*延时程序*/
void delay(int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<120;j++);
}
/*点阵显示*/
void xianshi()
{
int i,j,k;
for(j=7;j>0;j--)
{
m=j1[j-1];
j1[j]=m;
}
j1[0]=AD;
for(k=0;k<3;k++)
{
for(i=0;i<8;i++)
{
P2=j2;
P1=j1;
delay(2);
}
}
EX0=1;
wr=0;
rd=1;
}
main()
{
P0=0xff;
cs=0;
wr=0; //启动转AD换
rd=1;
EA=1; //开中断
EX0=1;
while(1)
{
xin=0;
delay(5);
xin=1;
delay(5); //判断是否进入中断服务程序
}
}
void service0( void) interrupt 0 using 0
{
EX0=0; //关外部中断0
rd=0;
wr=1; //启动数据输出
delay(1);
AD=P0; //读数据
AD=AD/64;
switch(AD)
{
case 0:
{;
AD=0x01;
}
break;
case 1:
{;
AD=0x03;
}
break;
case 2:
{;
AD=0x07;
}
break;
case 3:
{;
AD=0x0f;
}
break;
case 4:
{;
AD=0x1f;
}
break;
case 5:
{;
AD=0x3f;
}
break;
case 6:
{;
AD=0x7f;
}
break;
case 7:
{;
AD=0xff;
}
break;
default:break;
}
xianshi(); //显示
return;
} |