Using the Velleman K8048 / K8076 PIC Programmer in FreeBSD, NetBSD, Linux, CYGWIN (Windows) and MACOS/X (UNIX / POSIX)


Table of contents sygwin

K8076 K8048

Introduction

The application found here (k8048) has been written to allow programming of pic micro devices in FreeBSD, Linux and MACOS/X and any other UNIX / POSIX based system with the Velleman k8048 or k8076 kits. In order to use this program on Windows you must first install and setup Cygwin including the necessary development tools for building the application.

Below is the current status of serial interface support:

UART Interface Status Device name
8250/16550 driver Works perfectly Generic
MCT U232 converter Not working Targus PA088
pl2303 converter Working (slowly) Best Connectivity (Dabs Value)
FTDI USB Serial Device converter Not working ECS i-Buddie USB Dock

It has been tested with a standard serial tty by myself on FreeBSD and Linux, and with a Prolific PL-2303 USB to serial adapter on MACOS/X by Tobias Braun who reported success (Thank you Tobias). I have also tested the Prolific along with Fred Marquis and we both report success in Linux. Although the Prolific interface works, it is very slow and this is not resolvable due to usb control messages for this devices taking a minimum of 3ms.

News:

Kristoffer Myskja reports that he has had great success with the windows tool on a laptop without serial I/O by using a cardbus serial interface. He will test Linux at a later time, yet it would seem that such an interface is the best option for any laptop without a UART.

Johan Ahlander has notified me that this application works fine in NetBSD.

Working with keen linux user and PIC coder Paul Van Gelder I have added support for the new Velleman K8076 kit. Thanks Paul! To use the application with the k8076 see the BITRULES option for the DOT FILE below.

Many thanks to Chaitanya Rogers for donating money toward development and to acquire new PIC micros to add to the k8048 application. A couple of new PICs have been recently added, yet there are more to come. Thank you.

Before you download and use this app. you should read the LICENSE found here. This license details the rights and liabilities of using the application and it should be especially understood that I, the author, will not accept any responsibility for any side effects of running it. IE. Do not download and run this program unless you are willing to accept the consequences of it failing for any reason.

At this time, the application is work in progress, and only a small number of devices are supported, which is mostly because I do not have access to many devices for evaluation and testing. The known supported devices are listed later in this document.

If you have no success with this application then it is most likely due to the above but you may find it easy to add support for your own device by editing a small number of source files, else you are welcome to send to me a sample device for testing and I will add it to the list of supported devices with a high priority, if you just send links to PDF docs. etc they will be ignored.

Please contact darron at kewl org with any diffs you have made for support of for another device or alternatively contact me for details about where to send a sample. If you do send a sample it will not be returned as it may be required for future debugging work.

Table of contents

Supported Devices

The following devices are known to work (1..b have demos in asm/test):

  • 1. PIC16F84A - Added by Darron Broad. Initially tested by Paul Van Gelder.
  • 2. PIC16F627 - Added by Darron Broad.
  • 3. PIC16F88 - Added by Tobin Richard.
  • 4. PIC16F648A - Added by Darron Broad.
  • 5. PIC16F819 - Added by Darron Broad.
  • 6. PIC16F676 - Added by Darron Broad.
  • 7. PIC12F675 - Added by Darron Broad.
  • 8. PIC16F877A - Added by Darron Broad. Connect via ICSP and tie 15pf to ground on PGC.
  • 9. PIC18F1320 - Added by Darron Broad. Connect PGM to GND via 10K resistor on 28 PIN DIL.
  • a. PIC18F2550 - Added by Darron Broad.
  • b. PIC18F252 - Added by Darron Broad.
  • c. PIC16F716 - Added by Darron Broad.
  • x. PIC12F683/16F688 - Added by Darron Broad.
  • x. PIC18F4550 - Added by Darron Broad. Connect via ICSP and tie 15pf to ground on PGC.
  • x. PIC16F873A - Added by Chris Williams.

