Archive for January, 2011

January 25th, 2011

Embedded C Programming and the Microchip PIC

The Reference Book: Embedded C Programming and the Microchip PIC by Barnett, Cox and O’Cull

This book is a good guide for introducing the microcontroller technology. First chapter is dedicated to teaching basic C programming however, this book shouldn’t be considered a C programming handbook. One should always have a book like: Teach yourself C by Zhang ISBN 0-672-31861 as a C programming reference guide for beginners.

This book is designed to teach C language programming as it applies to embedded microcontrollers and to fuel knowledge in the application of the Microchip family of PIC microcontrollers. Coverage begins with a step-by-step exploration of the C language showing readers how to create C language programs to solve problems. PIC processors are then studied, from basic architecture to all of the standard peripheral devices included in the microcontrollers. Numerous worked-out example programs demonstrate common uses for each of the peripherals. Readers are subsequently introduced to the built-in functions available in C, to speed their programming and problem solving. Finally, readers are taken through use of the C Compiler, and to help custom learn to efficiently develop projects.

Included with the book is a CDROM containing samples all of the example programs from the book as well as an evaluation version of the CCS-PICC Compiler.

Author`s note 01/22/04 : In the first examples and projects in chapter 1, functions like “scanf” and “printf” are used that require prior knowledge to interface the board through RS-232 which is introduced in the late chapters of the book. It might be discouraging for the student not being able to do the first project of the book, hands-on. Although I was able to find answers to most of my questions about using the C compiler and the hardware however, I had to do a lot of skipping between chapters and Appendixes to find these answers which was time consuming. In general it is a nice and descriptive text book.
Beginner’s guide to the popular PIC Microcontroller.

Get all the advantages of the Basic Stamp, at one quarterthe cost and one hundred times the speed with Microchips Company’s 8-bit PIC computer-on-a-chip.

The no assembly required PIC Microcontroller Project Book, by popular TAB author John Iovine, shows you how to program the PIC using Microchip’s free MPLAB compiler and the BASIC programming language.

Learn about the two most popular PIC chips, exploring architecture, registers, CPU, RISC, RAM, and ROM.

microchip pic ebook download,microchip pic richard h barnett,microcontroller programming the microchip pic download,embedded c programming and the atmel avr,books microchip,pic ccs book,embedded c programming microchip pic download,
Microcontroller programming: the microchip PIC By Julio Sanchez, Maria P. Canton

Book overview

From cell phones and television remote controls to automobile engines and spacecraft, microcontrollers are everywhere. Programming these prolific devices is a much more involved and integrated task than it is for general-purpose microprocessors; microcontroller programmers must be fluent in application development, systems programming, and I/O operation as well as memory management and system timing.Using the popular and pervasive mid-range 8-bit Microchip PIC® as an archetype, Microcontroller Programming offers a self-contained presentation of the multidisciplinary tools needed to design and implement modern embedded systems and microcontrollers. The authors begin with basic electronics, number systems, and data concepts followed by digital logic, arithmetic, conversions, circuits, and circuit components to build a firm background in the computer science and electronics fundamentals involved in programming microcontrollers.For the remainder of the book, they focus on PIC architecture and programming tools and work systematically through programming various functions, modules, and devices. Helpful appendices supply the full mid-range PIC instruction set as well as additional programming solutions, a guide to resistor color codes, and a concise method for building custom circuit boards.Providing just the right mix of theory and practical guidance, Microcontroller Programming: The Microchip PIC® is the ideal tool for any amateur or professional designing and implementing stand-alone systems for a wide variety of applications.

PIC 16F877, 18F452 and 18F4550,PIC16F877, PIC18F452,PIC18F4550,16f876,16f84,microcontroller projects,lm35,lm34,lm335,temperature sensor,MikroC Projects


January 25th, 2011

ICD-S Debugger and Programmer

The ICD-S programmer is the hardware/firmware interface to burn the .hex files to the Microchip PIC. The ICD unit works with CCS’s PCW debugger or CCS’s stand-alone ICD control software. CCS’s PCW debugger is a very robust debugger integrated with PCW, and provides very detailed debugging information at the C level. The stand-alone control software allows you to quickly program target chips using ICD’s ICSP. The control software also lets you update the ICD unit’s firmware without having to remove the chip from the ICD unit. (Using these software tools requires you to have loaded the CCS-ICD firmware onto the ICD unit, which is loaded by default).

Authors note 01/22/04 : I found it odd that prllc.com does not provide a freeware program like “AVR bootloader.exe” for FlashPIC Development board as they do for Atmel AVR development board, that would enable programming the chip via serial communication connector P1 in-built to the development board. I don`t think that Development board and Compiler vendors should force the costumers to buy products like ICD-S where an option like programming via serial link exists. I have seen a program in http://sjeffroy.free.fr/Prog__PIC/BootLoader/bootloader.html which seems like it might work given the fact that bootloader file “loader.hex” pre-exists on the chip. Personally, I did not try running this program and programming the chip via RS-232.

