Anda di halaman 1dari 11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode

Search
Searchthissite(www.microchipC.com).

OpenADCHighSpeedAnalog
HighSpeedADCBoardforFPGAs:LowCost,OpenSource,ExampleCode

Expand All | Collapse All

Home
+ PIC Code in C (55)
Index
+ PIC16Fx code in C (2)
+ PIC18Fx code in C (2)
+ dsPIC30Fx code in C (2)
USB code in C
CRC routines in C
EEPROM
I2C
A/D
D/A
LCD
MMC Card
Pulse Monitor Project
Triac Controller Project
PIC12C509 logic gate
Phase Controller Project
Dallas DS1821 Thermostat
Heater Project
Multitasking
Samsung KS0713 driver code
... and 40 other example
projects

CsamplecodeforPICmicrosandHiTechC
Sample projects for the Microchip PIC micro series of microcontrollers, including the PIC12x, PIC16x, PIC18x, PIC24x, and dsPICx
microcontrollers.
Code is targeted at the HiTech C compiler, from www.htsoft.com, the C18 or C30 compiler from www.microchip.com, or CCS
C.
We want to publish your embedded source code for the benefit on the PIC community. Send it to support@microchipc.com
and I will post it on the site, together with recognition of your name and website.
CRC.
USBserialportforPIC18F4550.
MMCcard.
DelayroutinesinCforPIC16Fxcore.
DelayroutinesinCforPIC18Fxcore.
UARTforPIC16F87xandPIC18Fx.
BootloaderPIC16F876.
BootloaderPIC18F1320.
BootloaderPIC18Fx52.
BootloaderPIC17C4x.
BootloaderdsPIC(allvariants).
EEPROM.
A/D.
D/A.
SPI.
LCD.
PIC12C509logicreplacementnitrogenfiller.
I2C.
MultitaskingandRTOS.
17C4xbootloader.
16F84basedpulsemonitor.
TRIACcontroller
DallasDS1821thermometer.
Decimalroutines.
PIC16F84pulsemondate/timeRS232serial
port
PIC16F84TRIAC/IGBT50/60Hzcontrol.

+ PIC C FAQ (68)


+ PIC bootloaders (5)
+ PIC Articles (3)
+ PIC tips (7)
+ Reviews (7)
+ UVa tutorial (2)
Advertise

PhaseControllerfor2kWheater.
DallasDS1821threepindigitalthermostat.
GymTimer.
LCDandkeypadproject.
HeaterProjectinvolves1wireroutines,serial
routines,aP.I.D(Proportional,Integral,Derivative)
calculation,ADC,andainterruptdrivenburstmode
heatercontrol.
dsPIC30Fx"HelloWorld"example.
dsPIC30Fx"RCPulse"example.
CdrivercodeprojectforSamsungKS0713andPIC
micros.
PIC18LF4550withLCDandtemperaturesensor.
MiniBasicexampleperipheralcodeinC,for
PIC18,PIC24,PIC32.ExaminetheCsourcecodeto
workouthowtouseanyperipheralonaPIC18,
PIC24orPIC32.Veryuseful.
InterruptdrivenserialwithcircularFIFOforPIC16x
micro.
Tinythreadsexample1byteperthread.
TheDotFactory:AnLCDFontandImageGenerator
EmbeddedPICProgrammer
PortableLCDdriver.
SimpleRTOS.Atiny,portablemultitaskingOS.
ImproveyourprogrammingwiththeUVatutorial.
...andmuch,muchmore.

SampleCCode(setA)
TypesforHiTechC
Data Types for HiTech C, from Eduardo Rosso. Reasonably well known code, makes handling of
data easier.
Data types for HiTech C.

EnyxFPB1
Platform
HighendPCIe
StratixVFPGA
board10G/40G
Ethernet,
DDR3,QDR2+

^ Go to top

DelayandTimeoutRoutinesforHiTechC(PIC16Fxcore)
Example project illustrating delay and timeout routines.
Unlike the routines available from the HiTech C site, these are written in inline assembler and thus give precise
timing. Remember to match the actual microprocessor clock speed to the setting for PIC_CLK.
Delay routines v7.1 for HiTech C and PIC16x core.
^ Go to top

