How to Write a C program that will turn on PC speaker by using port 61H of Interval Timer

Vu Old Solved Programming Based Assignments Codes are Available in this Section.
Post Reply
User avatar
ALI RAZA
★★★★★★★★★★★★★
★★★★★★★★★★★★★
Posts: 177
Joined: Fri Dec 22, 2017 8:10 am
Location: Lahore
Has thanked: 6 times
Been thanked: 7 times
Contact:
Status: Offline

How to Write a C program that will turn on PC speaker by using port 61H of Interval Timer

Post by ALI RAZA » Tue Oct 02, 2018 10:23 am

Problem Statement:

Write a C program that will turn on PC speaker (for variable-pitched sound) by using port 61H of Interval Timer. The divisor value for Interval Timer will be last eight digits of your Student ID.

Detailed Instructions:
1) In this program, you will access internal PC speaker by using port 61H. Least two significant bits of port 61H are used for connecting PC speaker to Interval Timer.
2) In order to program Interval Timer, you have to first load the Command Byte into the Command Register. Calculate Command Byte according to following criteria:
a. Channel: 2
b. Interval Timer Mode: 2
c. Counter: Binary
d. Divisor bytes to be loaded: All (For calculating divisor value, read instruction 4)
3) You will first load last four digits of your Student ID as a divisor value (see the purple color digits in below example ID), and then after a delay of 2 seconds, you will again load new divisor value which will be next four digits of your Student ID (see the orange color digits in below example ID).
BC1 2345 6789
4) For producing delay, use Timer Count, a double word variable in the BIOS data area which is placed at the location 0040:006C
5) After loading each divisor value, turn on the PC speaker
6) You can check the output of the program by booting your system in DOS mode and then running the exe file. But does not worry if PC speaker does not produce sound; the host operating system may restrict you to directly access PC speaker. Just focus on the concepts.
7) Your assignment file should be a single Word file (.doc or .docx) containing complete code.
8) You can use Consolas font for enhancing readability of the code in Word file.

Answer:

Code: Select all

#include<BIOS.H>
#include<DOS.H>

unsigned long int * time = (unsigned long int *) 0x0040006C;

void main() {

	unsigned long int tx;

	outportb(0x43, 0xB4);
	outportb(0x42, 89);
	outportb(0x42, 67);
	outportb(0x61, inportb(0x61) | 3);

	tx = *time;
	tx = tx + 36;

	while((*time) <= tx);

	outportb(0x43, 0xB4);
	outportb(0x42, 45);
	outportb(0x42, 23);
	outportb(0x61, inportb(0x61) | 3);
}



Post Reply

Last 10 Members Who Visited This Topic

  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 1 guest