2

I've been searching for some information regarding microcontroller programming but the info I find is either way over my head or doesn't appear to exist. I'm looking for something easier to digest! I'm relatively new to programming and come from an SQL DBA background and decided that it would be quicker for me to learn some programming fundamentals and then teach myself Delphi than it would to get some changes implemented through my company's insane design change note system! After a couple of years of Delphi programming I can cope with writing database applications without too much bother and I want to be able to move on a level. We use PIC microcontrollers on our PCBs; mainly the PIC18F family. The software on the PICS is written in C but there are parameters values that are written to by a Delphi application that interface with the PIC using an ActiveX control. Basically, SQL Database holds parameter info, Delphi client app retrieves those values, passes them to the ActiveX controll which does all the low level stuff on the PIC. For example the internal EEPROM will have a map and within any particular address a value will be stored to switch something on or off or hold an integer value etc. I've gotten hold of an MPLAB kit which has an ICD2 device that can read and write values to the internal EEPROM and I understand how to change these hexadecimal values using MPLAB software. My hope isn't to learn embedded microcontroller programming; rather that I can write a Delphi app that will do something similar to MPLAB software. E.g read and write values to certain memory addresses within the EEPROM. I'd be very gratefull if anyone can point me in the right direction of any libraries or components that may already exist for bridging this gap between simple Delphi form application and writing low level PIC EEPROM. I doubt such any easy interface exists but I thought I'd ask. To summarise I want to be able to have a simple form app, with some edit boxes that the user types in or selects from dropdown boxes, parameter values, to click on a button and to assign those parameter values to specific EEPROM memory addresses. Thank you for reading and any comments would be gratefully received.

Regards

KD

kvnDalley
  • 21
  • 2
  • 5
  • What exactly did you intend to accomplish by making the interface to the high level system (a PC) so low-level in nature? (Write directly to EEPROM addresses.) The usual technique is to abstract away those details, and provide a high level interface tailored to the real functionality (turn LED on, turn LED off, etc etc). – Warren P May 29 '12 at 00:34
  • icd 2 uses usb, and usb hid mode was discussed in [link]http://stackoverflow.com/questions/6271421/using-hidcontroller-on-delphi-2010[/link] . – Hendra May 29 '12 at 03:44
  • BTW, you said '...The software on the PICS is written in C but there are parameters values that are written to by a Delphi application that interface with the PIC using an ActiveX control.' If that is the case, you can reuse the activex control (i.e. component--> import activex component from Delphi iDE), and use it in your Delphi app. I guess the low-level communication stuff has been dealt with the activex control ? – Hendra May 29 '12 at 04:01
  • Did you ever try out mikroC? http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/ – jimsweb May 29 '12 at 04:49
  • There is a sample project about using Delphi and 18f4550 pic doing DAQ via usb [link]http://www.sixca.com/eng/articles/usbdaq/index.html[/link] I think this might interest you. – Hendra May 29 '12 at 05:55

5 Answers5

2

Updated 2015 Answer:

Why not a Raspberry Pi with FreePascal and Lazarus? The boards cost from $5 to $25 US, as of this date, and the development tools are free.

Original 2012 Answer: If you like to use Pascal, you might find Free Pascal useful on small embedded systems, but the minimum I believe you will find it can compile on is a Linux-based ARM embedded system. The fact that you use pascal on both sides is very unlikely to help you accomplish anything major.

If you want to go all the way down the the smallest PIC microcontrollers, you'll find that it's almost always a variant of C that you'll be using. Frankly, at that level, the differences aren't that much. If you can write Pascal, you can learn enough C in a day, to use with microcontrollers.

Don't be scared to use the native language that most microcontrollers support. My personal favorites are the Rabbit microcontrollers, formerly from Z-World, now from digi -- I think I paid about $100 US for the first board and development toolkit.