DelayandTimeoutRoutinesforHiTechC(PIC18Fxcore)
Example project illustrating delay and timeout routines.
Unlike the routines available from the HiTech C site, these are written in inline assembler and thus give precise
timing. Remember to match the actual microprocessor clock speed to the setting for PIC_CLK.
Note: these routines could cause problems if HiTech C banks the assembly variables in the incorrect bank; the problem
would only surface on a large project with high RAM usage. See file "Warning_deprecated_routines.txt" within the archive

http://www.microchipc.com/sourcecode/#mmc

1/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode
for an alternative solution.
Delay routines v2.2 for HiTech C and PIC18x core.
^ Go to top

RS232Serialport
Serial port example. How to communicate with RS232 to your PC via a serial port, with HiTech C code, hardware
schematics, and Visual Basic 6 sample project.
Serial port example for HiTech C and PIC16x core.
Serial port example for HiTech C and PIC18x core.
SerialportexampleforHiTechCandPIC30xcore.
The FAQ contains hints here.
^ Go to top

USBSerialportonPIC18F4550
USB example for PIC18F4550. Plug your PIC18F4550 into your PC using a USB cable. A virtual RS232 COM port is
created, allowing your application to print RS232 messages into HyperTerminal. Allows porting of legacy code that used
RS232 comms.
This project is a modified form of the CDC (Communications Class Driver) available from www.microchip.com. The
www.htsoft.com forum has some discussion on this code.
Note: ensure that you read "readme (including install notes).txt" after download.
Schematics: this code runs on the PICDEMFS board from Microchip. To make your own schematic, place a PIC18F4550 on a
breadboard, ensure that you are using a 20Mhz crystal, place a 470nF capacitor on port Vusb, and hook the USB directly to
the chip. It should start to work straight away. Download the PICDEMFS datasheet for the exact schematic to use with
this code.
Result: start up HyperTerminal or putty, find the new COMx port that has been enumerated. Set it to 115200,N,8,1. The
actual COM port speed doesn't matter, as its a virtual comm port. You will see "[alive]" being continuously generated
on virtual com port X over USB. You can find the exact number of the virtual COM port by going into "Control Panel",
then "System", then selecting the "Hardware" then "Device Manager", there will be a new COM port under "Ports (COM &
LPT). You can change the number of the virtual comm port by going into properties, and selecting the new COM port.
11th Nov 2007 tried it on HiTech C v9.62, it worked. Had reports that it does not work on HiTech C v9.51.
2nd Feb 2009 customer got it working with HiTech C v9.51, it worked after some tweaks. Added instructions to v1.10
of the download.
Download PIC18F4550 USB serial port example v1.02 (540KB).
Download PIC18F4550 USB serial port example v1.10 (540KB).
^ Go to top

BootloadersforPICMicrocontrollers
BootloadersforvariousPICmicrocontrollers.
PIC16F87xbootloader.Browse.
PIC18F1320bootloader.ThisisaportofthePIC16F87xbootloadertothePIC18F1320.Project
includesMicrosoftVisualC++sourcefortheWindowsdownloader,andassemblysourceforthePIC
core.Formorebackgrounddocumentaitonaboutbootloadersingeneral,seethePIC16F87x
bootloaderpage.
Download(570KB).
PIC17C4xbootloader(obsolete).
Download(224KB).
PIC18x52bootloader.Browse.
dsPICbootloaderfromIngenia.ForanydsPICdevice.Browsetosection.

^ Go to top

dsPICbootloaderfromIngenia
This is the source code of the Ingenia dsPIC bootloader.
The bootloader consists of:
Opensourcefirmwarecode,writteninassembler.CanbeadaptedforgenericforalldsPICdevices.
AWindowsbasedGraphicalUserInterface.Comeswithuser'sguide,algorithmflow,etc.

http://www.microchipc.com/sourcecode/#mmc

2/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode
The main features of the firmware are:
AutoBaudratedetection.Thisallowsonetouseanyspeedofcrystal.
Abilitytoread/writeprogrammemory.
Abilitytoread/writeEEPROMMemory
Abilitytoread/writeconfigurationregisters.
EasilyaddnewdsPICdevices.BydefaultcomesonlywithdsPIC30F4011anddsPIC30F3011.Defineand
protectmemoryzonesthroughaXMLconfigurationfile.
Forum devoted to the Ingenia bootloader. See feedback from other users of this bootloader.
Or browse directly to the Ingenia bootloader homepage or the Ingenia company homepage.
Download
Download firmware and Windows installer (3.8MB).
Download user manual (442KB).
If you wish to contribute configuration files for this bootloader, for different dsPIC devices, email support@microchipc.com.
^ Go to top

