0% found this document useful (0 votes)
316 views22 pages

PICME User Guide PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
316 views22 pages

PICME User Guide PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

USER MANUAL

Copyright 2008
Advance Science & Technology Institute
Department of Science & Technology Institute
CP Garcia, U.P. Techno Park, Q.C
Philippines, 1101

PICMe™ ASTI-DOST
TABLE OF CONTENTS

Introduction . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . ... 3

PICMe™ Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Product Features .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Package Contents . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . 5

Board Lay-Out . . . . . . . . . . . . .. . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . 6

Components and Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Hardware Set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Using the PICMe™ DSM.. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 8

Using the PIC Downloader. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Using the PICMe™ Serial Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . 10

C Compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Using the CCS Compiler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

CCS Sample Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Using MPLAB Assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

MPLAB Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

PICMe™ ASTI-DOST
INTRODUCTION

A microcontroller unit (MCU) or most commonly called as a microcontroller is a computer


implemented on a single chip. Just like desktop and mainframe computers, the
microcontroller also contains the basic components that these computers have such as the
Central Processing Unit (CPU), Random Access Memory (RAM) and input/output (I/O)
devices. However, microcontrollers are special purpose computers whose dedication is to
perform one task at a time, unlike a desktop computer that can do several tasks
simultaneously.

Microcontrollers are low-powered devices that are usually used by embedding them into other
products or devices so that they can control the actions that these devices will do. It takes
input from the device that it controls and also sends signals to it to manipulate its actions. A
microcontroller needs to be programmed before it can be used to control devices.

Unlike a microprocessor that generally requires external components to implement a


program, a microcontroller already incorporates all the resources needed internally in a single
chip. Microcontrollers are usually designed to perform a small set of specific functions,
whereas microprocessors tend to be designed to perform a wider set of general purpose
functions just like the functions that are performed in a personal computer (PC).

The PICMe™ Microcontroller Starter Kit is a solution of the Advanced Science and
Technology Institute (ASTI) of the Department of Science and Technology (DOST) designed
to provide students, engineers and hobbyists with a low cost tool to explore the power of a
MCU and jumpstart their prototyping and product development projects on embedded
systems.

The PICMe™ Microcontroller Starter Kit package includes the Microchip MPLAB® IDE v7.xx
(Compiler/Assembler) which will be used in programming the PICMe™ microcontroller. In this
User Manual, you will be introduced to the programming language C to program the PIC to
perform some fairly simple tasks. The package also includes the PICMe™ DSM (Downloader
and Serial Monitor) a software program that easily downloads the code compiled in the PIC
Compiler directly into the MCU and also serves as a communication tool between the MCU
and PC.

This User Manual contains guides in using the hardware and software materials needed in
using the kit. It also includes instructions on how to install and use the MPLAB as a compiler
and assembler plus examples and sample exercises to help the user understand the
applications of the product.

PICMe™ ASTI-DOST
PICMe™ OVERVIEW

A.PRODUCT FEATURES

The PICMe™ Microcontroller Starter Kit is designed to give electronic enthusiasts an initial
application material in their prototyping and laboratory needs. The board supports the
PIC16F877A in the 40-pin DIP package. These controllers have a program memory built on
Flash technology which provides fast erasing and reprogramming, thus allowing a quick
debugging or error checking. The PICMe™ Microcontroller Starter Kit has the following main
features:

Powerful MCU
10-bit, 8-channel Analog-to-Digital (A/D) Converter.
Synchronous Serial Port (SSP) with SPI™ (Master mode) and I2C™ (Master/Slave mode)
Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address
Up to 8K x 14 words of Flash Program Memory, up to 368 x 8 bytes of Data Memory (RAM),
up to 256 x 8 bytes of EEPROM Data Memory Has 33 input/output (I/O) pins.

Pocket Size
The PICMe™ Microcontroller board has a compact size of 3.7” x 1.65” that includes all the
electronic components used Dual Function Header. The I/O pins can be accessed easily via
the dual function headers, which can act as sockets or pins that can be mounted on a
breadboard or on any prototyping board.

