2.15taomaydoxung

Màu nền
Font chữ
Font size
Chiều cao dòng

/*

Do thoi gian chinh xac giua 2 su kien.

Tuong tu bai 2_14

*/

#include "stdafx.h"

#include<conio.h>

#include<stdio.h>

#include<dos.h>

#include<PCIXP.h>

void main()

{

int miliseconds;

unsigned int HighByte=0,LowByte=0,value1, value2;

int add=Get_Addr("PCI_8255");

// Dung bo dem C0 cua 8254 de tao ra clock co chu ky 1ms.

// Out cua C0 ket noi vao Clock cua C1

outportb(add+11, 0x36); //dung bo T0 che do 3

outportb(add+8, 0xE8);

outportb(add+8, 0x03);

// Bat dau chuong trinh chinh

outportb(add+11, 0xB2); // Dung bo dem T2 che do 1

outportb(add+10, 0xFE); // Nap gia tri dem toi da

outportb(add+10, 0xFF);

outportb(add+11, 0x80); // Chot bo dem T2

LowByte = inportb(add+10); // Doc byte thap

HighByte = inportb(add+10); // Doc byte cao

value1 = (LowByte&0xFF) + (HighByte<<8); // Luu gia tri thuc su trong bo dem truoc khi bat dau dem

printf("

Xung 1ms duoc tao ra tu bo dem C0.

Su dung bo dem C2 de do thoi gian giua 2 su kien.");

printf("

Hay nhan & giu cong tac tao xung don de cho phep bo dem C2.");

printf("

Sau khi nha cong tac,hay nhan 1 phim bat ki de hien thi thoi gian giu cong tac.");

getch();

outportb(add+11, 0x80); // Chot bo dem T2

//bo dem T1, che do 2

LowByte = inportb(add+10); // Doc byte thap

HighByte = inportb(add+10); // Doc byte cao

value2 = (LowByte&0xFF) + (HighByte<<8); // So xung = gia tri doc duoc ngay sau khi nap (value1) tru di gia tri hien thoi cua bo dem

miliseconds = value1 - value2 ;

printf("

Thoi gian giu cong tac la: %7d ms",miliseconds);

getch();

}

Bạn đang đọc truyện trên: Truyen2U.Pro

#may#tinh