SampleProjectsinMPLabforHiTech
Example project in MPLab for PIC16F876 and HiTech C 7.86pl2, showing how to output decimals using putch().
Download.
Extremely simple example of how to efficiently count bits in an integer.
Download.
^ Go to top

I2C
Example HiTech C code for I2C, interfacing to Microchip 24LC01B nonvolatile EEPROM and Dallas Temperature sensors
DS1775 and DS1721.
Download (4KB).
By Mike Pearce. From readme.txt: "A complete set of bit banged, software driven I2C routines I created for any PIC
device and they work!! These functions are single master only functions, and are ideal for communicating with things
like EEPROMs, LCD Drivers, ADC Converters etc.". Intel enquired about using this code in one of their products.
Download (51KB).
See Mike Pearces projects below for more.
Example code for I2C, routines for PIC16F877 to write to the 24LC01B EEPROM, using the PICDEM 2 demo board
from Microchip. By Michael Alon.
Download (5KB).
^ Go to top

CRC
Excellent CRC code.
// Update the CRC for transmitted and received data using
// the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1).
unsigned char ser_data;
static unsigned int crc;
crc = (unsigned char)(crc >> 8) | (crc << 8);
crc ^= ser_data;
crc ^= (unsigned char)(crc & 0xff) >> 4;
crc ^= (crc << 8) << 4;
crc ^= ((crc & 0xff) << 4) << 1;
^ Go to top

InterfacingtomiscellaneoushardwarewithHiTechC
Hi Shane,
PIC16F876 to PC comms via RS232 with sample HiTech C code and VB 6 code.
Link.
By Mike Pearce. From readme.txt: Dallas DS1820 Digital Temperature Probe routines for
the PIC12Fx and PIC16Fx series. Includes CRC checking routines.
See Mike Pearces projects below for more.

Download (19KB).

PIC and SPI bus for a Linear Tech LTC2404 24 bit A/D module, from Scott Douglas,
Project Engineer, Blodgett Combi. Heavily commented implementation.
(6KB).
How to use EEPROM on 12CE673/4.

http://www.microchipc.com/sourcecode/#mmc

Download (1KB).

Download

I appreciate the time and


effort you spent to make
this page, well done !!
I've been involved with PIC
micros since 1996 and
programming in
C (CCS Compiler) for the
last two years.
I want to send you my best
regards from Argentina.
Humberto

3/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode
For a PIC16F87x, how to initialize the builtin 256 bytes of EEPROM at compile
time.

Download.

How to use EEPROM under CCS C for 24LC256. Link.


How to use EEPROM under HiTech C for 24LC01. Link.
Example A/D code for 12bit Texas Instruments TLC2543.
Example D/A code for 12bit Analogue Devices AD7390.

Download.
Download.

How to use the 93XXX EEPROM chip utilizing builtin hardware SPI for 16X and 17X series micros.
Example A/D code for inbuilt ports on PIC16F876/7.

Download.

Download.

Example C code for SPI to access the following chips.


A/D chip, the MAX186 12 bit 8channel microwire and D/A chip, the LTC1446 12 bit 2channel microwire.
Download.
Example HiTech C code for RS232, Dallas DS1821 temperature probe, I2C, A/D, LCD, keypad, see sample projects below
by Mike Pearce.
^ Go to top

CompleteDesignforGiant8footLCDCounter
This is the complete design for a giant 8 foot money counter for student debt. It is still working beautifully to
this day, counting up student debt in the main library at Canterbury University of New Zealand.
Download the complete design, including sample PIC code in C (for PIC16F876 or pIC16F877), Visual Basic
code, Protel 99 .pcb files, plans and photos.
Download (1080KB).
Explanation of the timesliced multitasking used in this project.
^ Go to top

MultitaskingonaPICinHiTechC
Example of a simple but powerful multitasking system. Have multiple tasks, each with their own priority, running in the
backgrounds. Stepbystep tutorial and sample code.
^ Go to top

USBtoIBMPCcommunicationsusingPIC16F876
See the following link for HiTech C source code for interfacing a 16F876 to a PC using a Philips PDIUSBD11 chip. Many thanks to
Craig Peacock. http://www.beyondlogic.org/usbnutshell/usb7.htm#PIC16F876Example.

