1.14 do re mi

#include <iostream.h>

#include<conio.h>

#include<dos.h>

#define DCCS_8255 0x60

#define DCCS_8253 0x40

void set_sound(int Hz, int milisecond);

void main()

{

clrscr();

cout<<"

\t\tChuong trinh dieu khien 8255 va 8253 phat am ra loa.";

cout<<"

Bam cac phim 'a','s','d','f','h','j' de phat am, 'Esc' de ket thuc.

";

char k;

// Xuat tu dieu khien cho 8253, bo dem C2 hoat dong o che do 3, phat song vuong

outportb(DCCS_8253+3,0xB6);

do

{

k = getch();

switch (k)

{

case 'a':

set_sound(261,200);

cout<<"\rAm: Do'";

break;

case 's':

set_sound(293,200);

cout<<"\rAm: Re ";

break;

case 'd':

set_sound(329,200);

cout<<"\rAm: Mi ";

break;

case 'f':

set_sound(392,200);

cout<<"\rAm: Son";

break;

case 'g':

set_sound(440,200);

cout<<"\rAm: La ";

break;

case 'h':

set_sound(500,200);

cout<<"\rAm: Si ";

break;

case 'j':

set_sound(523,200);

cout<<"\rAm: Do'";

break;

}

}while(k!=27);

}

void set_sound(int Hz, int milisecond)

{

int temp;

int value;

temp = 1193180/Hz;

// Set frequency

outportb(DCCS_8253+2,temp); // Send low_byte

outportb(DCCS_8253+2,temp>>8); // Send high_byte

// Set bit PB0 , PB1 to start sound

value = inportb(DCCS_8255+1);

outportb(DCCS_8255+1,value|0x03);

// delay milisecond

delay(milisecond);

// Stop sound

outportb(DCCS_8255+1,value&0xFC);

}

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

Tags: #may#tinh