2.4chay vong tron

// Bai2_4.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include<conio.h>

#include<stdio.h>

#include<dos.h>

#include<PCIXP.h>

void main()

{

char k;

unsigned int add,byte,i;

add = Get_Addr("PCI_8255");

do{

printf("

Chon chuc nang:");

printf("

1, Xuat mot byte ra cong A.");

printf("

2, Chi dat 2 bit PA5 va PA7 len 1.");

printf("

3, Diem sang nhay vong A sang cong C theo nguoc chieu kim dong ho.");

printf("

4, Diem sang nhay vong A sang cong C chieu kim dong ho.");

printf("

5, Thoat chuong trinh.");

k = getch();

switch (k)

{

case '1':

system("cls");

printf("

Nhap gia tri xuat ra cong A (0->255): ");

scanf("%d",&byte);

outportb(add+3, 0x80);

outportb(add,byte);

printf("

Da dat lai gia tri cho cong A");

break;

case '2':

byte = inportb(add);

byte = byte | 0xA0;

outportb(add, byte);

system("cls");

printf("

Da dat 2 bit PA5 va PA7 len 1.");

break;

case '3':

outportb(add+3, 0x80);

system("cls");

printf("

Dang thuc hien yeu cau...nhan mot phim bat ki de ket thuc !");

do{

byte = 0x01;

for(i = 0;i<8;i++)

{

outportb(add, byte);

byte=byte<<1;

Sleep(150);

}

outportb(add, 0x00);

byte = 0x80;

for(i = 0;i<8;i++)

{

outportb(add+2, byte);

byte=byte>>1;

Sleep(150);

}

outportb(add+2, 0x00);

}while(!kbhit());

break;

case '4':

outportb(add+3, 0x80);

system("cls");

printf("

Dang thuc hien yeu cau...nhan mot phim bat ki de ket thuc !");

do{

byte = 0x80;

for(i=0;i<8;i++)

{

outportb(add, byte);

byte=byte>>1;

Sleep(150);

}

outportb(add, 0x00);

byte = 0x01;

for(i=0;i<8;i++)

{

outportb(add+2, byte);

byte=byte<<1;

Sleep(150);

}

outportb(add+2, 0x00);

}while(!kbhit());

break;

}

}while(k!='5');

}

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #may#tinh