^ Go to top

MechanicallyscanneddisplaysourcecodeinHiTechC
From Rickard Gune in Norway, the design for a rotor with a row of LEDs on the end. As it spins, it forms pictures. The photo to
the right shows a game of tetris implemented on the spinning led rotor! See http://www.rickard.gunee.com/projects/
^ Go to top

Other
Sample projects that come with HiTech C compiler. Look in directory c:\htpic\samples for a/d routines, delay, i2c,
interrupt, interrupt serial, software serial, LCD, SCI, timer0 and more.
Sample routines that come with the HiTech C compiler. Look in directory c:\htpic\sources for many math, string, and
variable routines.
^ Go to top

SampleHiTechCprojectsbyMikePearce(setB)
These sample HiTech C projects were supplied by Mike Pearce while he was working at the University of Canterbury, New
Zealand. He is an excellent programmer for PIC micros, and manages to make them do things that I barely thought were
possible. These projects partially cover the 8+ years of work he performed in the Chemistry Department and as a hobby. They
give a window into the way he does his code, and perhaps you will learn a few tricks from him :) Enjoy!

PIC16F84basedpulsemonitorwithdate/timeoutputtoanRS232serialportbyMike
Pearce
Here's the scenario: at University of Canterbury, New Zealand, they operate a hugely expensive Xray crystallography machine. It
was water cooled, and each run would take 24 hours and cost the client a lot. Unfortunately, as the story goes, there was a
problem with the water supply controller, and it would periodically drop pressure and the machine would shut down. This means

http://www.microchipc.com/sourcecode/#mmc

4/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode
the run would have to be started again.
So, Mike Pearce designed a watermonitor. It would measure the flow, based on pulses from a flow meter. If the pulses dropped
below a predetermined threshold, it would log the date and time out to a serial port. They set up a PC with a serial program,
and came back the next day to see exactly when the flow had dropped.
Mike tracked down the problem and had the system adapted to counter for the glitches, due to this nice piece of design work.
Entire archive.

Download (136KB).

^ Go to top

PIC16F84basedTRIAC/IGBTphasecontrollerfor50/60HzbrightnesscontrolbyMike
Pearce
From readme.txt: A single channel phase controller for a PIC16x84 @ 10Mhz. RB0/INT is used for the zero cross detection. RA0 is
an active LOW output to an opto isolator to drive a TRIAC or IGBT circuit. Phase control is a simple even timeslice method, with
255 levels of output. This has samples of how to use the interrupt routine for TMR0 and INT. Timing for 50Hz and 60Hz has been
included selectable by commenting out the unwanted option. Also TRIAC or IGBT output is available by commenting out the
unwanted option.There is more info in the .c file pertaining to TRIAC/IGBTS and EMI standards.
Entire archive.

Download (106KB).

^ Go to top

PIC12C509logicgatereplacementfornitrogenfillerbyMikePearce
From readme.txt: This project was a really quick replacement for an old logic gate that had faulted and could not be fixed. It is
a simple program that uses nested if{}else{} statements to do a BETTER job than the original logic did, by the addition of some
error trapping and a timeout delay for safety reasons (and to save money because Liquid Nitrogen is not cheap).
Entire archive.

Download (5KB).

^ Go to top

DemoBoardbyMikePearce
This code was used to drive a demo board that I made for a University of
Canterbury demonstration day.
From readme.txt: The demo board consisted of a 16F84, five 240V 3A solid state
relays, an RS232 port, a Dallas 1wire interface port (using a RJ11/12
connector), and a number of LEDs ...
The archive contains the HiTech C source code, Protel 99 schematic and pcb
files, and .jpg schematic.
Schematic for demo board. View.
Entire archive.

Download (180KB).

^ Go to top

HeaterProjectbyMikePearce
From readme.txt: The Heater 3 project is used to control waterbath heaters and other specialist temperature controlled
equipment within the Chemistry Department.
This project combines the use of the 1wire routines, serial routines, a P.I.D (Proportional, Integral, Derivative) calculation,
ADC, and a interrupt driven burst mode heater control.
Entire archive.

Download (158KB).

^ Go to top

PhaseControllerfor2kWheaterbyMikePearce
From readme.txt: One of the projects I did need accurate control of a 2KW heater element ... with quite a bit of thought and
some help with some math to work out "Even Power" steps for a sign wave, I sat down and wrote this simple, soft timed program
that controls a single output and is set but 4 input pins. Uses 12C508. Note: this is an assembly language project, not a HiTech C
based project.
Entire archive.