Ease of Reprogramming
No external programmer is required for the boot loader. The PICMe™ Microcontroller Starter
Kit has a pre-installed PIC boot loader located in the PIC's memory area. The PIC boot loader
initializes the system to enable reprogramming of PIC microcontrollers without the need for a
chip programmer, a device used to transfer the compiled program from the computer into the
microcontroller memory. It utilizes the self-programming features of the PIC microcontroller,
which allows in-circuit reprogramming and downloading of codes.

PICMe™ ASTI-DOST
B. PACKAGE CONTENTS

The PICMe™ Microcontroller Starter Kit should contain the following materials:

a. PICMe™ Microcontroller Board with PIC16F877A Microcontroller

b. CD containing the software tools, sample program codes and support documentations

c. Serial cable (RS-232 data cable)

d. AC-DC power supply adapter (optional)

e. Portable case

PICMe™ ASTI-DOST
C.BOARD LAY OUT

RJ 11-SERIAL
DC POWER
JACK
POWER SWITCH
POWER INDICATOR

RS232 CHIP
RESET SWITCH

ICD 2 PIC16F877

PORT A
PORT B

PORT E
2 PIN
POTENTIOMETER

SWITCH 1
PORT D
PORT C

SWITCH 2 JUMPER HEADER

LED DISPLAY

Figure 2. PICMe™ Starter Kit board layout

PICMe™ ASTI-DOST
D. COMPONENTS & DESCRIPTIONS

PIC16F877A Has up to 8Kx14 words of In-System Programmable Flash memory with up to 256x8 bytes of EEPROM
and up to 368x8 bytes of Internal RAM

RJ11 Serial Input Interfaced on board through a RS232 driver/receiver pin-compatible level converter chip. Flash PIC
microcontroller units like the one in the development kit can be programmed by connecting it to RS232
in the appropriate COM port of the computer and using the provided boot loader application.
DC power jack (J2) Used to connected to the power adapter and interfaced with an on-board regulator
Power Regulator (U3) Allows power inputs from 100-240V to an output of 12V (1.0A) towards the board
Red LED (D10) Connected to the power regulator, which indicates if the power is on
Potentiometer (POT) A 5k trimmer resistor to control an analog signal input interfaced on thPin 2 (PIN A0) of the PIC6F877A
microchip.
Reset Switch Attached to the Master Clear/Reset Input or Pin 1 of the PIC microcontroller

Push-Button Switch 1 Connected to Pin 32 (PIN B0) of the microcontroller and used for handling interrupts
(SW1)
Push-Button Switch 2 Connected to Pin 8 (PIN E0) of the microcontroller and used for making control inputs
(SW2)
Jumper Header (J3) If the header is shorted or the Jumper is inserted, then the PIC microcontroller can output signals to the
yellow LEDs. Otherwise, Port D is open as parallel slave port for external interfacing.

2-Pin Header (J4) Provided by the power regulator with +5V DC output at 250mA and GND

6-Pin Header (Port A) A bidirectional I/O port connected to Pin 2 (PIN A0) to Pin 7 (PIN A5) of the microcontroller. PIN A0 is an
analog input interfaced with the potentiometer While the other pins can be interfaced with other analog
inputs and as well with clock/timer.

8-Pin Header (Port B) A bidirectional I/O port connected to Pin 33 (PIN B0) to Pin 40 (PIN B7) of the microcontroller. PIN B0 is
connected to Push-button Switch 1 (SW1) to test its capability to handle interrupts. While the rest of the
pins can be accessed as interrupt-on-change pins or in-circuit debugger pins.

8-Pin Header (Port C) A bi-directional port connected from Pins 15,16,17,18, 23 and 24 (PIN C0 to PIN C5) of the
microcontroller respectively. Pin 25 (PIN C6) and Pin 26 (PIN C7) are used for USART Asynchronous
Transmit and Receive respectively. These two pins are currently dedicated and set-up for the Starter Kit
and Computer serial communication such as the downloader and HyperTeminal.
8-Pin Header (Port D) Also a bidirectional port interfaced to the 8 yellow LEDs and a jumper header. This port is either used for
outputting values on the LEDs or as parallel slave port.

