{0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},
{0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},
{0x00,0x00,0x0E,0x38,0x11,0x44,0x10,0x84,0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00},
{0x00,0x00,0x0E,0x04,0x08,0x0C,0x08,0x0C,0x08,0x08,0x08,0x10,0xFF,0xFE,0x00,0x00},
{0x00,0x00,0x3F,0xFC,0x41,0x02,0x42,0x02,0x06,0x02,0x0E,0x06,0x0C,0x0C,0x00,0x00},
{0x00,0x00,0x20,0x04,0x20,0x08,0x27,0x98,0x24,0xB0,0x24,0x82,0xA4,0x81,0x64,0xFE},
{0x24,0x80,0x24,0x80,0x24,0xA0,0x27,0xB0,0x60,0x1C,0x20,0x08,0x00,0x00,0x00,0x00},
{0x28,0x04,0x24,0x08,0x22,0x32,0x21,0xC2,0x26,0xC2,0x38,0x34,0x04,0x04,0x18,0x08},
{0xF0,0x30,0x17,0xC0,0x10,0x60,0x10,0x18,0x14,0x0C,0x18,0x06,0x10,0x04,0x00,0x00},
{0x02,0x02,0x82,0x04,0x73,0xF8,0x20,0x04,0x00,0x02,0x3F,0xE2,0x20,0x42,0x40,0x82},
{0x40,0x02,0x3F,0xFA,0x20,0x02,0x20,0x42,0x20,0x22,0x3F,0xC2,0x00,0x02,0x00,0x00},
{0x01,0x00,0x02,0x04,0x0C,0x1C,0x3F,0xC0,0xC0,0x1C,0x09,0x02,0x16,0x02,0x60,0x92},
{0x20,0x4A,0x2F,0x82,0x20,0x02,0x24,0x0E,0x22,0x00,0x31,0x90,0x20,0x0C,0x00,0x00},
{0x00,0x00,0x00,0x08,0x1F,0xDC,0x3F,0x08,0x3C,0x00,0x30,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}。
a)主程序流程图 (b)中断服务程序流程图
图3. 程序流程图
动态扫描显示程序代码如下:
while (1)
{for (i=0;i<8;i++) //显示左半边屏幕
{ P0=*(p+offset+2*i);
P2=i|0x90; //P2.4=1,P2.3=0 选中U3, 输出扫描码给U7
delay();
P0=*(p+offset+2*i+1);
P2=i|0x08; //P2.4=0,P2.3=1 选中U2, 输出扫描码给U6
delay(); }
for (i=8;i<16;i++) //显示右半边屏幕
{ P0=*(p+offset+2*i);
P2=(i-8)|0xC0; //P2.6=1 P2.5=0, P2.4=0 选中U5,输出扫描码U9
delay();
P0=*(p+offset+2*i+1);
P2=(i-8)|0x20; //P2.5=1 P2.4=0, P2.3=0 选中U4,输出扫描码U8
delay();
} }
4. 调试与仿真
Proteus仿真时,单片机需要加载程序,加载程序为.HEX文件。本设计利用Keil μVision2, 在新建Keil项目时选择AT89C52单片机作为CPU,将C语言源程序导入,在“Options For Target”对话窗口中,选中“Output”选项中的“Create HEX File”,编译链接后就可以生成.HEX文件。在Proteus ISIS中,选中AT89C52并单击鼠标左键,对AT89C52进行设置,设置单片机时钟频率为12MHz,按照正确的文件路径加载.HEX文件。对单片机设置完毕后就可以开始仿真了。仿真过程中如有硬件问题可在Proteus ISIS中直接修改,如有软件问题可在Keil μVision2中直接修改,通过Keil与Proteus的联合调试就可以得到满意的结果。本设计的仿真结果如图4所示。