Download (30KB).

^ Go to top

DiscoLightControllerbyMikePearce
From readme.txt: I wanted to make up a simple disco light controller that went through a pre
programmed sequence, and I had not had HTPIC C for long, so it was a good opportunity to
have a play. Included are a couple of DOS programs that I used to generate the patterns and
convert to an array ready to be pasted into the PIC's C file. I took this software one step
further and had it output to the PC Parallel port so with a patch cable I could simulate the
PIC's output on the actual circuit board I used, hence I was able to preview the lights outputs.
Included is an image of the Lighting Box I built up.

http://www.microchipc.com/sourcecode/#mmc

Dear Shane Tolmie,


This site is great. It
helped me a lot to start
with c development on
PIC.
Thank you for this great
work.

5/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode
Entire archive.

Download (200KB).

^ Go to top

Regards,
Parag Panchal
India

DallasDS1821threepindigitalthermostatbyMikePearce
From readme.txt: The DALLAS DS1821 is a 3 pin digital thermostat that can have its trigger points programmed using the Dallas
1wire interface. The need arose for this programmer when we had to replace the bimetal thermostat controls from some
fridges in the department for safety reasons. The DS1821 was the ideal replacement, the combination of small size, low
operation voltage (35 volts) and operates to pre programmed settings that couldn't be changed unless you had a special
programmer. Hence the birth of the DS1821 Programmer project. This project uses the 1wire and I2C routines.The Turn On,
Turn Off and Polarity values can be programmed using this code. There are 3 buttons, 'Menu', '+', and '' to allow adjustments.
The Data is displayed on a 4 digit I2C LCD controlled by a PCF8577 (Philips).
Archive includes HiTech C source code, schematics, and more.
Entire archive.

Download (149KB).

^ Go to top

GymTimerbyMikePearce
From readme.txt: For PIC12C509, this was a very simple timer and buzzer that I made for a client that wanted timer for doing
gym circuits in his home gym. I made this one up on a piece of vera board, and it injects a signal into an audio line that was fed
into an amplifier from his CD Player. This cut costs dramatically due to no extra amplifier/speakers needed. The time is set by
the state of GP0,1,2,3 and is calculated by the binary value * 5 + 30 seconds. This allows the interval to be set from 30 seconds
to 105 seconds in 5 second increments. This is only approximate!!GP5 was fed through a resistor and capacitor type set up into
one channel of the audio and just does a short Buzz at the end of each interval.
Entire archive.

Download (6KB).

^ Go to top

HighSpeedPulseGenerator(HSPG)byMikePearce
From readme.txt: I have included this code as an Example of using a 20x2 character LCD, I2C EEPROM and basic I/O Control, it
also has a ascii to unsigned long function that I created to convert entered text into a useable number.The HSPG project is a
specialized piece of hardware for accurately generating pulses on a rather large piece of equipment (it takes up a large room).
This unit has a resolution of 20ns and a 24 bit counter (0 to approx. 0.335 sec in 20ns steps) and all the pulse outputs are fibre
optic for noise reduction, earth loop elimination and speed. This is the only piece of equipment like it in the world that we know
of, and hence it is restricted, so circuit diagrams will not be supplied. However, if you want to buy a complete unit (with
updated firmware) ... not a problem if you have a spare US$10,000 ... but you still won't get the diagrams!!!
Entire archive.

Download (15KB).

^ Go to top

LCDandKeypadprojectbyMikePearce
From readme.txt: This project was for the first version of the High Speed Pulse
Generator, but was scrapped due to technology restrictions of the time. But the board has
been used for testing character LCDs and keypads, and does make a reasonable general
purpose display and keypad type controller with a number of control lines available.
Entire archive.

Download (108KB).

^ Go to top

SamplecodefromMikePearce
Miscellaneous code for reference, the projects above are a more complete and updated version
of this archive.

Hello Shane,
Congratulations on a truly
excellent learning
resource for PICC! I have
learnt from your examples
and refer many of our PIC
customers to your site for
additional design tips.