Interfacing such an application with delphi is pretty easy, usually these days, I would interface using TCP/IP over either wired Ethernet, or wireless (Wifi). But if you really want to you could use RS-232 or RS-485 serial links. (RS-485 has the advantage that you can wire it up to 5 miles long.) If I was using a serial link, I'd probably implement something like Modbus on both sides, if I just wanted to send some numeric data back and forth, and if I was doing something text-oriented, I think I'd write a mini HTTP web server on the embedded controller, and most boards these days come with enough HTTP server demos to make that drop-dead easy.

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • ModBus uses 9-bit data. Can Delphi handle that? Is there a (free) VCL component necessary? Or a driver for the 9-bit serial port? – Mawg says reinstate Monica Nov 27 '15 at 09:57
  • 1
    Your other question is about something that is definitely not modbus. http://stackoverflow.com/questions/14212660/how-to-access-my-9-data-bit-serial-port-on-a-pc – Warren P Nov 27 '15 at 12:32
  • 1
    Reading your other question, I believe you would be better off finding an external piece of hardware that will convert from the extremely ODDBALL EIA=485/MDB "9 bit" mode. Only the vendor insane enough to use such a crazy arrangement will know where to get such an insane piece of hardware. The MDB engineer who made the decision to use 9 bit mode for your vending machine communication system should be shot and pissed upon, and let his name be anathema. – Warren P Nov 27 '15 at 12:40
  • Oops, sorry, I meant MultiDrop bus, not MOdBus. I heartily agree with your comments, but am restricted to MDB (I can't even use CCtalk) – Mawg says reinstate Monica Nov 28 '15 at 16:53
  • 1
    Glad you figured that out. Modbus is often used over EIA-485 (RS-485) multi-drop electrical signalling, and so I can see how you would get confused. Also, Modbus is used for single-master multiple-slave (multi-drop) communication, but it is most widely used in factory automation PLC and electrical/power control systems (RTU). – Warren P Nov 28 '15 at 18:16
  • The confusion was just that I dropped the Atmel project a few years ago & have just decided to rebirth it on the Raspberry Pi/ My addled old brain mixed the two up (as I had used ModBus on other projects). Apologies if my confusion confused other readers of this question. Would it be better if I delete my comment(s)? And do you know of any useful MDB stuff for Delphi? – Mawg says reinstate Monica Nov 29 '15 at 15:49
  • 1
    No. I have never encountered MDB before, and I have 20+ years professional experience in embedded serial-communications, so that means it's probably ONLY used by your vending machine industry and as such, counts as a technological cul-de-sac. These comments may help other people in future, or we can delete them all. Not sure. – Warren P Nov 30 '15 at 14:32
2

I'm a big fan of MikroElectronika and have used their Pascal tools for pic16 series MCU with great success (touch screen interfaces, ZigBee, ...). http://www.mikroe.com/

  • Nice, but it's $250 for a Pic or AVR pascal compiler. Too bad there isn't an open source Pascal for PIC and AVRs. Of course, compared to Delphi, that's cheap, but then compared to actually how much comes in the box for $250, it's actually quite expensive. – Warren P Jun 01 '12 at 19:52
  • "Download and try out the software - FOR FREE! Software is equipped with fully functional demo license with up to 2K of program words of output code size which can be just enough for simple applications." Admittedly I did end up buying one of their full development boards since one of my early applications (zigbee wireless race timing system) needed more than the 2k size of the free version. – Anthony Eischens Jun 27 '12 at 19:24
  • 1
    These days, I think I'd get one of those 5 dollar US raspberry Pi boards and use FreePascal. – Warren P Nov 27 '15 at 14:04
  • 1
    @WarrenP I would be tempted to do that as well but for any project producing a decent number of units, the 8-bit PIC series start in the $0.35USD/unit range and still have a place. – Anthony Eischens Dec 02 '15 at 17:18
  • 1
    That's true, and the other thing in favor of a PIC solution is that the Pi board and Raspbian are a lot more complex and therefore, can fail in a lot more weird ways. I have a coffee roaster at home that is 8-bit PIC microcontrolled, and I'm glad it's not running on a Pi. In embedded systems, Complexity is like an excitation field that just begs Entropy to step in and have something Weird/Bad happen. – Warren P Dec 02 '15 at 17:49
  • 1
    I just downloaded their mikroPascal Pro demo/trial, and using Spy I can see that this is written in Delphi and is using the AutomatedQA docking library (TaqDockingControl). – Warren P Dec 02 '15 at 17:56
0

Delphi outputs Win32 and Win64 native applications you can write software that can interact with certain devices if the PCB has serial comunication or I2C you can write software that in Delphi that it will interact with the physical device.

But if you want to programm the devices yourself , write software that will run on this devices you can't do it in Delphi. I suggest you buy an Arduino it's an excellent envoirment for beginners in microcontroller programming.

opc0de
  • 11,557
  • 14
  • 94
  • 187
0

If you have the source code of your pic microcontroller then you can implement the code in C to read from Serial, USB or some other interface available in your hardware and write it to the eeprom. This way its easy to write the app in any high level language like delphi, c++, etc.

Or you can write your PIC application using the mikropascal compiler from mikroeletronika that its very good and I've been using for a long time, but as you can see you will have to implement some mecanism to read from the interface and write to your eeprom as I've mentioned before.

This compiler comes with a lote of librarys to work with many devices. You should take a look on it, its not free but the price is low and in their site you can find samples and sample boards to test it.

Diego Garcia
  • 1,134
  • 1
  • 12
  • 25
0

One option, if you want a simple interface to write to the PIC EEPROM, is to use the ICD command line utility. Unfortunately it is not available for the ICD2, but the PICkit 2 and 3 (which are cheap), ICD3, and RealICE have command line utilities that give you the ability to write to the EEPROM (google pk2cmd). In Delphi, you could just wrap a very simple set of command line calls to pk2cmd.

Nathan Wiebe
  • 794
  • 5
  • 12