Recent

Author Topic: PicPas, Pascal compiler for Microchip PIC  (Read 114877 times)

Edson

  • Hero Member
  • *****
  • Posts: 1296
PicPas, Pascal compiler for Microchip PIC
« on: April 21, 2017, 06:08:39 am »
PicPas 0.5.1 is my new compiler for Microchip small devices (16F PIC microcontrollers)  :D.

https://github.com/t-edson/PicPas

By the moment, there are only limited functionalities. Only the bit, byte and boolean types are supported, and a few operators are implemented.  :-[

A small IDE is included with the compiler.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #1 on: April 21, 2017, 08:30:00 am »
PicPas 0.5.1 is my new compiler for Microchip small devices (16F PIC microcontrollers)  :D.
Congratulations!

As I see this is just a beginning... You have a lot of work in front of you.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #2 on: April 21, 2017, 09:42:07 am »
It is very nice project maybe you want to look at that project too:

https://github.com/jallib/jallib

I used once for a project but I think it is not full open source project.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #3 on: April 21, 2017, 10:59:15 am »
Cool project.

I'm working on my very own compiler for the Z80 microprocessor, but I didn't tell anything because it only extracts tokens telling what they are, no code generated yet.

I've briefly look at your code and I must to say that it was ingenious to use SynEdit parser.  I'll write it my own.
« Last Edit: April 21, 2017, 11:05:50 am by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #4 on: April 21, 2017, 06:01:18 pm »
Congratulations!
As I see this is just a beginning... You have a lot of work in front of you.

Thanks.
Yes. There is a lot of work in front, and there is a lot of word done: Several libraries, frameworks, design and docs. The design is very important for this kind of projects.

I will be publishing my advances.

It is very nice project maybe you want to look at that project too:
https://github.com/jallib/jallib
I have seen something about the JAL project. There were some things I didn't like of JAL. I will check again.

« Last Edit: April 21, 2017, 06:03:27 pm by Edson »
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #5 on: April 21, 2017, 07:25:40 pm »
Congratulations ;D ;D

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #6 on: April 22, 2017, 03:20:12 am »
Congratulations ;D ;D

Thanks. It's really hard to make a functional compiler, especially for a limited architecture like this.

I'm working on my very own compiler for the Z80 microprocessor, but I didn't tell anything because it only extracts tokens telling what they are, no code generated yet.

Good. Z80 is one of my favourites CPU. Although I have worked a lot with the 6502 CPU, in the Commodore 64. I remember, I wrote a very simple, and low level compiler in BASIC, for this CPU. Some routines of this compiler were "compiled" by the same compiler.  %) Sadly, the code has gone with my audio-tapes.  :'( Maybe I can rewrite this, in FPC.

I've briefly look at your code and I must to say that it was ingenious to use SynEdit parser.  I'll write it my own.
Maybe, you can use the lexer of PicPas, and some of its libraries, like T-Xpres (https://github.com/t-edson/t-Xpres) and SynFacilSyn. The code generator is some very complex module, and T-Xpres helps a lot on this case.

This project, really reuse the code, because the same lexer is used for the editor higjlighter and for the completion tool, too.

Tell me if you need some help on your compiler.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #7 on: April 22, 2017, 03:24:03 am »
Cool project.

I'm working on my very own compiler for the Z80 microprocessor, but I didn't tell anything because it only extracts tokens telling what they are, no code generated yet.

I've briefly look at your code and I must to say that it was ingenious to use SynEdit parser.  I'll write it my own.

There is experimental FPC branch for z80 here : http://svn.freepascal.org/cgi-bin/viewvc.cgi/branches/z80/?sortby=date&view=log

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #8 on: April 22, 2017, 02:00:37 pm »
Good. Z80 is one of my favourites CPU. Although I have worked a lot with the 6502 CPU, in the Commodore 64. I remember, I wrote a very simple, and low level compiler in BASIC, for this CPU. Some routines of this compiler were "compiled" by the same compiler.  %) Sadly, the code has gone with my audio-tapes.  :'( Maybe I can rewrite this, in FPC.

Maybe, you can use the lexer of PicPas, and some of its libraries, like T-Xpres (https://github.com/t-edson/t-Xpres) and SynFacilSyn. The code generator is some very complex module, and T-Xpres helps a lot on this case.

This project, really reuse the code, because the same lexer is used for the editor higjlighter and for the completion tool, too.

Tell me if you need some help on your compiler.
Thanks for the advices.  I'll work on it.

A C64 compiler would be nice too...

There is experimental FPC branch for z80 here : http://svn.freepascal.org/cgi-bin/viewvc.cgi/branches/z80/?sortby=date&view=log
:o
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #9 on: April 22, 2017, 02:14:03 pm »
Cyrax was a bit faster about the z80 branch :)

A C64 compiler would be nice too...
Plenty of them in the wild.
- Ruud's commodore site
- G-Pascal by nick gammon
- Others

Do realize that because of the available space (or lack thereof) most of those compilers made heavy use of macro's.
« Last Edit: April 22, 2017, 02:17:26 pm by molly »

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #10 on: April 22, 2017, 09:26:53 pm »
It would be nice for me, to do compilers for Z80 or 6502 (especially this), but there are, currently, many compilers developed.  Maybe it would be some experimental.

What I see is, the only 8 bits devices, widely used now, are the microcontrollers. And the 8 bits PICs are very used in this part of the world. This is one motivation on doing my compiler.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #11 on: April 30, 2017, 09:45:06 pm »
Hi Edson,
This is a fantastic choice, the PIC16x86 for a target. As good as it gets, really. This is the bread and butter chip used in most mass produced electronics products. THIS is the best choice for a 16 bit microcontroller for a multitude of reasons.

