/* For time delay generation we are using the delay (unsigned milliseconds) function from Borland C/C++ dos.h library. */ #include main() { unsigned char orgbits; /* for orginal status of port B */ unsigned char bits; /* new status of port B */ outp(0x43, 0xB6); /* 8253/54 control byte */ /* For D3 note 1.1931MHz/147Hz=8116 =1FB4 Hex */ outp(0x42,0xB4); /* send the low byte to port 0x42 */ outp(0x42,0x1F); /* send the high byte to port 0x42 */ orgbits=inp(0x61); /* get the original status of port B */ bits=orgbits|3; /* make d0=1,d1=1 to turn the speaker on */ outp(0x61,bits); /* speaker is on and note is playing */ delay(250); /* wait for 250 milliseconds */ outp(0x61,orgbits); /* turn the speaker off */ delay(100); /* wait for 100 milliseconds */ /* Repeat for A3 note where 1.1931MHz/220Hz=5423 =152F Hex */ outp(0x42,0x2F); /* low byte */ outp(0x42,0x15); /* high byte */ orgbits=inp(0x61); bits=orgbits|3; outp(0x61,bits); delay(500); outp(0x61,orgbits); delay(100); /* Repeat for A4 note where 1.1931MHz/440Hz=2711=0A97 Hex */ outp(0x42,0x97); /* low byte */ outp(0x42,0x0A); /* high byte */ orgbits=inp(0x61); bits=orgbits|3; outp(0x61,bits); delay(500); outp(0x61,orgbits); }