buzzer programming?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Thunder2fr

buzzer programming?

Post by Thunder2fr »

Hello, everybody.
I develop an OS with my friends and I want to know how program a internal buzzer driver.
We want to can play melody with the internal buzzer and to make it, we want to change the buzzer frequency for example.
Where can I have some information?
Thanks.
ASHLEY4

Re:buzzer programming?

Post by ASHLEY4 »

Code: Select all

org 100h
xor ah,ah
int 16h
call Beep1
xor ah,ah
int 16h
call Beep2
xor ah,ah
int 16h

ret

Beep1:
MOV     [Hz],100h
CALL    Sound
CALL    DeLay
CALL    NOSOUND

RET

;------------------------------------------------------------------------------------------------
; Beep tone 2
;------------------------------------------------------------------------------------------------

Beep2:
MOV     [Hz],150h
CALL    Sound
CALL    DeLay
CALL    NOSOUND
RET
;------------------------------------------------------------------------------------------------
; Sound
;------------------------------------------------------------------------------------------------

Sound:
MOV BX,[Hz]                       ;This
MOV AX,34DDH
MOV DX,0012H
CMP DX,BX
JNC DONE1 
DIV BX
MOV BX,AX 
IN AL,61H
TEST AL,3 
JNZ A99
OR  AL,3 
OUT 61H,AL
MOV AL,0B6H 
OUT 43H,AL 
A99:
MOV AL,BL 
OUT 42H,AL
MOV AL,BH 
OUT 42H,AL
DONE1: 
RET
 
;------------------------------------------------------------------------------------------------
; Delays
;------------------------------------------------------------------------------------------------
 
DeLay:
MOV  CX, [MilliS] 
JCXZ A2
A1: 
CALL DeLaYoneMS
LOOP A1 
A2: RET
 
;------------------------------------------------------------------------------------------------
;Delay
;------------------------------------------------------------------------------------------------
 
DeLaYoneMS:
 
PUSH CX                          ; Save CX
MOV  CX, [OneMS]                 ; Loop count into CX 
B1:
LOOP B1                          ; Wait one millisecond 
POP  CX                          ; Restore CX
RET 

;------------------------------------------------------------------------------------------------
; Turn sound off 
;------------------------------------------------------------------------------------------------
 
NOSOUND:
IN  AL,61h 
AND AL,11111100b
OUT 61h,AL 
RET
 
Hz     DW ?
MilliS DW 200
OneMS  DW 40000

The above code uses no dos int, so can be run from realmode, if you find old turbo pascal programs, they use the above call, that way you can play melody :-).

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:buzzer programming?

Post by Pype.Clicker »

more theorically, the "buzzer" is usually called "internal PC speaker". It's a trick IBM set up from a free clock generator (8253) and a free output bit on the multi-purpose parallel interface (8255, now emulated on the 8042)
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:buzzer programming?

Post by bubach »

does anyone now why i can hardly hear the internal pc speaker on new computers while my 286/386:es can be heard from a diffrent room?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:buzzer programming?

Post by Pype.Clicker »

probably because nowadays
- PC speakers are emulated on the soundcard speaker, rather than being a separated device
- the wave is thus no longer a Square (one of the more loud soundwaves) but something smoother
- noone really wish to hear the neighbour's PC speaker ;)
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:buzzer programming?

Post by bubach »

- noone really wish to hear the neighbour's PC speaker
Maybe i do.. ;-)
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
Post Reply