BatteryChargerfor8NiCadbatterypacks
DiscoLightDriverForthePIC12C50x
RepeatingTimerForGymCircuits,switchablefrom30secto60secin5sec
Please encourage
intervals
contributions and grow
the resource !
ProgramforusingaPIC16C64tocontroltheheating/coolingforthePVC
Reactor
Andrew Metcalfe
SoftwaretoreplacelogicdrivingtheLiquidNitrogenFillersystem,uses
Field Applications
PIC12C508
Engineer,
Arrow Electronics
MotorcontrolsoftwaretodriveUOCMOTORCTRL001usingPWM.
AprogramforthePIC12C50xtodrive4solidstaterelays,usesRS232and
Dallas1wiresystem.
ProgramisaserialcommunicationbetweenDallasTempProbesPCandPhaseController.
Basiccodethatturnsthe16F84intoaEEPROMtogetthingsupandrunning.
The entire archive is available.

Download (213KB).

^ Go to top

SamplecodefromEdWaugh(setC)
http://www.microchipc.com/sourcecode/#mmc

6/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode

EEPROM
Sometimes it is useful to have access to a larger amount of nonvolatile storage than is available onboard the PIC. A serial
accessed eeprom can be the best way to do this but they are usually only available in sizes up to 512Kbits. The 24LC256 is a
256Kbit eeprom avaialble from microchip and is what these functions are designed to work with although they should work with
any size and speed of eeprom with suitable modification of the loops. This is just the functions you need to get some code
working and then drop these in.

The code has been tested on both a 16F876 using software and hardware I2C interfaces. Setting the pins to the hardware I2C
port int the #use line at the top of the code enables the hardware I2C.
Basic read and write byte functions are provided as well as a set of functions for a contiguous read (by Tom Cook) that allows
faster read out of a stream of data. There is also a function to write a string of any length to the eeprom. They should all be
fairly self explanatory.
EEPROM source in CCS C
^ Go to top

MMCcard
For applications where more storage is required I would definately reccomend MultiMediaCards (some times called SanDisk (SD)
flash). The built in SPI interface only requires four data lines and they are available in sizes of up to 256MByte (at the moment).
There are a few little quirks in making the cards work with a PIC but these are hopefully all sorted out within the code. The
code is set to use the hardware SPI pins on the 16F876 and I haven't tried it any other way.
The MMC card has quite a large block size for writing, I think at the moment it is at least 512Bytes although I think I saw
something about a new version of the specifcation that is more flexible. But at the moment this means that you need to buffer
512Bytes and write them all in one go, the eeprom code (above) is ideal for this. The write_block function just writes the lowest
512Bytes from the eeprom to the MMC. The same is true when reading the card and in my current application I only need to read
the data to a PC so the read_block function just outputs every byte to RS232 although it wouldn't be hard to insert some
processing or pass each byte to whatever function you wanted. This is just the functions you need to get some code working and
then drop these in.

MMC source in CCS C


^ Go to top

CcodesamplesfordsPICbyMikePearce(setD)
"HelloWorld"fordsPIC30F3011onaKPIC2840Pprototypingboard
From readme.txt: All my samples will be written for the dsPIC30F3011 40 pin DIP package that can work (with minor mods) on a
KPIC2840P prototyping board (available from www.kiwacandirect.com). Compiled with the C30 evaluation version of the C
compiler from www.microchip.com.
This project is a simple "Hello World" sent out the serial port. Shows quick setup of the UART for TX only.
C source for Microchip C30 compiler for Hello World
^ Go to top

RCPulsefordsPIC30F3011onaKPIC2840Pprototypingboard
From readme.txt: All my samples will be written for the dsPIC30F3011 40 pin DIP package that can work (with minor mods) on a

http://www.microchipc.com/sourcecode/#mmc

7/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode
KPIC2840P prototyping board (available from www.kiwacandirect.com). Compiled with the C30 evaluation version of the C
compiler from www.microchip.com.
RCPulse generates the 1 to 2ms pulse required for remote control servo control. Demonstrates the use of Timer and interrupts.
Currently writing a multichannel version for a project. Compiled with the C30 evaluation version of the C compiler from
www.microchip.com.
C source for Microchip C30 compiler for RC Pulse