3-Pin Header (Port E) Pin 8 (PIN E0) is connected to Push-button Switch 2 (SW2) which “read” control inputs, while Pin 9 (PIN
E1) and Pin 10 (PIN E2) are defined as “control” and “select” controls. These three pins can also be
used as parallel slave port or analog inputs.

8 Yellow LEDs All of which are I/O controlled by Port D and are jumper selectable
XTAL A 20 MHz crystal located on the clock socket under the PIC16F877A microchip and is used as the
external clock of the microcontroller
100 Mils (0.1”) centered Provide a more accessible or simple connection to the processor special function pins and I/O
headers
ICD2 Pins for In Circuit Debugger

PICMe™ ASTI-DOST
GETTING STARTED

A. HARDWARE SETUP

Figure 3. PICMe™ Starter Kit Hardware Setup

B. USING PICMe™ DSM

The PICMe™ DSM (Downloader and Serial Monitor) is a software program that can be used
to easily download the code compiled in the PIC Compiler directly into the MCU and also
serves as a communication tool between the MCU and PC.

System Installation

• Look for the folder PICDSM Setup and copy it from the CD onto your PC.
• Click setup icon and this will display the PICMe™ DSM window.

PICMe™ ASTI-DOST
C. Using the PIC Downloader

1. Run the program PICDSM.exe. Select the Downloader tab.

2. Locate the desired HEX file through the Browse button.

3. Set the Port number. The default setting of the Port is COM1.

4. Set the Baud Rate to 57600.

C:\Documents and Settings\admin\Desktop\test.HEX

5. Click the Download button to start downloading the file. Click Cancel button if you want to
stop the activity.

PICMe™ ASTI-DOST
D. Using the PICMe™ Serial Monitor

1. Run the program PICDSMv1.exe. Select the Serial Monitor tab.

2. Set the correct Port settings before attempting to connect with the serial communication
port of the device. The default setting of the Port is COM1. Set the Baud Rate at which data is
being sent. The baud rate setting of the Serial Monitor must match the baud bate setting of
the device which is set by the program. Set the Parity, Data Bits, Stop Bits, and Handshaking
method accordingly to match the requirements of the device. The default values are none, 8,
1 and none respectively.

PICMe™ ASTI-DOST
3. Click the Connect/Disconnect button to connect/disconnect to the device.

4. In the Receive area, check the desired format (ASCII or HEX format) of the received data.
The Clear button is used to clear the window.

5. In the Transmit area, enter the specific data to be sent. Check the As HEX tab when
sending HEX-formatted data.

6. Click the Send button to transmit the data to the microcontroller.

PICMe™ ASTI-DOST
C COMPILERS

The C software/compiler is a common choice of programming most microcontrollers. The C


Language is a human-level language that can be used to control hardware activities without
thinking much of the tiniest details. It also features predefined functions contained in built-in
libraries that can just be simply embedded in a program. Although it takes more memory
space than the assembly language, it takes lesser memory space than other human-level
programming languages. Below is a list of the links to some of the websites that offer free C
Compiler software.

CCS Compilers
The CCS Compiler supports 12-bit, 14-bit and 16-bit PICs. The compiler has a generous
library of built-in functions, preprocessor commands, and ready-to-run example programs to
quickly jump-start any project. Drivers for real-time clocks, LCDs, A/D converters, and many
more are innate features to the CCS C Compiler. The latest software (full version and demo
version) can be downloaded via the Internet at: http://www.ccsinfo.com/downloads.php.

The Hi-Tech Compiler


HI-TECH PICC is the leading C compiler for the Microchip PICmicro 10/12/14/16/17 series of
microcontrollers. A free 45 day evaluation software which runs on multiple platforms
(Windows®, Linux®, UNIX®, Mac OS X†, Solaris™) is available in the developer's website
http://www.htsoft.com.

