Skip to content

Interfacing Buzzer with LPC2148 Development Board

Introduction

In this guide, we will explore how to interface a buzzer with the LPC2148 board. By following these steps, you will learn how to control the buzzer to produce sound.

Problem Statement

The objective of this guide is to demonstrate how to program LPC2148 development board to control beeps of buzzer.

Requirements

To successfully complete this project, you will need the following components:

  1. LPC2148 Development board

  2. USB cables, for power and programming.

Connectionsmoode

We will be beeping the buzzer connected to 11th GPIO of Port 0 (0.11) on the board . Ensure the jumper BUZZ (0.11) connector is connected properly.

Code

  1. Open the Keil IDE and create a new project with name buzzer by clicking on project in the menu bar. (Refer the steps from Getting started page to create new project - do not skip any step from the process)

  2. Copy the code given below into the main.c file and save the main.c file. You can also copy and paste the code from here into the file.

c

#include  <lpc214x.h>                    //Includes LPC2148 register definitions

#define BUZZER_ON() IO0CLR=(1<<11)       //Macro Functions to turn ON Buzzer
#define BUZZER_OFF() IO0SET=(1<<11)      //Macro Functions to turn OFF Buzzer

void Delay(unsigned int ms);                          

int  main(void)
{  
    PINSEL0 = 0x00000000;       // Enable GPIO on all pins
    PINSEL1 = 0x20000000;
    PINSEL2 = 0x00000000;

    IO0DIR = (1<<11) ;  // Set P0.11 as Output  to control buzzer  
    while(1)    
    {
        BUZZER_ON();
        Delay(100);  
        BUZZER_OFF();
        Delay(100);
    }
}

void Delay(unsigned int ms)
{
    unsigned int i, j;
    for (j = 0; j < (ms / 10); j++)
    {
        for (i = 0; i < 60000; i++);
    }
}
  1. After saving the file click on build icon or press F7. You should be able to see the build output with 0 errors and warnings.
Buzzer
  1. Now the hex file has been generated i.e. your program is compiled for uploading on the board. Open Flash Magic and do the following changes:

    a. Change the Device to LPC2148

    b. Select the Serial Port

    c. Change the baud rate to 9600

    d. Finally in the firmware section select the generated hex file.

    e. In the erase section select entire device (refer the image below).

  2. To upload the code do the following:

i. Connect a DB9 cable between the selected COMx port on your PC and the UART0 port on LPC2148 development board.

ii. Plug in an AC/DC 9V/1A supply to the development board and slide ON/OFF switch to ON position.

iii. Enter in to boot load mode by keeping the BOOT switch pressed and then press RESET switch.

iv. You should see LED D4 glowing which means board is now in programming mode.

  1. Click on Start in the Flash Magic tool. This will upload the code to the board.

  2. Once you have uploaded the code into board then exit the programming mode by pressing reset button once.

Output

Upon successfully running the project, the on-board buzzer will blink. The beeping demonstrates successful code execution.

Conclusion

In this guide, you have learned how to interface a buzzer with the LPC2148 development board. By following the steps outlined here, you gained knowledge about configuring GPIO pins, controlling the buzzer, and generating sound patterns. This basic example serves as a starting point for more advanced projects involving sound generation and control using the LPC2148 board.