Full support list is as follows with device status:

         * Compatible ICSP devices:

         * DS30262E
         *  PIC16F84A   T

         * DS30277D
         *  PIC16F627   T
         *  PIC16F628   U

         * DS39025F
         *  PIC16F870   U
         *  PIC16F871   U
         *  PIC16F872   U
         *  PIC16F873   U
         *  PIC16F874   U
         *  PIC16F876   U
         *  PIC16F877   U

         * DS39589B
         *  PIC16F873A  T
         *  PIC16F874A  U
         *  PIC16F876A  U
         *  PIC16F877A  T

         * DS39607B
         *  PIC16F87    U
         *  PIC16F88    T

         * DS41173C/DS41191C
         *  PIC12F629   U
         *  PIC12F675   T
         *  PIC16F630   U
         *  PIC16F676   T

         * DS41196F
         *  PICF627A    U
         *  PICF628A    U
         *  PICF648A    T

         * DS39603C
         *  PIC16F818   U
         *  PIC16F819   T
          
         * DS40245B
         *  PIC16F716   T

         * DS41204G
         *  PIC12F635   U
         *  PIC12F683   T
         *  PIC16F631   U
         *  PIC16F636   U
         *  PIC16F639   U
         *  PIC16F677   U
         *  PIC16F684   U
         *  PIC16F685   U
         *  PIC16F688   T
         *  PIC16F689   U
         *  PIC16F690   U

         * DS39576B
         *  PIC18F242   U
         *  PIC18F248   U
         *  PIC18F252   T
         *  PIC18F258   U
         *  PIC18F442   U
         *  PIC18F448   U
         *  PIC18F452   U
         *  PIC18F458   U

         * DS39592E
         *  PIC18F1220  U
         *  PIC18F1320  T
         *  PIC18F2220  U
         *  PIC18F2320  U
         *  PIC18F4220  U
         *  PIC18F4320  U

         * DS39622K
         *  PIC18F2221  U
         *  PIC18F2321  U
         *  PIC18F2410  U
         *  PIC18F2420  U
         *  PIC18F2423  U
         *  PIC18F2450  U
         *  PIC18F2455  U
         *  PIC18F2458  U
         *  PIC18F2480  U
         *  PIC18F2510  U
         *  PIC18F2515  U
         *  PIC18F2520  U
         *  PIC18F2523  U
         *  PIC18F2525  U
         *  PIC18F2550  T
         *  PIC18F2553  U
         *  PIC18F2580  U
         *  PIC18F2585  U
         *  PIC18F2610  U
         *  PIC18F2620  U
         *  PIC18F2680  U
         *  PIC18F2682  U
         *  PIC18F2685  U
         *  PIC18F4221  U
         *  PIC18F4321  U
         *  PIC18F4410  U
         *  PIC18F4420  U
         *  PIC18F4423  U
         *  PIC18F4450  U
         *  PIC18F4455  U
         *  PIC18F4458  U
         *  PIC18F4480  U
         *  PIC18F4510  U
         *  PIC18F4515  U
         *  PIC18F4520  U
         *  PIC18F4523  U
         *  PIC18F4525  U
         *  PIC18F4550  T
         *  PIC18F4553  U
         *  PIC18F4580  U
         *  PIC18F4585  U
         *  PIC18F4610  U
         *  PIC18F4620  U
         *  PIC18F4680  U
         *  PIC18F4682  U
         *  PIC18F4685  U

	 * DS39752A
	 *  PIC18F1230      U
	 *  PIC18F1330      U
	 *  PIC18F1330-ICD  U

         * T=TESTED, U=UNTESTED
         

The bandgap bits and osccal word of the 12F series are preserved for each write without user intervention yet they should be retrieved and written down for safe keeping and reference (determining these details may be found later in this document).

The PIC16F716 must be power cycled before verification.
The k8048 cannot control the 5V rail so follow these steps:
a. program device
b. switch to standby
c. switch to prog
d. verify device

Table of contents

Devices that may be supported later

The following devices are in my possession and should work some day (hopefully):

  • PIC16F505 (12 bit word architecture)
  • PIC10F200
  • PIC10F202
  • PIC30F4013 (other)
Table of contents

Installing the application

Download the application from here and decompress/extract it, then peform make. It should then be ready for use. This has been tested on FreeBSD 5 and 6 yet should work on all FreeBSD variants and perhaps other BSD derived systems. It has also been test to work in Linux 2.6.

You will need permission to access the tty (linux: ttyS0) device as your user id, so you may need to chmod/chown that dev entry as root to gain access to it, else run the app. as root or make it setuid root.

Here is a sample session obtaining the app. and getting it work:

beethoven:/var/tmp/k> wget -q http://dev.kewl.org/k8048/k8048.tar.gz
beethoven:/var/tmp/k> tar zxf k8048.tar.gz
beethoven:/var/tmp/k> cd k8048/k8048
beethoven:/var/tmp/k/k8048/k8048> make
gcc -Wall -I. -ggdb   -c -o inhx32.o inhx32.c
gcc -Wall -I. -ggdb   -c -o serial_posix.o serial_posix.c
gcc -Wall -I. -ggdb   -c -o io.o io.c
gcc -Wall -I. -ggdb   -c -o pic16f.o pic16f.c
gcc -Wall -I. -ggdb   -c -o pic18f.o pic18f.c
gcc -Wall -I. -ggdb   -c -o pic.o pic.c
gcc -Wall -I. -ggdb   -c -o dotconf.o dotconf.c
gcc -Wall -I. -ggdb   -c -o util.o util.c
gcc -Wall -I. -ggdb   -c -o k8048.o k8048.c
gcc -Wall -I. -ggdb inhx32.o serial_posix.o io.o pic16f.o pic18f.o pic.o dotconf.o util.o k8048.o -o k8048 -lreadline -lncurses
ln -sf k8048 ktest
ln -sf k8048 kdebug
ln -sf k8048 k14
ln -sf k8048 k16
cd velleman && make -s
cd asm/test && make -s
cd asm/pic16f627 && make -s
cd asm/pic16f648a && make -s
beethoven:/var/tmp/k/k8048/k8048> sudo make install
Password:
cd velleman && make -s
cd asm/test && make -s
cd asm/pic16f627 && make -s
cd asm/pic16f648a && make -s
cp k8048 /usr/local/bin/k8048
ln -sf /usr/local/bin/k8048 /usr/local/bin/ktest
ln -sf /usr/local/bin/k8048 /usr/local/bin/kdebug
ln -sf /usr/local/bin/k8048 /usr/local/bin/k14
ln -sf /usr/local/bin/k8048 /usr/local/bin/k16
beethoven:/var/tmp/k/k8048/k8048> sudo chmod 777 /dev/ttyS0
beethoven:/var/tmp/k/k8048/k8048> k8048

k8048: [k8048]

Usage:

   Command        Help
   -------        ----
   k8048       -  Usage
   kdebug      -  Debug PIC16F627
   ktest n     -  Test I/O with n seconds between each test
   k14 a [p]   -  Use 14 bit word architecture (see below for params, and 1a)
   k16 a [p]   -  Use 16 bit word architecture (see below for params, and 1b)

   Action(a)      Parameter(p)   Help
   ---------      ------------   ----
   (i)d                        - Dump device identification
   (c)onfig    -  [config]     - Dump or write (see 2 below) config word
   (o)sccal    -  [osccal]     - Dump or write (see 2 below) oscillator calibration word
   (f)lash     -  [size]       - Dump 128 or size bytes of program flash
   (e)eeprom   -  [size]       - Dump 128 or size bytes of data eeprom
   (p)rogram   -  filename     - Program intel hex32 file into flash
   (v)erify    -  filename     - Verify intel hex32 file in flash
   (u)nprotect                 - Disable program/data protection
   (b)lank                     - Bulk erase device

   (1) a. Some PIC12 and most PIC16 are 14 bit word achitecture (k14).
       b. PIC18 are 16 bit word architecture (k16).

   (2) 12F/16F 14 bit word devices with OSCCAL and BG only.
       The Device is blanked prior to writing either calibration or bandgap bits.

   Examples:

   ktest 10                 - Test I/O
   k14 c                    - Dump config
   k14 c 0x11ff             - Write config
   k16 p mycode.hex         - Program hex32 file
   k16 v mycode.hex         - Verify hex32 file

   Configuration:

   /var/tmp/k/k8048/k8048/.k8048

   # Serial device
   DEVICE=/dev/ttyS0

   # Bit rules for I/O
   # + 0x01 FLIPDTR      (PGD out)    (needed for k8048, not needed for k8076)
   # + 0x02 FLIPRTS      (PGC out)    (needed for k8048, not needed for k8076)
   # + 0x04 FLIPTX       (VPP out)    (needed for k8048, not needed for k8076)
   # + 0x08 FLIPCTS      (PGD in)     (needed for k8048, not needed for k8076)
   # + 0x10 ENABLEPULLUP (PGD pullup) (needed for k8048, may be needed for k8076)

   # k8048: +FLIPDTR +FLIPRTS +FLIPTX +FLIPCTS +ENABLEPULLUP
   # k8076: +ENABLEPULLUP
   BITRULES=0x1f

beethoven:/var/tmp/k/k8048/k8048>

If make fails to build correctly there may be a missing dependency in your installtion such as readline development headers.

In such a circumstance refer to your distribution manual and perform something similar to apt-get install libreadline4-dev or whatever is required in your distro.

In exceptional circumstances you may need to edit the Makefile, please notify me if you do so.

Table of contents

Using the application

There are multiple ways to use the k8048 application and selection of it's mode of operation is performed using one of the psuedo (symlinked) command names.

A DOT FILE in your home directory (.k8048) can be used to determine two constants, the serial interface and velleman kit type. These default to /dev/ttyS0 and k8048 if not specified.

