Buzzer

Buzzer on the controller can be used.

 

Things to Prepare

CM-510 (CM-700 has no buzzers.)

 

Theory

Signals of the buzzer circuit can be controlled through I/O Port of the micro controller.  The buzzer can play different musical notes by adjusting signal frequency.  

PORTB, PORTC and PORTD are used in this example.  Please refer to Controller Port Map.

 

The relationship between musical scale and frequency is as below.

Time is a reciprocal number of frequency.  The conversion formula is as below.

( Unit : Hz )

Octave

=====

Scale

1

2

3

4

5

6

7

8

C

32.7032

65.4064

130.8128

261.6256

523.2511

1046.502

2093.005

4186.009

C#

34.6478

69.2957

138.5913

277.1826

554.3653

1108.731

2217.461

4434.922

D

36.7081

73.4162

146.8324

293.6648

587.3295

1174.659

2349.318

4698.636

D#

38.8909

77.7817

155.5635

311.1270

622.2540

1244.508

2489.016

4978.032

E

41.2034

82.4069

164.8138

329.6276

659.2551

1318.510

2637.020

5274.041

F

43.6535

87.3071

174.6141

349.2282

698.4565

1396.913

2793.826

5587.652

F#

46.2493

92.4986

184.9972

369.9944

739.9888

1479.978

2959.955

5919.911

G

48.9994

97.9989

195.9977

391.9954

783.9909

1567.982

3135.963

6271.927

G#

51.9130

103.8262

207.6523

415.3047

830.6094

1661.219

3322.438

6644.875

A

55.0000

110.0000

220.0000

440.0000

880.0000

1760.000

3520.000

7040.000

A#

58.2705

116.5409

233.0819

466.1638

932.3275

1864.655

3729.310

7458.620

G

61.7354

123.4708

246.9417

493.8833

987.7666

1975.533

3951.066

7902.133

 

Source

This is an example for CM-510.  This is not applicable for CM-700 because it has no buzzers.

 

if(~PIND & SW_START)

{

PORTC = ~(LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY);

_delay_ms(1);

PORTB |= 0x20;

_delay_ms(1);

PORTB &= ~0x20;

}

else

{

PORTC = LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY;

PORTB &= ~0x20;

}

Pressed buttons are checked by PORTD, LEDs and Buzzers can be turned on and off by controlling PORTB and PORTC pursuant to pressed buttons.

You can use macro function PIND to get the input value through PORTD.

PIND is 1 byte, and the pins of PORTD are facing each bit.

Therefore, you can read the value of the certain pin through "&" operation etc.

If "Start" button is pressed, the buzzer makes sounds through PORTB as soon as all LEDs are turned on.

 

Result

All LEDs are turned on, and the buzzer makes sounds of same musical notes continuously while "Start" button is being pressed.