Skip to main content

Posts

Showing posts from 2009

Experiment No. 8: Use of PWM to control the brightness of a LED.

Introduction:
A PIC16F628A has an in-built Capture/Compare/PWM (CCP) module for which the I/O pin is served by RB.3 (Pin No. 9). In this experiment we are going to use the CCP as a PWM to control the power to a LED. PWM stands for the Pulse Width Modulation where the width of a digital waveform is varied to control the power delivered to a load. The underlying principle in the whole process is that the average power delivered is directly proportional to the modulation duty cycle. The term duty cycle describes the proportion of on time to the regular interval or period of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
Image Source: http://www.micromouseinfo.com/introduction/images/intro_hardware/PWMod.gif The mikroC has an in-built library functions for PWM hardware module. Click here for details.

Experiment No. 7: Timers and Interrupts

Background
Many microcontroller applications like generating periodic signals, measuring time interval, keeping date and time, use time as their variable. Therefore, microcontrollers need to have some internal resources to accurately measure time. The PIC16F628A has 3 timer modules which are known as Timer0, Timer1, and Timer2. The basic unit of a timer is a free-run 8-bit or 16-bit incrementing synchronous counter which can be programmed to count internal or external pulses. The count number stored by each counter can be read or modified by accessing the special function register associated with that timer. Some of the bits in these registers are also the indicators of timer overflow, which, therefore, can generate interrupt request to the microcontroller. The use of timer modules to keep record of time elapsed allows the microcontroller to carry on with its other operations like controlling outputs, reading inputs, etc.

Timers can also have another asynchronour counter, known as pr…

Experiment No. 6: Read/Write Internal EEPROM Memory

An EEPROM (Electrically-Erasable Programmable ROM) data memory is one of the important features of flash-based PIC microcontrollers. It is called non-volatile to indicate that it retains the data even when the power is down. Practically speaking, if you want to design a digital lock system, then the password to unlock the system can be saved into the EEPROM, so that when the power is down, the password will still be saved. And other good thing is that the data can be easily modified or overwritten with software control. In this experiment, I am going to show you how to read and write in to the internal EEPROM memory of PIC16F628A using mikroC EEPROM library functions. Here is what we are going to do:

We will write 0s to 10 EEPROM locations. We will read them first, then write 0-9 to these locations, and turn the power off. We will turn the power on, and read the data in those locations and see. I have created a simple menu on LCD with Read, Write and Delete functions.

Experimental Set…

Experiment No. 5: Multiplexed Seven Segment Displays

In this experiment, we are going to learn how to interface more than one 7-segment LED display to a PIC Port using multiplexing technique. We are going to interface a 4-digit common cathode seven segment display to our PIC board. The multiplexing circuit is already built up in the board using 4 transistors and few resistors (Read Make Your Own PIC Development Board). The basic idea of multiplexing is that all seven segment displays are connected to the microcontroller in parallel and the microcontroller alternately prints ones, tens, hundreds, and thousands digits, selecting one at a time. The switching among the digits is so fast that it gives an impression of simultaneous light emission.

Experimental Setup:

1. Connect RA0 through RA3 to 7-Segment Digit Select headers DG1, DG2, DG3, and DG4 using jumper wires.
2. Insert 7FR5641AS 4-Digit Seven Segment module in to its place on the board.


Experiment No. 4 : Reading Temperature Values from DS1820 using 1-Wire Protocol

In this experiment, we are going to build a digital temperature meter using DS1820 connected to our PIC16F628A development board. The temperature value will be displayed on the LCD display. I have modified the sample program that comes with the compiler according to our PIC board requirements. Also I have elaborated comments in the program so that every step will be more clear to the readers.

Experimental Setup:
The experimental setup is very straight-forward. Place DS1820 device on the three-pin female header that we recently added to our board. And also connect the data pin of DS1820 to RB.0 pin of PIC16F628A using a jumper wire.

DS18S20 : 1-Wire Digital Thermometer and mikroC OneWire Library

Introduction
The DS18S20 is a 1-Wire digital thermometer device from MAXIM that provides 9-bit Celsius temperature measurements and communicates over a 1-Wire bus with a central microprocessor. It also has in-built alarm function with nonvolatile user-programmable upper and lower trigger points. The operating temperature range of the device is –55°C to +125°C with an accuracy of ±0.5°C over the range of –10°C to +85°C. Each DS18S20 has a unique 64-bit serial code, which allows multiple DS18S20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18S20s distributed over a large area.