SamsungKS0713GraphicalLCDDriverforMicrochipPIC24anddsPIC33Microcontrolers
From readme.txt: Make sure you have the latest MPLAB and MPLAB C30 programs from www.microchip.com before proceeding.
Original hardware obtained from Mike Pearce from www.kiwacandirect.com.
1. Create a new project.
2. Select PIC24 or dsPIC processor.
3. Select MPLABC30 compiler.
4. Add the following files and select "copy to project folder".
glcd.c
glcd.h
glcdbitmaps.c
glcdbitmaps.h
glcdtest.c (for demo code otherwise your main c file )
pXXxxxx.gld (The gld file specifically for your micro
controller)
(Found in c:\Program files\Microchip\Mplab
C30\Support\Gld\)

Click to enlarge

5. Once setup has completed open the glcd.h file for


editing.
Change the I/O LAT, PORT, TRIS settings to match your
design.
Change frequecy to match your design.
Change display resolution to match your LCD.
Save your changes.
6. Open main.c for editing (This is just a basic framework).
Fill in the gaps with the rest of your program.
Make sure any analog input ports that have been used for the LCD are set up as digital I/O.
7. Compile and hopefully it works.
C project for Microchip C30 compiler for Samsung KS0713 Graphical LCD Driver.
^ Go to top

CcodesamplesforPIC18F4550fromJohnLeung(setE)
PIC18LF4550withLCDandTemperatureSensor
"Attached is an example project to display realtime ambient temperature and relative humidity from SHT10 digital sensor on a
65k 1.8" color display. The microcontroller was PIC18LF4550. The result is shown in the jpeg file as well. All code with heavy
comment."
Compiler: C18 compiler v2.40
Comaptible with SHT10 digital temperature and humidity sensor.
Compatible with CM50012ACT6 65k color Graphical LCD Display Driver (HYVIX HDC1600 controller).
Original hardware obtained from www.techtoys.com.hk.
Temperature sensor with LCD for PIC18LF4550.

^ Go to top

JoystickDemo
"Attached please find another application for using joystick commonly found in game pad, mobile phones, etc. It is nothing more
than individual tactile keys. There is a .pdf explaining the source code as well. Working on a dev board for PIC24 series. It will
come with a 2.2" TFT color LCD. Designed for the C18 compiler."
Original hardware obtained from www.techtoys.com.hk.
PIC sample project with JoyStick and I/O handling. Note: zip file includes documentation in .pdf format.

http://www.microchipc.com/sourcecode/#mmc

8/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode

^ Go to top

MiniBasicSourceCodeinC(setF)
MiniBasicexampleperipheralsourcecodeinC
MniBasic is a full basic interpreteter for the PIC18, PIC24, and PIC32. It is written in C. By examining the source code, you can
work out how to use almost any peripheral on the PIC18, PIC24 or PIC32. Example peripheral source code includes, but is not
limited to, RS232, PWM, timers, LCD, port control, SPI, I2C, ethernet (under development), etc.
See www.pic32.org/minibasic/.
^ Go to top

SourceCodefromRegulusBerdin(setG)
InterruptDrivenSerialRoutineswithCircularFIFOforPIC16xMicro
This is another routine that I want to share. This is the interrupt driven serial routine with circular FIFO for any PIC16x micro
with a hardware UART. Compiled with HiTech C. Since this is unbuffered, so I added a software FIFO. The FIFO management is
quite lean and fast but required the size of the buffer to be power of 2 (2^x). This is because FIFO rollover uses bitwise AND of
(buffer_size 1). This reduces code size due to that no more conditionals to test pointers overflowing the buffer.
Interrupt driven serial routine with circular FIFO for PIC micro.

TinyThreadsTinyMultitaskingThreadsforMicrocontrollers
For the efficiency and performance conscious C programmers, here is my tiny cooperative multitasking engine.
byRegulusBerdin
Idea based on http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html.
Only 1 byte RAM needed per thread.
Very small overhead context switching.
Limitations:
Maximum 254 lines per thread.
Thread context switching will not work within a switch block.
tthread.h. Header file for Tiny Threads. This is the only file needed to use Tiny Threads.
tt_sample.zip. Sample application using tthread. Compiles with PICC compiler from www.htsoft.com.
^ Go to top

SourcecodefromShaneTolmie(setH)
InnoSetupAV v1.00, a sample installer script for any Windows based support programs for any embedded work.

UVaTutorial
You can easily rank your programming aptitude compared to others over 80,000 others, to be precise.
Read more on the UVa Online Judge tutorial.
^ Go to top