For an ICD-S to function properly, it requires +3.3V or +5.0V of power and at least 50mA. If the ICD-S cannot draw power from the target device, the connection between pin 5 on the ICD-S and pin 2 on the target device can be cut, and the ICD-S can be powered with an external power supply. This same technique can be used to supply voltage to the target board as well as the ICD-S.

Unlike the ICD-S, the ICD-U draws its power directly from the USB port. However, the connection between pin 5 on the ICD-U and pin 2 on the target device should be left intact. One reason for this is because the ICD-U uses this connection to pull up voltage values. Another reason is because the ICD-U is capable of supplying +3.3V or +5.0V to the target board. This can be done by opening the case of the ICD-U and placing a jumper on the correct jumper pins next to the ICD connector.
In order to use in-circuit programming and debugging, the I/O pins B6 and B7 are reserved on the PIC® MCU or PIC® DSC. If debugging is not going to be used on the target device, pins B6 and B7 can be used in the target circuit. If pins B6 and B7 are used in the target circuit, ensure the circuit has high impedance during the programming process. However, some PIC® MCUs or PIC® DSCs do not use pins B6 and B7 for programming and debugging. Always check the datasheet to find the proper programming and debugging pins. The table below lists some of the PIC® MCUs that use different programming pins.
Pin B3 is an optional pin connected to the ICD-S/U that allows use of the monitor feature while debugging. If pin B3 is used in the target circuit or is not connected to the ICD-S/U, the target can still be programmed and debugged, except without use of the monitor feature. When debugging, disabling the userstream feature will ignore the connection between pin 1 on the ICD-S/U and pin 6 on the target device. Older versions of the debugger software require that if the monitor is not used, the pin connection on the ICD connector needs to be pulled high at all times. While pin B3 is recommended for the monitor feature, any pin on a PIC® MCU or PIC® DSC can support this feature.

The MCLR pin is used for both programming and debugging. While programming, the MCLR pin will have +13V supplied to it, or +5.0V while programming a PIC18J® MCU, PIC24® MCU, or dsPIC® DSC. The 47K resistor to +5.0V is sufficient isolation to protect the PIC® MCU or PIC® DSC from the +13V. However, if anything else is connected to the MCLR pin, be sure the +13V will not damage or interfere with the connected device.

The ICD-S/U is not capable of programming using the Low Voltage Programming mode. Programs being written to the target devices should have the NOLVP fuse set.

If using the ICD-S/U to debug a target device, the target device needs to have an active oscillator running. If the ICD-S/U is only being used to program a target device, the ICD-S/U generates a clock signal that is used to program the PIC® MCU or PIC® DSC without the need of a running oscillator.

Some PIC® MCUs are not capable of debugging with the standard version of the part. In order to debug, a specific ICD version of the chip will be needed. The table below lists some of the PIC® MCUs that require ICD Headers.
ICD is a complete in-circuit debugging solution for Microchip’s PIC16Fxx and PIC18Fxx PIC® microcontrollers. ICD can debug all PIC16 and PIC18 targets that support debug mode for debugging. It also provides in-circuit serial programming (ICSP) support for all flash chips.)

