You are on page 1of 5


Upon the completion of this lab, you should be able to:
 Connect the PORTB of PIC to LED board.
 Use the OUTPUT instruction and be familiar to the environment of Flowcode
 Configure the correct settings for the target PIC.
 Design a simple program for PIC.
 Simulate the program.
 Compile and download the program to PIC.
 Test the program loaded in the PIC.
 Multichip Programmer
 USB cable
 AC adapter
 LED board
 PC
 PIC16F84A
 Flowcode
The PIC16F84A belongs to a class of 8 bit microcontrollers of RISC architecture.
It has ROM, RAM, EEPROM, Flash memory and two ports namely PORTA which has 5
pins (RA0RA4) and PORTB has 8 pins (RB0RB8). These ports are configurable as
input or output which means there are 13 input/output ports. They are used to interface
to different electronic devices such as LEDs, switches, motors, sensors, LCDs and
The basic PIC microcontroller circuit requires an oscillator and an optional reset
button. An oscillator is necessary for the PIC to work properly because it is the one that
provides the clock pulse and determines how fast the microcontroller will execute the
program loaded to its memory. Resistor-Capacitor (RC), Crystal and Resonator
oscillators are types of oscillators that can be used for PIC micros. The crystal oscillator
is the commonly used which ranges from 4MHz to 20MHz.
LEDs with current limiting resistors are connected to microcontroller in two ways.
One is to switch them on with logic zero, and the other using logic one. The value of
resistor is determined by the amount of current that can flow to the LED. The maximum
current flow through the LED is set by the manufacturer.
1. Set up the Hardware.

Place the PIC16F84A to Multichip Programmer.
Plug-in and connect the AC adapter to Multipchip Programmer.
Connect the Programmer and PC using the USB cable.
Set the clock setting to crystal oscillator (XTAL).
Attach the LED board to PORTB of PIC as shown in the picture.

Page 1 of 5

click ChipConfigure… Select XTAL as the oscillator and set Watchdog timer to OFF. This opens the 'Specify Component Pin Connections' dialogue box. Create a new flowchart by selecting FileNew.. Select the PIC16F84A microcontroller as the target from the list. It looks like this: Click once on the icon. Connect LEDs to PIC microcontroller virtually. Move the cursor over the LED icon in the Components toolbar.   Open the Flowcode Software. Then click once on the 'Components Connections. like the one shown below. Configure clock and watchdog timer settings. Page 2 of 5 . If the microcontroller is not shown.' option on the menu. and which bit of the port on the PICmicro chip.   On menu bar. 4. Click once on the button. Set up the Software.. click ViewChip 3. A set of LED's appears in the main window.  Flowcode will then display the microcontroller in the Microcontroller view and create an empty flowchart. This shows which LED is connected to which port.2.

5. and choosing the 'Properties' option. Move the cursor over the Output icon. You will now see a dialogue box like this:  Move the cursor over the 0 in the Variable or value box and click once. All flowcharts have these icons.    Click on the arrow by the ' Connect to Port' dialogue box.  Move the cursor over the Output box. Choose Properties from the menu that appears. an arrow appears showing you where the Output box will end up. Place an “Output icon” in the flowchart. and select the color you want. This will highlight the '0'. Page 3 of 5 . Then click the 'OK' button to close the dialogue box. Move it in between the BEGIN and END boxes. Release the mouse button to drop the Output box in between the BEGIN and END boxes. You will now see your flowchart appears with a BEGIN and END icon. The following dialogue box opens: Click on the arrow at the end of the 'LED Color' box. in the Icon toolbar. and select the PORTB option in the menu that you see. and click with the right mouse button. You can change the color of the LED's by clicking on the button on the LED display. by clicking once on it with the left mouse button. As you get close to the flowchart. Click on the 'Done' button to close the dialogue box. The normal cursor changes into a tiny copy of the icon. and click and drag it over the work area. Notice that the settings for 'PIC Port' and 'PIC Bit' change for all eight LED's. Now type a number 1 on the computer keyboard to change the value to a 1.

6. If you select the Step into icon on the menu toolbar then you will see that Flowcode will step through your program icon by icon. Page 4 of 5 . and there is a message saying that the simulation is completed. To transfer your program to PICmicro. The result is that the first LED lights. the blue arrow on the main toolbar. Move the cursor over the arrow in the Port window. Once done. Click on the 'Run' icon. Fortunately Flowcode has a feature you can use to step through your program icon by icon. But to debug your programs you will need a way of slowing the simulation down. The Run icon looks like this: or press F5. Simulate the program. Click on Port B in the menu that opens up. This will slow your program down and you will be able to see the effects on your virtual system of each icon. The dialogue box now looks like the one below. click ChipCompile to Chip. You will see the actual output on the LED board. A window appears and shows the compiling and downloading process. Compile and download your program to PICmicro.  Now click on the 'OK' button to close the box. When you pressed the 'play' button the program was over in a flash. This is one of the great things about microcontrollers: they work really fast. If the Multichip Programmer is properly connected. you need to save first the program by clicking the menu FileSave or by pressing Ctrl+S in your keyboard. it should be successful. In later programs you will learn to slow microcontrollers down with delays or loops so that they go at the speed that humans can cope with. As you step through the program you will see a red rectangle around each icon: this indicates which icon will be executed next time you click on the 'Step into' icon as you can see here: 7.

8. Repeat Step 5 to 7 You can also use Hexadecimal number preceded by 0x. Use a single output icon that lights all of the LED's of Port B. Alter the icon parameters so it puts only the odd LEDs of PortB 'on' Now put only the even LEDs of PortB 'on'. 0xCD g. Now put the High nibble (bits 4 to 7) of Port B 'on' Put only the LED on PB7 'on' by sending an 8-bit value to this port. 6. the reset circuit. Draw up the full circuit diagram of the PIC with 8 LEDs on port B. Write a program with at least 20 Outputs icons that writes a pattern of different values to port B. 4. 15 d. For example 45H is equivalent to 0b01000101 in Binary. 57 b. 5. one after the other. To input 45H. VDD and VSS connected to the PIC and the correct current limiting resistors connected between LED and PIC. Page 5 of 5 . and review what the result is in simulation. For Binary numbers. Modify the value of set in the Output icon into the following: a. 7. 0x1F i. 0xA1 What’s the actual output? Which LEDs are ON? Which LEDs are OFF? Why? Supplemental Activities The program should be downloaded to the PIC for verification and checking. 1. 150 e. precede it with 0b followed by 8 bit binary number. enter 0x45. 3. 0x35 j. 200 f. 2. 36 c. 0xAD h. including the clocking circuit.