TheDotFactory:AnLCDFontandImageGenerator
From www.pavius.net: The Dot Factory is a small, GPL, open source tool intended to generate the required C language
information to store many fonts and images, as efficiently as possible, on a microcontroller. These fonts are then uploaded via
the LCD driver (see the Drivers and Modules page for a few) to the actual dot matrix LCD. Compatible with numerous PIC micros,
more micros can easily be added by writing a simple driver.
Read more.
^ Go to top

EmbeddedPICProgrammer
From www.pavius.net: Hi Shane, I'm the author of The Dot Factory, the free LCD font generator you so gracefully link to on
microchipc. I was recently contracted to implement lpicp, a PIC programmer that works on embedded Linux platforms. It allows
any embedded platform running Linux to effectively become a PIC programmer. I haven't seen such an implementation before so
I released it as GPL, for anyone to use or reference.
If you feel it is relevant for microchipc, please feel free to link to the project page:
http://www.pavius.net/2011/06/lpicptheembeddedlinuxpicprogrammer/.
Read more.

http://www.microchipc.com/sourcecode/#mmc

9/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode
^ Go to top

PortableLCDdriver
From Pallav Aggarwal:
Following link contains code for Character LCD interface Driver for 16x2 Size (8bit/4bit configurable), this is fully portable code
for any MCU.
http://pallavaggarwal.blogspot.in/2012/06/genericcharacterlcddriver16x2.html
Requesting you to please add my code for the benefit of all engineers and students.
If you feel it is relevant for microchipc, please feel free to link to the project page:
Portable LCD driver.
Read more.

SimpleRTOS
Published in response to an email sent the admin at MicrochipC. This website also has a good range of other sample code, its
worth checking out.
Dear All,
I just published a new version of my "toy" RTOS in my personal pages at PICList. Just it is not a "toy" anymore, it is really useful
and I'm using it already in new projects.
For now the ports for dsPIC/PIC24 and PIC32MX are already working, but I published only the PIC32MX port because it is already
tested.
The link is
<http://www.piclist.com/Techref/member/IMByahooJ86/SimpleRTOS2.htm>
My main page is
<http://www.piclist.com/Techref/member/IMByahooJ86/index.htm>
I plan to port it also to ARM CortexM3 and M4 because I use Atmel's SAM3 and SAM4 devices, but those ports may take some time
to be finished.
My original RTOS was just a proofofconcept cooperative RTOS for
PIC16F, but could be used in some simple applications.
My main motivation to rewrite it for bigger MCUs was that FreeRTOS uses too much memory and it doesn't fit even in some
PIC32MX devices's (PIC32MX210F016B) RAM or FLASH. My RTOS uses just a fraction of the memory needed by FreeRTOS and I
expect it to be somewhat faster.
The sample application which has six tasks, each one with a 256bytes stack, when compiled with optimization level O3 uses
just 3685 instruction words and 2956 bytes of RAM. It fits easily in a PIC32MX210F016B.
I know that it cannot compete with FreeRTOS in general, but for some simple applications or very constrained devices it may fit
while FreeRTOS won't.
Comments are welcome.
Best regards,
Isaac

XilinxFpgatrainings

8ChannelLEDDimmer

USBSPIProgrammingCable

FreeCalculatorToolbar

mvdfpga.com

abeltronics.co.uk/dimmers

embeddedcomputers.net

calculator.utilitychest.com

Approvedtrainings:Fpga,VHDL,EDK
SoC,Virtex,MicroBlaze,RocketIO

010VDINRailDimmerforLED
stripandtape,UKfactoryprices

Programthousandsofdevicesfast!
Includesfreesoftwareandshipping

Calculators:DifferentCalculators
ForEverySituationFree!

http://www.microchipc.com/sourcecode/#mmc

10/11

3/28/2015

MicrochipPICmicrosandCsourceandsamplecode

We welcome any suggesions or comments! Send them to Shane Tolmie onsupport@microchipc.com. This site is a completely separate site to www.microchip.com, and
is maintained independently of Microchip Ltd., manufacturers of the PIC micro. All code on this site is free for noncommercial use, unless stated otherwise.
Commercial use normally free, however, it is prohibited without contactingsupport@microchipc.comfor permission. All content on this site created by Shane Tolmie is
copyrighted by Shane Tolmie 19992009. Click to advertise on this website $29.90 for a banner ad which will reach 55,000 user sessions per month. One months free
trial!

http://www.microchipc.com/sourcecode/#mmc

11/11

Anda mungkin juga menyukai