Device PIC12F629 PIC12F675 PIC16F72 PIC16F73 PIC16F74 PIC16F76 PIC16F77 PIC16F83 PIC16F84 PIC16F84A PIC16LF84A PIC16F627 PIC16F627A PIC16F628 PIC16F628A PIC16F630 PIC16F648A PIC16F676 PIC16F818 PIC16F819 PIC16F870 PIC16F871 PIC16F872 PIC16F873 PIC16F873A PIC16F874 PIC16F874A PIC16F876 PIC16F876A PIC16F877 PIC16F877A PIC18F242 PIC18F248 PIC18F252 PIC18F258 PIC18F442 PIC18F448 PIC18F452 PIC18F458 PIC18C601 PIC18C801 PIC18F1220 PIC18F1320 PIC18F2220 PIC18F2320 PIC18F4220 PIC18F4320 PIC18F6520 PIC18F6585 PIC18F6620 PIC18F6680 PIC18F6720 PIC18F8520 PIC18F8585 PIC18F8620 PIC18F8680 PIC18F8720


January 25th, 2011

CCS PIC-C compiler

The CCS PCW compiler is specially designed to meet the special needs of the PICmicro MCU controllers. These tools allow developers to quickly design application software for these controllers in a highly readable, high-level language.

The compilers has some limitations when compared to a more traditional C compiler. The hardware limitations make many traditional C compilers ineffective. As an example of the limitations, the compilers will not permit pointers to constant arrays. This is due to the separate code/data segments in the PICmicro MCU hardware and the inability to treat ROM areas as data. On the other hand, the compilers have knowledge about the hardware limitations and do the work of deciding how to best implement your algorithms. The compilers can efficiently implement normal C constructs, input/output operations and bit twiddling operations.
The compiler can output 8 bit hex, 16 bit hex, and binary files. Two listing formats are available. Standard format resembles the Microchip tools and may be required by some third-party tools. The simple format is easier to read. The debug file may either be a Microchip .COD file or Advanced Transdata .MAP file.

All file formats and extensions are selected via the Options|File Formats menu option in the Windows IDE. 
The usage of the copiler is explained in Section 2.0 Getting started. The reference book “Embedded C Programming and the Microchip PIC” comes with a demo version of the compiler.
Write a C source program, compile, and download the HEX code to the chip directly, connect DC adapter and debug the program until it works to the designed objective.
While it is true that C compilers may generate less efficient code from a quickly written line of C than a human working in hand coded / hand optimized assembly, in most cases, well written C compilers can come very close. In some cases, a C compiler can optimize code in a way that would be very difficult for a human, even surpassing well written human assembly when very complex constructs are involved. Byte Craft did an interesting test on one of thier C compilers^ where they verified that for every instruction in the processors instruction set, there is some C sequence that compiles into that single instruction. At least with that compiler, for every possible Assembly program there exists a C program that generates the same (if not less) code.The PCB, PCM, and PCH are separate compilers. PCB is for 12-bit opcodes, PCM is for 14-bit opcodes, and PCH is for 16-bit opcode PIC® microcontrollers. Due to many similarities, all three compilers are covered in this reference manual. Features and limitations that apply to only specific microcontrollers are indicated within. These compilers are specifically designed to meet the unique needs of the PIC® microcontroller. This allows developers to quickly design applications software in a more readable, high-level language.
When compared to a more traditional C compiler, PCB, PCM, and PCH have some limitations. As an example of the limitations, function recursion is not allowed. This is due to the fact that the PIC® has no stack to push variables onto, and also because of the way the compilers optimize the code. The compilers can efficiently implement normal C constructs, input/output operations, and bit twiddling operations. All normal C data types are supported along with pointers to constant arrays, fixed point decimal, and arrays of bits.

PIC 16F877, 18F452 and 18F4550,PIC16F877, PIC18F452,PIC18F4550,16f876,16f84,microcontroller projects,lm35,lm34,lm335,temperature sensor,MikroC Projects


January 25th, 2011

FlashPIC-DEVelopment Board

