Page 1 of 1
buzzer programming?
Posted: Thu Jan 27, 2005 11:53 am
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.
Re:buzzer programming?
Posted: Thu Jan 27, 2005 2:13 pm
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.
Re:buzzer programming?
Posted: Fri Jan 28, 2005 2:35 am
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)
Re:buzzer programming?
Posted: Fri Jan 28, 2005 2:45 am
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?
Re:buzzer programming?
Posted: Fri Jan 28, 2005 2:57 am
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
Re:buzzer programming?
Posted: Sat Jan 29, 2005 2:24 pm
by bubach
- noone really wish to hear the neighbour's PC speaker
Maybe i do..