An example DOT FILE is as follows for FreeBSD using a k8048:

            DEVICE=/dev/cuad0
            BITRULES=0x1f
        

To demonstrate it's usage we may demonstrate some assembly code supplied in the asm directory. One test example for the pic16f627 and all it does is send the text "hello, world" over the serial control lines to the host PC within an infinite loop.

The k8048 app has a function to decode such text as sent above and dump it to the console, below is an example of assembling the test file, writing it to the 627 chip and dumping out the text sent by the chip.

beethoven:/var/tmp/k/k8048/k8048> k14 p asm/pic16f627/debug.hex
Total: 103
beethoven:/var/tmp/k/k8048/k8048> kdebug
io_debug: read byte: 04 .
io_debug: read byte: 48 H
io_debug: read byte: 65 e
io_debug: read byte: 6c l
io_debug: read byte: 6c l
io_debug: read byte: 6f o
io_debug: read byte: 2c ,
io_debug: read byte: 20
io_debug: read byte: 77 w
io_debug: read byte: 6f o
io_debug: read byte: 72 r
io_debug: read byte: 6c l
io_debug: read byte: 64 d
io_debug: read byte: 0a .
io_debug: read byte: 03 .
io_debug: read byte: 02 .
io_debug: read byte: 48 H
io_debug: read byte: 65 e
io_debug: read byte: 6c l
io_debug: read byte: 6c l
io_debug: read byte: 6f o
io_debug: read byte: 2c ,
io_debug: read byte: 20
io_debug: read byte: 77 w
io_debug: read byte: 6f o
io_debug: read byte: 72 r
io_debug: read byte: 6c l
io_debug: read byte: 64 d
io_debug: read byte: 0a .
io_debug: read byte: 03 .
io_debug: read line: Hello, world
^C

It is important that the k8048 board is set to the PROG. mode when writing to the chip and set to the RUN mode when we want the pic to actually execute our code.

Two velleman supplied demos can also be found in the velleman directory which may be used to test a pic16f627 as per the kit documentation.

Below are some examples of using the other commands available in k8048:

beethoven:/var/tmp/k/k8048/k8048> k14 i
[2000] [USERID0]  ff .
[2001] [USERID1]  ff .
[2002] [USERID2]  ff .
[2003] [USERID3]  ff .
[2006] [DEVICEID] 07a0 DEV:7a0 (3d) REV:0 PIC16F627
beethoven:/var/tmp/k/k8048/k8048> k14 c
[2007] [CONFIG] 3f61

Code protection for 2k program memory:
        [CP] Program memory code protection off

Code protection for 1k program memory:
        [CP] Program memory code protection off

        [DATA_CP] Data memory code protection off

        [LVP] Low voltage programming disabled

        [BODEN] Brown-out detect reset enabled

        [MCLRE] MCLR enabled

        [PWRTE] Power-up timer enabled

        [WDT] Watchdog timer disabled

Oscillator selection:
        [XT] 001
beethoven:/var/tmp/k/k8048/k8048> k14 e
[2100] 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 0a 00 ff ff Hello, world....
[2110] ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
[2120] ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
[2130] ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
[2140] ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
[2150] ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
[2160] ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
[2170] ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
beethoven:/var/tmp/k/k8048/k8048> k14 f
[0000] 2855 3fff 3fff 3fff 285a 3020 00a0 01a1
[0008] 0ba1 2808 0ba0 2807 0008 3000 00a2 01a3
[0010] 1f06 0008 0ba3 2810 0ba2 280f 0008 3000
[0018] 00a2 01a3 1b06 0008 0ba3 281a 0ba2 2819
[0020] 0008 00a4 1406 200d 1786 2017 1386 3008
[0028] 00a5 200d 0103 0ca4 1c03 3080 0086 2017
[0030] 0ba5 2829 1006 0008 1683 009b 1283 3002
[0038] 2021 1683 141c 081a 0a9b 1283 3800 1903
[0040] 2843 2021 2839 3003 2021 0008 1283 3007
[0048] 009f 1683 118e 018b 3080 0081 3040 0086
[0050] 30ff 0085 1283 0186 0008 2046 3000 2034
[0058] 2005 2856 0009 3fff 3fff 3fff 3fff 3fff

As you may see, the number of functions available are not comprehensive yet satisfy my need for interaction with the PicMicro at this time. Any new features can be added should they be deemed worthy and of course some features may change.

Update: New options have been added to remove write protection, update the OSCCAL and update bandgap bits on 14 bit word devices. Refer to the in-built help text for more details.

I hope you enjoy using this application, good luck.

Table of contents
Version 1.7 by Darron Broad © 2005 - 2007 Valid HTML 4.01!