features of the development board include:
- RS232 through a 9-Pin D-Shell as well as screw terminals and a jumper header.- Up to 32K words of In-System Programmable FLASH memory with up to 256 bytes of EEPROM and up to 1.5K of Internal RAM (depending on processor selection).
- Up to 8, 10 bit, Analog Inputs, using either internal or user supplied reference.
- 9 I/O controlled LEDs, 8 of which are jumper selectable.
- 32KHz “watch” crystal for on-board Real-Time operations.
- A universal clock socket allows for “canned oscillators”, as well as a variety of crystals, ceramic resonators, and passive terminations.
- 0.1” centered headers provide for simple connection to the processor special function pins and I/O.
- A 6-pin, ICD connection is provided for in-system programming and debugging.
This connection is directly compatible with the Microchip ICD, ICD2 and CCS ICD-S programming hardware. Flash PICs can also be programmed through RS232 using an appropriate boot loader application.
- On-board regulation allows for power inputs from 8-38VDC with an LED power indicator.
- Termination is provided for 5VDC output at 250ma Power J2 (screw terminal connector) is the power input point. Acceptable voltages are 8 – 38 VDC (J1-1 is +, J1-2 is ground).
JP11 is an output of the regulated 5 VDC that may be used to power other devices. Note, however, that the LM7805 does not have a heat sink and so the actual available power output is somewhat limited, depending on the input voltage and power being consumed. Check the LM7805 regulator specification for details.
Serial Connection P1 is a standard DB-9 connector usually used to connect to a PC. The TX signal is on
P1-2 and the RX signal on P1-3. These are RS-232 level signals. J1 and JP8 also provide connections for the RS-232 level serial signals. On each connector, pin 1 is the TX signal, pin 3 is the Rx signal and pin 2 is ground.JP9 and JP10 are jumpers, which connect the processor serial signals (RXD and TXD) to/from the RS-232 driver chip. These jumpers must be in place for the RS-232 serial connections to work. Removing the jumpers allows use of the Port D, bits 0 and 1, for TTL-level I/O.
SPI Connection Use of the SPI bus is by making connections to the SPI bus signals on Port C (JP1-4, 5,
and 6). Parallel Ports
Parallel ports A/E, B, C, and D are connected to JP5, JP4, JP1, and JP7, respectively (and labeled clearly on the board). Bits are connected sequentially with bit 0 on pin 1, bit 1 on pin2, etc. These are normal TTL-level signals with or without pull-ups depending on the port initialization set up in the software.
Port A/E (JP5) has a parallel row of ground pins next to it (JP6) providing a convenient ground reference when measuring analog voltages with the internal A/D converter (ADC).
Port B (JP4) has a parallel row of ground pins next to it (JP16) so that enabling the built-in pull-up resistors and then using two-pin jumpers to ground any pins that need a logic 0 applied for input purposes can effect simple input signals. Port C (JP1) has a parallel set of pins (JP3) at positions 1 and 2. A clock crystal (32.768 KHz) is connected to JP3. JP3 is located adjacent to JP1 (Port C) to proprovide an easy
connection of the clock crystal to Port C bits 0 and 1 for use as a real-time clock. Port D (JP7) has a parallel row of pins (JP2), each of which is connected to an LED through a 510-ohm series resistor to +5 VDC. Jumping any of the pins of JP7 to the corresponding pin of JP2 allows the use of the on-board LED’s as an output. Because the LED’s are connected to +5 VDC and the port is sinking the LED current, the LED
will be on for any pin that outputs logic 0. System Clock
As supplied, the system clock is 10 MHz. U2 contains the crystal and caps necessary for the oscillator. Replacing U2 with a TTL, crystal, ceramic resonator, or RC oscillator, or a different integrated oscillator unit allows changing the system clock if necessary.
CAN Interface A CAN interface driver socket it provided (U5) for a Linear Technologies, LT1796
CAN bus interface. Jumpers JP13 and JP14 connect the CAN interface to the appropriate pins on the controller (CANTX and CANRX). The CAN interface is intended for use with the PIC18F45x microprocessors that have an actual CANtransceiver built in. Refer to Microchips website and datasheets for details on the CAN bus controller and its features.
PIC16F877/18F458 PIC® Boot Loader The boot loader runs on the PIC’s UART at 9600 baud, XON, XOFF handshaking, 8 data bits and 1 stop bit. The boot loader code is executed upon reset or power up of the processor. If the boot loader does not receive instructions to load a new file with 5 seconds, then it jumps to the application code.the boot loader source
code is available for purchase and as such provides the opportunity for customized boot
loader solutions. The PIC boot loader is available at http://www.prllc.com/