I am experimenting with an uploader/debugger/logic analyzer combination (for lack of a better term) utilizing the FTDI ft2232h chip. The idea is to enable something like PICPas to have a full Lazarus like "RAD" environment functionality. You will be able to compile/upload in one operation and utilize the integrated logic analyzer in-line as the ultimate debugger. It will enable you to "tap" actual pins on the PIC and map them to the logic analyzer, which is fully controlled by the PicPas GUI app as simple project settings, for example. So no more messing with breadboards. It's all safely done in a hands off fashion.

The FT2232h and the larger FT4232h can also be utilized in a loopback fashion as a stand-alone solution. You configure one serial port for uploading to the target PIC chip and utilizing MPSSE (GPIO functionality of the FT2232h via the D2xx.pas) you set up capture pins. This is all that PICPas really needs. Of coarse, this will require coding the logic analyzer in Pascal.

How about "Pascal hardware components"? The PIC16x86 looks like the perfect target chip for this. An example would be a linear actuator for a CNC. The PIC has properties and functions much like a visual component. You intitalize (create) it, then you pass opcodes as function/method arguments over the serial link for "moveto(300)". The PIC "component" handles things from here on. As far as a "programming style" goes, do a search on "Arduino firmata" to get an idea of the concept.

The logic analyzer I am working with is an amazing little FPGA design that is TOP NOTCH!! This puppy will capture at 200mhz and has a 64Mib buffer and 32 channels. The top of the line Saelae logic analyzer only captures 100mhz and only 16 channels... and will set you back $700.

The FPGA design is fully OpenSource and only use about 10% of the "fabric" on the Pipistrello FPGA board. Driving this board is a piece of cake over serial. It utilizes the SUMP protocol. All that is needed is a good TSignalDrawer component for Lazarus for drawing a nice GUI to round things out.

https://www.sigrok.org/blog/new-better-openbench-logic-sniffer

I am currently trying to get this same setup going with Professor Wirth's "PICL", which is his little PIC16C86 compiler. Have you seen it? Less than 800 lines of code including the uploading tools!

https://www.inf.ethz.ch/personal/wirth/PICL/index.html

Good luck with this!
« Last Edit: April 30, 2017, 11:15:58 pm by CaptBill »

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #12 on: May 01, 2017, 06:14:36 pm »
Hi Edson,
I am experimenting with an uploader/debugger/logic analyzer combination (for lack of a better term) utilizing the FTDI ft2232h chip. The idea is to enable something like PICPas to have a full Lazarus like "RAD" environment functionality. You will be able to compile/upload in one operation and utilize the integrated logic analyzer in-line as the ultimate debugger. It will enable you to "tap" actual pins on the PIC and map them to the logic analyzer, which is fully controlled by the PicPas GUI app as simple project settings, for example. So no more messing with breadboards. It's all safely done in a hands off fashion.

The FT2232h and the larger FT4232h can also be utilized in a loopback fashion as a stand-alone solution. You configure one serial port for uploading to the target PIC chip and utilizing MPSSE (GPIO functionality of the FT2232h via the D2xx.pas) you set up capture pins. This is all that PICPas really needs. Of coarse, this will require coding the logic analyzer in Pascal.


Well. PicPas is just beginning. The objective is to have a full compiler for the MicroChip series 12F, 16F and 18F.

The other objective is to include the control of the programmer and a device simulator. It is to compile, simulate and transfer, all in the same IDE. Including a debug tool is a great idea too.

The simulation is one of the feature I expect to implement first, because the libraries are designed for this. Anyway you are invited to colaborate . There are many things that can be implemented in this project.

I am currently trying to get this same setup going with Professor Wirth's "PICL", which is his little PIC16C86 compiler. Have you seen it? Less than 800 lines of code including the uploading tools!
https://www.inf.ethz.ch/personal/wirth/PICL/index.html

I didn't know about this project. After reading it, I must say, it's very similar to one project I made, a long time ago. I called it The "symbolic compiler", and was targeted to the micro MOS 6510.

It's a very basic compiler, implemented on the limitations of the PIC16C84. It is just a little high-level language for the assembler of this PIC, but probably no so useful for others PIC or more complex programs. Its advantage is to generate a very small code.
« Last Edit: May 01, 2017, 06:16:15 pm by Edson »
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

FPK

  • Full Member
  • ***
  • Posts: 118
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #13 on: May 01, 2017, 07:35:18 pm »
Why not extending FPC with a PIC backend? FPC has a full featured Object Pascal front end, so no need to bother with this part :D

Edson

  • Hero Member
  • *****
  • Posts: 1296
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #14 on: May 01, 2017, 09:04:26 pm »
Why not extending FPC with a PIC backend? FPC has a full featured Object Pascal front end, so no need to bother with this part :D

Well, I have no problem on include PicPas as a FPC backend  :). In fact, it was some sad to me, to see FPC cannot compile to this 8 bits small devices  :'(.

What do you refer with frontend? I don't really know about the design of FPC. :-[

I think, we need to consider that if FPC is going to enter to the embedded world:

1. There are very small devices, with just a few bytes of RAM and EEPROM. The common Pascal language have some limitation on this case.
2. The compiler have to be very efficient. Maybe the more advanced devices can support recursivity, objects or advanced features, but the smaller, cannot even support float numbers.
3. This kind of tools, usually are accompanied with software simulators, hardware debugger, burning software, ...

Anyway, I would love to see a FPC compiler for Microchip PIC  :D.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

 

TinyPortal © 2005-2018