2.9controldengiaothongnga4

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

Dieu khien den giao thong tai 1 nga tu.

Xem anh "Bai2_8.jpg" kem theo.

*/

#include "stdafx.h"

#include<conio.h>

#include<stdio.h>

#include<dos.h>

#include<PCIXP.h>

void phase1(void)

{

// Cho phep di theo truc Y, cam di theo truc X -> Bat Den Xanh1, Xanh3, Do2, Do4, DiBo2, DiBo4, cac den con lai tat.

//

// PortA: 0 0 1 1 0 1 0 0 = 0x34

//

// PortC: 1 0 0 0 1 0 0 1 = 0x89

//

outportb(add, 0x34);

outportb(add+2,0x89);

Sleep(3000); // Thoi gian thong duong cua truc Y

// Tat Xanh1, Xanh3 & Bat Vang1, Vang3 -> chuan bi cam di theo truc Y, yeu cau moi nguoi giam toc do.

//

// PortA: 0 0 1 1 0 0 1 0 = 0x32

//

// PortC: 0 1 0 0 1 0 0 1 = 0x49

//

outportb(add,0x32);

outportb(add+2,0x49);

Sleep(1000); // Thoi gian bat den vang

// Tat Do2, Do4, DiBo2, DiBo4, Vang1, Vang3 -> Cam di theo truc Y.

//

// PortA: 0 0 0 0 0 0 0 0 = 0x00

//

// PortC: 0 0 0 0 0 0 0 0 = 0x00

//

outportb(add,0x00);

outportb(add+2,0x00);

}

void phase2(void)

{

// Cho phep di theo truc X, cam di theo truc Y -> Bat Den Xanh2, Xanh4, Do1, Do3, DiBo1, DiBo3, cac den con lai tat.3

//

// PortA: 1 0 0 0 1 0 0 1 = 0x89

//

// PortC: 0 0 1 1 0 1 0 0 = 0x34

//

outportb(add, 0x89);

outportb(add+2,0x34);

Sleep(3000); // Thoi gian thong duong cua truc X

// Tat Xanh2, Xanh4 & Bat Vang2, Vang4 -> chuan bi cam di theo truc X, yeu cau moi nguoi giam toc do.

//

// PortA: 0 1 0 0 1 0 0 1 = 0x49

//

// PortC: 0 0 1 1 0 0 1 0 = 0x32

//

outportb(add,0x49);

outportb(add+2,0x32);

Sleep(1000); // Thoi gian bat den vang

// Tat Do1, Do3, DiBo1, DiBo3, Vang2, Vang4 -> Cam di theo truc X.

//

// PortA: 0 0 0 0 0 0 0 0 = 0x00

//

// PortC: 0 0 0 0 0 0 0 0 = 0x00

//

outportb(add,0x00);

outportb(add+2,0x00);

}

void main()

{

int add;

add = Get_Addr("PCI_8255");

outportb(add+3, 0x80); // Tu dieu khien cho cong A,C mode ra

printf("

Chuong trinh dieu khien den giao thong.");

printf("

Bam 1 phim bat ki de ket thuc chuong trinh.");

outportb(add,0x00); // Ban dau, tat het cac den PortA

outportb(add+2,0x00); // Ban dau, tat het cac den PortC

do

{

phase1();

phase2();

}while(!kbhit());

}

Bạn đang đọc truyện trên: TruyenFun.Vip