After the PICBL is started (via a reset or a power-up), the following protocol must be observed. The PC application provided handles the protocol for you with its default settings or you can create a custom application. PIC 16F877, 18F452 and 18F4550,PIC16F877, PIC18F452,PIC18F4550,16f876,16f84,microcontroller projects,lm35,lm34,lm335,temperature sensor,MikroC Projects


January 25th, 2011

Flash PIC development board

Usually, a microcontroller by itself is not sufficient to perform the intended tasks. For instance, an oscillator chip is necessary to time the programmed instructions. In order to investigate the capabilities or to test a given microcontroller, obviously it is vital to build the proper circuitary. Example: potentiometer and a power supply to simulate analog inputs or LEDs to simulate the digital outputs. Hence, some hardware and sofware vendors provide the microcontroller with the supplemantary circuit elements on the same breadboard. These boards are called Development Boards. One can also build a development board himself/herself if he/she is willing to go through the painsaking process of building the circuit.
The development board used in the series of experiments is Flash PIC development board. (Figure3.1-1) It has the following features:

- RS232 through a 9-Pin D-Shell as well as screw terminals and a jumper header.
- Up to 32K words of In-System Programmable FLASH memory with up to 256 bytes of EEPROM and up to 1.5K of Internal RAM (depending on processor selection).
- Up to 8, 10 bit, Analog Inputs, using either internal or user supplied reference.
- 9 I/O controlled LEDs, 8 of which are jumper selectable.
- 32KHz “watch” crystal for on-board Real-Time operations.
- A universal clock socket allows for “canned oscillators”, as well as a variety of crystals, ceramic resonators, and passive terminations.
- 0.1” centered headers provide for simple connection to the processor special function pins and I/O.
- A 6-pin, ICD connection is provided for in-system programming and debugging.
This connection is directly compatible with the Microchip ICD, ICD2 and CCS ICD-S programming hardware. Flash PICs can also be programmed through RS232 using an appropriate boot loader application.
- On-board regulation allows for power inputs from 8-38VDC with an LED power indicator.
- Termination is provided for 5VDC output at 250ma The peripheral features of the PIC16F877 are:
• Timer0: 8-bit timer/counter with 8-bit prescaler
• Timer1: 16-bit timer/counter with prescaler,can be incremented during SLEEP via external crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler
• Two Capture, Compare, PWM modules Capture is 16-bit, max. resolution is 12.5 ns
- Compare is 16-bit, max. resolution is 200 ns
- PWM max. resolution is 10-bit
• 10-bit multi-channel Analog-to-Digital converter
• Synchronous Serial Port (SSP) with SPI. (Master mode) and I2C. (Master/Slave)
• Universal Synchronous Asynchronous Receiver
Transmitter (USART/SCI) with 9-bit address detection
• Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin only)
• Brown-out detection circuitry for Brown-out Reset (BOR)

GENERAL
The FlashPIC-Development board is designed for prototyping and laboratory use. The board supports the PIC16F877, PIC18F458 as well as several other PIC16x and PIC18x microcontrollers in the 40-pin DIP package.
New Feature: PIC16F877/18F458 PIC® Boot Loader The FlashPIC-Development board now comes programmed with the PIC16F877/18F458 PIC® Boot Loader. The PIC Boot Loader (PICBL) is a bootstrap loader that, once programmed into the PIC processor’s memory area, allows reprogramming of PIC microcontrollers without need for a chip programmer. The PICBL makes use of the selfprogramming
features of the PIC microcontrollers to allow in-circuit reprogramming. Once the PICBL is programmed into the microcontroller, it remains resident until the chip is erased. Application programs require only a very minimum software interface to use the PICBL. The PC application to interface to the boot loader and more documentation about interfacing to the boot loader are available free at http://www.prllc.com/.

PIC 16F877, 18F452 and 18F4550,PIC16F877, PIC18F452,PIC18F4550,16f876,16f84,microcontroller projects,lm35,lm34,lm335,temperature sensor,MikroC Projects