We have discussed in the past experiments how to use a PIC microcontroller to do a variety of things from flashing an LED to driving a motor, etc. Today, we will see how to play notes of a song with a PIC microcontroller. Musical notes are simply sound waves of particular frequencies. If the frequency of a note is known correctly, a microcontroller can be programmed to play the note by generating a square wave (of the same frequency) signal at one of its I/O pins. The signal must be fed to a speaker to listen to the sound. Here, we will discuss playing notes of the popular “Happy birthday to you” tune using a PIC16F628A microcontroller and a buzzer.
Tag Archives: mikroC
This tutorial describes how to use the mikroElektronika’s GLCD bitmap editor tool to convert a monochromatic bit map (BMP) image file into a data array so that it could be displayed on a graphics LCD using a microcontroller. The GLCD bitmap editor tool is embedded into mikroElektronika’s compilers. It can generate a code equivalent of a BMP image, which can be easily inserted into the microcontroller’s source program.
HD44780 based LCD displays are very popular among hobbyists because they are cheap and they can display characters. Besides they are very easy to interface with microcontrollers and most of the present day high-level compilers have in-built library routines for them. Today, we will see how to interface an HD44780 based character LCD to a PIC16F688 microcontroller. The interface requires 6 I/O lines of the PIC16F688 microcontroller: 4 data lines and 2 control lines. A blinking test message, “Welcome to Embedded-Lab.com”, will be displayed on the LCD screen.
All HD44780 based character LCD displays are connected through 14 pins: 8 data pins (D0-D7), 3 control pins (RS, E, R/W), and three power lines (Vdd, Vss, Vee). Some LCDs have LED backlight feature that helps to read the data on the display during low illumination conditions. So they have two additional connections (LED+ and LED-), making altogether 16 pin. A 16-pin LCD module with its pin diagraam is shown below.
Today is our first session in PIC microcontroller lab, and we will begin with an experiment that flashes an LED on and off. While this looks very simple it is the best project to start because this makes sure that we successfully wrote the program, compiled it, loaded inside the PIC, and the circuit is correctly built on the breadboard.
In this lab session we will connect an LED to one of the port pin of PIC16F688 and flash it continuously with 1 sec duration.
You must be familiarized with,
- digital I/O ports (PORTA and PORTC) of PIC16F688
- direction control registers, TRISA and TRISC
- special function registers CMCON0 and ANSEL
If you are not then please read this first: Digital I/O Ports in PIC16F688.
To our basic setup on the breadboard (read Getting Ready for the First Lab), we will add a light-emitting-diode (LED) to port pin RC0 (10) with a current limiting resistor (470 Ohm) in series. The complete circuit diagram is shown below.
The development of an embedded system requires some hardware and software products. Although the hardware requirements depend on the type and complexity of the project, the following hardware tools are required in all of the experiments we are going to discuss here.
- A solderless breadboard for constructing and testing the experimental circuits. The breadboard is chosen because it is reusable. You can change, modify or remove the components on it at any time. While an embedded system is in development phase, you never know in advance whether or not your circuit will function correctly when assembled. So it is always good to test it first on a breadboard. Once it performs well, the circuit can be transferred to a printed circuit board.
- Microcontroller chips (PIC16F688 and PIC16F628A in this case)
- A PIC programmer to load firmware inside the microcontroller. You need to buy one with in circuit serial programming(ICSP) capability. This allows you to quickly program the PIC while it is in the target circuit. I have got an iCP01 USB PIC programmer from iCircuit Technologies. It is very handy, easy to use, and low-cost ICSP programmer for the most popular flash-based PIC microcontrollers. The best thing about it is that it is compatible with Microchip’s PICKit2 and MPLAB IDE softwares. And, it works great. Read Choosing a PIC Programmer.
- A PC is required for two purposes: to develop and compile the firmware for the microcontroller, and to transfer it to the PIC programmer so that it could be loaded into the program memory of the microconroller.
- A regulated +5V DC source to power your circuit on the breadboard.
- A digital multimeter as test equipment.
- Other components like resistors, LEDs, capacitors, wires, etc as required.
Required Software Tools
In addition to the above hardware, following software products are required during the experiments.
- A Compiler to develop and compile the firmware. You need to download and install the free version of mikroC Pro for PIC (a C compiler for PIC from Mikroelektronika) to follow these experiments. Here is the download link: mikroC Pro for PIC. Also download mikroC Pro manual and Create First Project. These user’s manuals describe the compiler features and setup procedure in detail.
- A microcontroller device programmer software that’s provided by the vendor along with the programmer hardware. It is required to transfer the firmware from the PC to the microcontroller. You can download PICkit2 programming software for iCP01 USB PIC programmer here.