现代微机原理与接口技术
(接口部分)
实验报告
学号: 09008112 姓名: 马京亚 成绩:
学号: 09008123 姓名: 郭 晨
成绩:
东南大学计算机科学与工程学院
二〇一〇年十二月
微机原理与接口技术(接口部分)实验报告
目录
实验二 可编程定时器计数器 8253...............................................3
实验三 Windows 中断..................................................................5
实验四 8255 实验.......................................................................... 9
实验五 七段数码管实验...............................................................13
实验六 竞赛抢答器.......................................................................20
实验七 交通灯控制实验...............................................................22
2
微机原理与接口技术(接口部分)实验报告
实验二 可编程定时器计数器 8253
1、实验目的
掌握 8253 的基本原理和编程方法
2、实验内容
实验(1)
将 8253 计数器 0 设置为方式 0,计数器初值设置为 N(N≤0FH)。将实验台上单脉冲接到
CLK0 上,用手动逐个输入单脉冲,编程使计数值在计算机屏幕上显示(查询方式),并同时
用逻辑笔观察 OUT0 电平变化(当输入 N+1 个脉冲后 OUT0 变高电平)。
流程图
接线说明
8253:CS# --> 280H-287H
CLK0 --> 单脉冲
GATE0 --> VCC
OUT0 --> 逻辑笔
程序
//Lab2_1
#include
#include
#include "ApiEx.h"
#pragma comment (lib,"ApiEx.lib")
void main()
3
微机原理与接口技术(接口部分)实验报告
{
printf("Press any key to begin!\n");
getch();
printf("Press any key to exit!\n");
if(!Startup())
{
printf("ERROR:Open Device Error!\n");
return;
}
unsigned char data;
PortWriteByte(0x283,0x10);
PortWriteByte(0x280,10);
while(!kbhit())
{
PortReadByte(0x280,&data);
printf("%d\n",data);
Sleep(1000);
}
Cleanup();
}
实验(2)
将计数器 0,计数器 1 分别设置为方式 3,利用这两个计数器,将实验台上的一个 1MHz 的
方波信号分频为 1Hz 的方波(做好 8253 初始化工作),并将此方波接到 L7 上,观察 L7 以周
期为 1 秒的频率闪烁。
接线说明
8253:CS# --> 280H-287H
CLK0 --> 1MHz
OUT0 --> CLK1
GATE0 --> VCC
GATE1 --> VCC
OUT1 --> L7
程序
//Lab2_2
#include
#include
#include "ApiEx.h"
#pragma comment (lib,"ApiEx.lib")
void main()
{
printf("Press any key to begin!\n");
getch();
4
微机原理与接口技术(接口部分)实验报告
printf("Press any key to exit!\n");
if(!Startup())
{
printf("ERROR:Open Device Error!\n");
return;
}
PortWriteByte(0x283, 0x37);
PortWriteByte(0x283, 0x77);
PortWriteByte(0x280, 0x00);
PortWriteByte(0x280, 0x10);
PortWriteByte(0x281, 0x00);
PortWriteByte(0x281, 0x10);
while (!kbhit()) {}
}
3、实验结果
实验(1)
用手动逐个输入单脉冲,编程使计数值在计算机屏幕上显示,当输入 N+1 个脉冲后 OUT0
变高电平。
实验(2)
l7 以周期 1 秒闪烁
实验三 Windows 中断
1、实验目的
了解 Windows 下中断处理过程
5
微机原理与接口技术(接口部分)实验报告
比较中断和查询两种数据交换方法的效率差别。
2、实验内容
实验(1)
用查询和中断方式分别实现控制指示灯,然后在任务栏中比较中断和查询方式下 CPU 利用
率的差别
查询方式
将 8255 的 A 口设为输出,接指示灯 L0~L7,C 口设为输入并将 PC0 接正脉冲输入,CS 接到
实验台的 138 译码的 8 组 I/O 地址中的任意一组上,通过程序不断地查询 PC0 的输入值,当
为高电平的时候让指示灯显示一秒钟的 0x55(软件延时),否则让指示灯显示 0xAA。
接线说明
8255:CS# --> 280H-287H
PC0 --> 单脉冲
PA0-PA7 --> L0-L7
程序
//Lab3_1_1
#include
#include
#include "ApiEx.h"
#pragma comment(lib,"ApiEx.lib")
void main()
{
printf("Press any key to begin!\n");
getch();
printf("Press any key to exit!\n");
if(!Startup())
{
printf("ERROR:Open Device Error!\n");
return;
}
PortWriteByte(0x283, 0x89);
while (!kbhit()) {
PortReadByte(0x282,&data);
if (data&0x01) {
PortWriteByte(0x280,0x55);
Sleep(1000);
}
else {
PortWriteByte(0x280,0xAA);
Sleep(1000);
6
微机原理与接口技术(接口部分)实验报告
}
}
Cleanup();
}
中断方式
将 8255 的 A 口设为输出,接指示灯 L0~L7,CS 接到实验台的 138 译码的 8 组 I/O 地址中的
任意一组上,IRQ 直接接到实验台上的单脉冲,要求直接用手动产生的单脉冲作为中断请求
信号,每按一次单脉冲产生一次中断让指示灯显示一秒钟的 0x55,否则让指示灯显示 0xAA。
接线说明
8255:CS# --> 280H-287H
IRQ --> 单脉冲
PA0-PA7 --> L0-L7
程序
Lab3_1_2
#include
#include
#include "ApiEx.h"
#pragma comment(lib,"ApiEx.lib")
int i;
void MyISR()
{
PortWriteByte(0x288,0x55);
Sleep(1000);
printf("%d\n",i++);
}
void main()
{
printf("Press any key to begin!\n");
getch();
if(!Startup())
{
printf("ERROR:Open Device Error!\n");
return;
}
printf("Press any key to exit!\n");
PortWriteByte(0x28b, 0xa0);
RegisterLocalISR(MyISR);
EnableIntr();
while (!kbhit()) {
PortWriteByte(0x288,0xaa);
Sleep(100);
7
微机原理与接口技术(接口部分)实验报告
}
DisableIntr();
Cleanup();
}
实验(2)
利用实验二的第二个实验产生一个周期为 1 秒的中断,编程在中断处理程序中打印中断的
次数到计算机屏幕上。
接线说明
8255:CS# --> 288H-28FH
IRQ --> OUT1
8253:CS# --> 280H-287H
CLK0 --> 1MHz
OUT0 --> CLK1
GATE0 --> VCC
GATE1 --> VCC
程序
//Lab3_2
#include
#include
#include "ApiEx.h"
#pragma comment (lib,"ApiEx.lib")
int i=0;
void MyISR(){
printf("%d\n",i++);
}
void main()
{
printf("Press any key to begin!\n");
getch();
if(!Startup())
{
printf("ERROR:Open Device Error!\n");
return;
}
printf("Press any key to exit!\n");
PortWriteByte(0x28b,0x80);
PortWriteByte(0x283, 0x37);
PortWriteByte(0x283, 0x77);
PortWriteByte(0x280, 0x00);
PortWriteByte(0x280, 0x10);
PortWriteByte(0x281, 0x00);
8