Tuesday, January 17, 2012

C code for PIC micros and Hi-Tech C


Types for Hi-Tech C

  • Data Types for Hi-Tech C, from Eduardo Rosso. Reasonably well known code, makes handling of data easier.

    Data types for Hi-Tech C.



Delay and Timeout Routines for Hi-Tech C (PIC16Fx core)

  •  Example project illustrating delay and timeout routines.
    Unlike the routines available from the Hi-Tech C site, these are written in in-line 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 Hi-Tech C and PIC16x core.



Delay and Timeout Routines for Hi-Tech C (PIC18Fx core)

  •  Example project illustrating delay and timeout routines.
    Unlike the routines available from the Hi-Tech C site, these are written in in-line 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 Hi-Tech 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 for an alternative solution.
  • Delay routines v2.2 for Hi-Tech C and PIC18x core.



RS232 Serial port




USB Serial port on PIC18F4550

  •  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 PICDEM-FS 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 PICDEM-FS 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 Hi-Tech C v9.62, it worked. Had reports that it does not work on Hi-Tech C v9.51.
    2nd Feb 2009 - customer got it working with Hi-Tech 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).



Bootloaders for PIC Microcontrollers

  • Bootloaders for various PIC microcontrollers.

    • PIC16F87x bootloader. Browse.
    • PIC18F1320 bootloader. This is a port of the PIC16F87x bootloader to the PIC18F1320. Project includes Microsoft Visual C++ source for the Windows downloader, and assembly source for the PIC core. For more background documentaiton about bootloaders in general, see the PIC16F87x bootloader page.

      Download (570KB).
    • PIC17C4x bootloader (obsolete).
      Download (224KB).
    • PIC18x52 bootloader. Browse.
    • dsPIC bootloader from Ingenia. For any dsPIC device. Browse to section.



dsPIC bootloader from Ingenia


This is the source code of the Ingenia dsPIC bootloader.

The bootloader consists of: 
  • Open source firmware code, written in assembler. Can be adapted for generic for all dsPIC devices. 
  • A Windows based Graphical User Interface. Comes with user's guide, algorithm flow, etc.
The main features of the firmware are: 
  • Auto-Baud rate detection. This allows one to use any speed of crystal.
  • Ability to read/write program memory.
  • Ability to read/write EEPROM Memory 
  • Ability to read/write configuration registers.
  • Easily add new dsPIC devices. By default comes only with dsPIC30F4011 and dsPIC30F3011. Define and protect memory zones through a XML configuration file.
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.


Sample Projects in MPLab for Hi-Tech

  •  Example project in MPLab for PIC16F876 and Hi-Tech C 7.86pl2, showing how to output decimals using putch().
    Download.
  • Extremely simple example of how to efficiently count bits in an integer.
    Download.



I2C

  • Example Hi-Tech C code for I2C, interfacing to Microchip 24LC01B non-volatile 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).



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;


    Hi Shane,

    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 

Interfacing to miscellaneous hardware with Hi-Tech C

  •  PIC16F876 to PC comms via RS232 with sample Hi-Tech 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. Download (19KB). See Mike Pearces projects below for more.
  • PIC and SPI bus for a Linear Tech LTC2404 24 bit A/D module, from Scott Douglas, Project Engineer, Blodgett Combi. Heavily commented implementation. Download (6KB). 
  • How to use EEPROM on 12CE673/4. Download (1KB).
  •  For a PIC16F87x, how to initialize the built-in 256 bytes of EEPROM at compile time. Download.
  • How to use EEPROM under CCS C for 24LC256. Link.
  • How to use EEPROM under Hi-Tech C for 24LC01. Link.
  • Example A/D code for 12-bit Texas Instruments TLC2543.  Download
  • Example D/A code for 12-bit Analogue Devices AD7390.  Download.
  • How to use the 93XXX EEPROM chip utilizing built-in hardware SPI for 16X and 17X series micros. Download.
  • Example A/D code for inbuilt ports on PIC16F876/7.  Download.
  • Example C code for SPI to access the following chips.
    • A/D chip, the MAX186 12 bit 8-channel micro-wire and D/A chip, the LTC1446 12 bit 2-channel micro-wire. Download.

  • Example Hi-Tech C code for RS232, Dallas DS1821 temperature probe, I2C, A/D, LCD, keypad, see sample projects below by Mike Pearce.



Complete Design for Giant 8-foot LCD Counter

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 time-sliced multitasking used in this project.


Multitasking on a PIC in Hi-Tech C




USB to IBM-PC communications using PIC16F876


See the following link for Hi-Tech 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.




Mechanically scanned display source code in Hi-Tech C


From Rickard GunĂ©e 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/


Other

  • Sample projects that come with Hi-Tech C compiler.  Look in directory c:\ht-pic\samples for a/d routines, delay, i2c, interrupt, interrupt serial, software serial, LCD, SCI, timer0 and more.
  • Sample routines that come with the Hi-Tech C compiler.  Look in directory c:\ht-pic\sources for many math, string, and variable routines.


0 comments:

Flag counter

free counters