BoostC Compiler
The BoostC compiler works with PIC16, PIC18 and some PIC12 processors. This ANSI C
compatible compiler supports features like source level symbolic debugging, signed data
types, structures/unions and pointers. The BoostC compiler can be used within its own IDE
(Integrated Development Environment), or it can be integrated into Microchip MPLAB. Aside
from the free demo version of the BoostC Compiler, the developer's website
http://www.sourceboost.com also offers C++, Basic and Pascal Compilers

CC5X C Compiler
This compiler supports mid-range PICmicro devices including the PIC16F877A
microcontroller used in the PICMe™ Microcontroller Starter Kit. The CC5X compiler is
available as a 16 or 32 bit application (MSDOS command line or WIN32 console application)
and requires Windows 95 or higher. The free edition from
http://www.bknd.com/cc5x/download.shtml supports up to 1024 instructions in any single C
module but has a 1k code limit. The generated code is compact, but full optimization is not
available. Moreover, support is not available to users of the free edition.

PICMe™ ASTI-DOST
SDCC-Small Device C Compiler
SDCC (available at http://sourceforge.net ) is an open source retargettable, optimizing ANSI -
C compiler. The current version targets the Intel 8051, Zilog Z80, Dallas 80C390, Motorola
HC08 and Microchip PIC MCUs. Linux - x86, Microsoft Windows - x86 and Mac OS x - ppc
are the primary, so called "officially supported" platforms.

Due to license restrictions, the C Compiler software that is used to program the PIC
microcontroller cannot be distributed. However, there are several C Compiler software
available from the Internet that can be downloaded for free. Hence, we leave it up to you to
obtain a copy of the software and learn how to use it.

PICMe™ ASTI-DOST
USING CCS COMPILER

1. Run the compiler by opening pcw.exe.


2. Create a new file and save it as blinker.c.

3. Enter the C program below onto the source code template window.(CCS Sample
Program)

PICMe™ ASTI-DOST
4. Run the program: Compile->Build All -> Compile

5. Locate for the blinker.hex

PICMe™ ASTI-DOST
CCS SAMPLE PROGRAM

1. LED SWITCH ON & OFF

#include <16F877A.h> //Initialization


#include <string.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock=20000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)

void main()
{ //Start of Main Program
int8 a=0x00; //Set variable a to 0
delay_ms(500);
printf ("\nIf you can read this message,");
printf (" you are using the PICMe Starter Kit properly!\n"); //Confirmation

while (1) { start of main loop


output_d(0x00); //Turn off LEDs
delay_ms(500); //for 0.5sec
output_d(a); //Turn on LEDs
delay_ms(500); //for 0.5s

if (!input(PIN_B0)) //if SW1 is pressed for a while


{
printf("\n value of a: %X\n",a); //display value of a in hex format
}

while(!input(PIN_B0)); //stop while SW1 is pressed


{a++; //Increment a}

if(a>=0xFF)
{a=0;}

}// end of main loop


} //End of program

PICMe™ ASTI-DOST
ASSEMBLER

A program written in assembly language consists of a series of instructions in mnemonic


formats (symbolic) correspond to a stream of executable code, which can be loaded into
memory after translated by an assembler,

ASSEMBLER creates object code by translating assembly instruction mnemonics into


opcodes, and by resolving symbolic names for memory locations and other entities. The use
of symbolic references is a key feature of assemblers, saving tedious calculations and manual
address updates after program modifications. Most assemblers also include macro facilities
for performing textual substitution; one example, to generate common short sequences of
instructions to run inline, instead of in a subroutine. Modern assemblers, especially for RISC
based architectures, such as MIPS, Sun SPARC and HP PA-RISC, optimize instruction
scheduling to exploit the CPU pipeline efficiently. . Below are the lists assemblers

MPLAB® IDE is a Windows Operating System-based Integrated Development Environment


for the PICmicro® MCU families and dsPICTM Digital Signal Controllers. MPLAB® IDE is a
comprehensive editor, project manager and design desktop for application development of
embedded designs using Microchip PIC microcontrollers. It is the software developed by
Microchip, the manufacturer of PIC microcontrollers, to program the PIC microcontrollers
using assembly language. The MPASM assembler, the MPLINK object linker and the MPLIB
object librarian are typically used together under MPLAB IDE to provide GUI development of
application code for PICmicro MCU devices. The operation of these PICmicro MCU language
tools with MPLAB IDE is discussed here.

ASEM-51 is a two-pass macro assembler for the Intel MCS-51 family of microcontrollers. It is
running on the PC under MS-DOS, Windows and Linux. The ASEM-51 assembly language is
based on the standard Intel syntax, and implements conditional assembly, macros, and
includes file processing. The assembler can output object code in Intel-HEX or Intel OMF-51
format as well as a detailed list file. The ASEM-51 package includes support for more than
180 8051 derivatives, a bootstrap program for MCS-51 target boards, and documentation in
ASCII and HTML format

GPUTILS is a collection of tools for the Microchip (TM) PIC microcontrollers. It includes
gpasm, gplink, and gplib. It's distributed under the terms of the GNU Public License. See the
gnupic page for other GNU PIC tools such as gpsim, a gputils compatible simulator. Linux
(and other unices), Mac OS X, and MS-Windows are supported. GPUTILS will compile
natively on Linux using gcc. Mac OS X users will need the December 2001 Developer Tools.

PICMe™ ASTI-DOST
Windows 98/NT users will need MinGW32 if they wish to compile the tools.

Picasm114 is a freeware (free download) assembler and disassembler for 12 and 14-bit PIC
microcontroller chips. The Picasm114 assembler is written in (mostly) ANSI-C, and it is single
pass, so there are restrictions in forward references. It can output IHX16 and IHX8M formats.
Include files, macros and conditional assemblies are supported. Picasm 1.14 is now available.
Download here: picasm114.tar.bz2. Documentation is here: picasm114.html. In this version,
new PIC types can be defined in special includes files, without recompiling Picasm114. The
installation requires the include files to be manually copied to the correct directory, specified
in the Makefile (No automatic installation yet).

GNUPIC gputils is free software; it can be freely redistribute and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2, or (at your option) any later version. The GNUPIC utilities project gputils, contains
many things among which is gpasm, an open source replacement for Microchip's MPASM
(here's the MPASM manual). The source for gpasm may also be found on the gputils
sourceforge page which is hosted by Source Forge.

PICMe™ ASTI-DOST
USING MPLAB ASSEMBLER

MPLAB IDE allows the user to:

1. Open an MPLAB editor

2. Create a new file in File -> New.

3. Type the following code on the text editor window of MPLAB IDE

4. Save the new file as lightson.asm.

5. Create a new project in Project -> New. Name it and select its directory according to your
own preference.

PICMe™ ASTI-DOST
6.Add the lightson.asm to the current project by right-clicking on the Source File folder located
at the project window.

7. Select the Microchip MPASM Tool suite in Project -> Select Language Tool suite.

PICMe™ ASTI-DOST
8. Build the program by selecting the Project -> Build All.

9. Locate the lightson.hex file on the same directory that the lightson.asm is and open it using
a text editor.

10.Delete the first line (:020000040000FA) and save.

11.Finally, download the lightson.hex file in the PIC16F877A using the PICMe™ DSM.

PICMe™ ASTI-DOST
MPLAB SAMPLE PROGRAM

1. LED SWITCH ON & OFF

LIST p=16F877A

#include p16f877a.inc ;include file with config bit definitions

__config 0x3F3A;_XT_OSC & _WDT_OFF & _LVP_OFF ;Set oscillator to HS,


;watchdog time off,
;low-voltage prog. off

STATUS equ 0x03 ; assign register addresses


PORTD equ 0x08
TRISD equ 0x88

org 0x03 ;load program starting at memory address 0x03

movlw 0x00 ;set-up program counter


movwf 0xA
goto INIT
nop

INIT clrf 0x04 ; clear indirect addressing register

START bsf STATUS, 5 ; select Bank 1


clrf TRISD ;set Port D to output
bcf STATUS, 5 ;select Bank 0
movlw 0xff
movwf PORTD ;output 0xff to Port D
goto START ;continuous loop
sleep
end ;end of program

PICMe™ ASTI-DOST

You might also like