The 1-Wire Communication Protocol

The 1-Wire is a registered trademark of Dallas Semiconductor Corp (now Maxim) for a serial communication protocol using a single data line and a ground reference. A 1-Wire Master (a microcontroller) initiates and controls the communication with one or more 1-Wire Slave devices (usually sensors). Each 1-Wire slave device has a unique, factory-programmed , 64-bit identifier, which serves as device address on the 1-Wire bus. This globally unique address is composed of eight bytes divided into three main sections. Starting with the LSB, the first byte stores the 8-bit family codes that identify the device type. The next six bytes store a customizable 48-bit individual address. The last byte, the most significant byte (MSB), contains a cyclic redundancy check (CRC) with a value based on the data contained in the first seven bytes. This allows the master to determine if an address was read without error. With a 248 serial number pool, conflicting or duplicate node addresses on the net are n…

Experiment No. 3: LCD Interface in 4-bit Mode

The objective of this experiment is to interface a 16x2 LCD to PIC16F628A in 4-bit mode. This means the data transfer will use only four pins of the microcontroller. There is no additional hardware setup needed for this experiment, as we have a ready-made LCD interface female header. We only need to define the data transfer and control pins in the software. Remember, the LCD interface in our development board uses the following pins of PIC16F628A: Data Transfer : D4 -> RB4, D5 -> RB5, D6 -> RB6, D7 -> RB7 RS -> RA0, and EN -> RA1

About PIC16F628A

PIC16F628A is a powerful (200 nanosecond instruction execution) yet easy-to-program (only 35 single word instructions) CMOS FLASH-based 8-bit microcontroller from Microchip. It comes into an 18-pin package and is upwards compatible with the PIC16F628, PIC16C62XA, PIC16C5X and PIC12CXXX devices.

Experiment No. 2 : Push Button and Seven Segment Display Interface

In this experiment, we will program the PIC16F628A as an UP/DOWN Decade Counter. The count value will be displayed on a Seven-Segment Display and will be incremented/decremented by two push buttons on the board.

Experimental Setup:
The board has built in interface for a multiplexed 4-digit seven segment display (HS-5461AS2 from www.futurlec.com).We will select only one digit by connecting a Digit Select pin to Vcc, as shown in figure below. A black jumper wire is used for this purpose. The seven segments will be driven through PORTB (already wired on the board). Connect Push Buttons (PB3 and PB4) to RA1 and RA0 female headers using jumper wires.


PIC microcontrollers: Nebojsa Matic (Free Online Book)

If you are a beginner to PIC microcontroller, I would recommend you to read this free e-book on PIC16F84 microcontroller. PIC16F84 is one of the most popular PIC family microcontrollers that resembles very much with PIC16F628A.
In this book you will find:
Introduction to microcontrollers Learn what they are, how they work, and how they can be helpful in your work.Practical connection samples for  Relays, Optocouplers, LCD's, Keys, Digits, A to D Converters, Serial communication etc.How to write your first program, use of macros, addressing modes...Instruction Set Description, sample and purpose for using each instruction...MPLAB program package How to install it, how to start the first program, following the program step by step in the simulator...

Ready to read now? Click Here

Experiment No. 1 : 4-Bit Binary Counter

Experimental Setup:
The first experiment that we are going to do with our PIC16F628A board is a 4-bit binary counter that counts from 0(00h) to 15(0Fh) with 1sec delay between each count. The output will be at RB.0 through RB.3 and will be displayed on 4 LEDs. Use four jumper wires to connect RB.0 through RB.3 to LEDs. The picture below shows these connections.


Figure 1. Jumper Connections for a 4-bit Binary Counter

PIC16F628A Development Board

The development board we are going to make for our experimental microcontroller PIC16F628A will look like this. Here are the features it is going to have:
Access to all I/O pins through female header pins4 Push Buttons for Input4 LEDs for OutputAn LCD Interface PortA 4-digit Seven-Segment Display InterfaceLCD Backlight Switch and Contrast AdjustmentICSP Programming (Very Important)

Why use the PIC?

Source:PICmicro MCU C : An introduction to programming the Microchip PIC in CCS C by Nigel Gardner