PROTEUS仿真电路图:
电路图原理:
用74LS138译码器控制点阵的阴极端口,P2口控制阳极端口,也即是字形代码输入端。
仿真效果图:
C语言程序代码:
#include <REGX51.H>
#include <at89x51.h>
sbit a=P1^0;
sbit b=P1^1;
sbit c=P1^2;
unsigned char code hua[50]=
{
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x3E,0x8,0x8,0x8,0x8,0x3E,0x0,
0x0,0x66,0x99,0x81,0x42,0x24,0x18,0x0,
0x0,0x24,0x24,0x24,0x24,0x24,0x24,0x18,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
};
void main()
{
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
EA=1;
ET0=1;
TR0=1;
while(1);
}
void duan() interrupt 1
{
static unsigned char i=0;//static很重要否则点阵不能正常显示,因为将其定义为静态变量后,每次中断产生后,他的值会保持原来的值,不会重新被置零,如果重复置零会造成点阵无法正确显示文字。
static unsigned int index=0,time;
TH0=0xFC;
TL0=0x67;
switch(i)
{
case 0:a=0;b=0;c=0;i++;P2=hua[index+0];break;
case 1:a=1;b=0;c=0;i++;P2=hua[index+1];break;
case 2:a=0;b=1;c=0;i++;P2=hua[index+2];break;
case 3:a=1;b=1;c=0;i++;P2=hua[index+3];break;
case 4:a=0;b=0;c=1;i++;P2=hua[index+4];break;
case 5:a=1;b=0;c=1;i++;P2=hua[index+5];break;
case 6:a=0;b=1;c=1;i++;P2=hua[index+6];break;
case 7:a=1;b=1;c=1;i=0;P2=hua[index+7];break;
default:break;
}
time++;
if(time>=250)
{
time=0;
index++;
if(index>=32)
{
index=0;
}
}
}