Recent

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

xterro

  • New member
  • *
  • Posts: 9
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #165 on: May 24, 2018, 06:53:47 am »
Thank you for your work  :)

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #166 on: May 24, 2018, 11:00:37 pm »
Thanks Edson, for your work ! I love PIC !!
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #167 on: June 03, 2018, 01:53:10 pm »
Does PicPas compiler support the ENHANCED MID-RANGE CPU like 16F1825 ?
If yes, I would like to help you and write the description file for this PIC (PIC16F1825.pas)
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #168 on: June 03, 2018, 05:03:00 pm »
Thanks Edson, for your work ! I love PIC !!
You're welcome.

Does PicPas compiler support the ENHANCED MID-RANGE CPU like 16F1825 ?
No yet. It's the next step. PicPas have now, the ability to support multiple PIC compilers in the same IDE, so it's not dificult to include a compiler for this family. The hard work would be to update some routines in the Code Generator and in the Real-time simulator.

If yes, I would like to help you and write the description file for this PIC (PIC16F1825.pas)
You can write the description file now and so, you are helping to have support for the Enhanced Mid-range family. It would be better if you write hardware description for: PIC16F1454 PIC16F1455 PIC16F1459 PIC16F1503 PIC16F1507 PIC16F1508 PIC16F1509 PIC16F1512 PIC16F1513 PIC16F1516 PIC16F1517 PIC16F1518 PIC16F1519 PIC16F1526 PIC16F1527 PIC16F15313 PIC16F15323 PIC16F15324 PIC16F15325 PIC16F15344 PIC16F15345 PIC16F15354 PIC16F15355 PIC16F15356 PIC16F15375 PIC16F15376 PIC16F15385 PIC16F15386 PIC16F1574 PIC16F1575 PIC16F1578 PIC16F1579 PIC16F1613 PIC16F1614 and some others.

Then we need ASM routines for some logical and arithmetic operations.
« Last Edit: June 03, 2018, 05:18:38 pm by Edson »
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #169 on: June 03, 2018, 05:15:03 pm »
Ok, I'll do what I can. It's a good project !
How do you set the config bit for the PIC ? I can't found any example in the sample folder
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #170 on: June 03, 2018, 05:32:54 pm »
How do you set the config bit for the PIC ? I can't found any example in the sample folder

You need to use the directive $CONFIG. You can use the value directly:

Code: Pascal  [Select]
  1. {$CONFIG $3FFD}

But it's better to include macros in the description file:

Code: Pascal  [Select]
  1. {$define _CP_ON       =     0x000F}
  2. {$define _CP_OFF      =     0x3FFF}
  3. {$define _WDT_OFF     =     0x3FFB}
  4. {$define _LP_OSC      =     0x3FFC}
  5. {$define _XT_OSC      =     $3FFD}
  6.  

So we can use them in $CONFIG:

Code: Pascal  [Select]
  1. {$CONFIG _CP_OFF, _XT_OSC, _WDT_OFF }
  2. {$CONFIG _CP_OFF _XT_OSC _WDT_OFF }

Check the units in the folder "/device10" or "/device16" as an example.

IIRC in the ENHANCED MID-RANGE CPU we have until two config words. I think we can add a new directive, some like {$CONFIG2}
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #171 on: June 05, 2018, 10:01:29 pm »
Thanks for the precisions.
One more question... Did you take in account the ID Locations of the PIC ? I see that it not appear in the description of the 16F877 (for example). If you tell me you ignored it, I will ignore it too.
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #172 on: June 06, 2018, 01:13:12 am »
PicPas doesn't use the PIC ID. I haven't found a necessity for the device ID. Probably it could be useful when including burning software.

Maybe you can define the ID in some variable, like:

Code: Pascal  [Select]
  1. {$SET PIC_ID  = 0x3027}

Later we can use that information in some application.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #173 on: June 06, 2018, 08:31:35 pm »
Ok Edson. I'm too busy at this time, so I go slowly on the description files asked...
In fact, I'm trying to develop a program to automate the task as much as possible from existing include files. :-X
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #174 on: June 06, 2018, 10:26:36 pm »
Ok Edson. I'm too busy at this time, so I go slowly on the description files asked...
In fact, I'm trying to develop a program to automate the task as much as possible from existing include files. :-X

No problem. It will take some time to me too, to rewrite the new compiler for the Enhanced Mid-range devices.

Now I'm working on improving the debugger/simulator of PicPas in order to have a fast way to execute the test code. This will help too to test the Enhanced Mid-range compiler.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #175 on: June 08, 2018, 03:36:20 pm »
I noticed that in the file PIC16F877.pas (my reference to understand how to declare a pic) there is the line:
Code: Pascal  [Select]
  1. {$SET_UNIMP_BITS '000:00'} // INDF
After some search in the datasheet, I found 'reading the INDF register itself, indirectly
(FSR = '0') will read 00h'. That's why you add this line?

second question: in PIC16F877.pas again, section  Configuration Bits:
Code: Pascal  [Select]
  1. // WDTE : Watchdog Timer Enable bit
  2.   {$define _WDTE_ON      = $13BFF}  // WDT enabled
  3.   {$define _WDTE_OFF     = $3BFF}  // WDT disabled
  4.  
  5.   // FOSC : Oscillator Selection bits
  6.   {$define _FOSC_EXTRC   = $63BFF}  // RC oscillator
  7.   {$define _FOSC_HS      = $43BFF}  // HS oscillator
  8.   {$define _FOSC_XT      = $23BFF}  // XT oscillator
  9.   {$define _FOSC_LP      = $3BFF}  // LP oscillator
  10.  
There are masks on 5 digits but the configuration register is on 14 bits ... is this an error?
« Last Edit: June 08, 2018, 05:17:16 pm by Lulu »
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #176 on: June 08, 2018, 08:04:27 pm »
I noticed that in the file PIC16F877.pas (my reference to understand how to declare a pic) there is the line:
Code: Pascal  [Select]
  1. {$SET_UNIMP_BITS '000:00'} // INDF
After some search in the datasheet, I found 'reading the INDF register itself, indirectly
(FSR = '0') will read 00h'. That's why you add this line?
Well. I haven't written this files. They are part of some collaboration. But I guess the idea of setting 0x000 as "Unimplemented" is because INDF is not implemented as a register.
The information about unimplemented bits, is used for the compiler when find free space.
But it's more useful for the simulator, to know how it will be the result when reading some special bytes.

Anyway it's not a problem in the Baseline, and Mid-range compilers  because they know that reading the INDF address is an indirect addressing.

Actually, I don't know how the PicPas simulator respond when trying to read INDF indirectly. I will test.

Don't forget directive {$SET_UNIMP_BITS} set bits to be read always as 0.
If you need to set bits to be read always as 1, you need to use {SET_UNIMP_BITS1}

PicPas is accurate in defining the state of every bit of the hardware. That's a difference from other simulator like Proteus, what is incapable of simulate the state of unimplemented bits and can give wrong results in some simulations.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Edson

  • Hero Member
  • *****
  • Posts: 1044
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #177 on: June 08, 2018, 08:36:49 pm »
second question: in PIC16F877.pas again, section  Configuration Bits:
Code: Pascal  [Select]
  1. // WDTE : Watchdog Timer Enable bit
  2.   {$define _WDTE_ON      = $13BFF}  // WDT enabled
  3.   {$define _WDTE_OFF     = $3BFF}  // WDT disabled
  4.  
  5.   // FOSC : Oscillator Selection bits
  6.   {$define _FOSC_EXTRC   = $63BFF}  // RC oscillator
  7.   {$define _FOSC_HS      = $43BFF}  // HS oscillator
  8.   {$define _FOSC_XT      = $23BFF}  // XT oscillator
  9.   {$define _FOSC_LP      = $3BFF}  // LP oscillator
  10.  
There are masks on 5 digits but the configuration register is on 14 bits ... is this an error?
Strange. They seem to be clearly an error. I will ask to the person who made this file.
Lazarus 1.6 - FPC 3.0.0 - x86_64-win64 on  Windows 7

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #178 on: June 08, 2018, 09:06:14 pm »
I picked up some file randomly in 'device16' folder and it seems they are other files with the same error, like 16F874.

About the {$ SET_UNIMP_BITS} and {SET_UNIMP_BITS1} directives, it's an elegant way to specify bits !
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)

Lulu

  • Full Member
  • ***
  • Posts: 112
Re: PicPas, Pascal compiler for Microchip PIC
« Reply #179 on: June 09, 2018, 12:20:28 am »
I noticed another problem: I'm working on PIC16F1454.pas as you asked.
This pic has two configuration word located at adresses $8007 and $8008.
The PIC16F877 has only one configuration word located at $2007.
How do you specify the adress of the configuration word ? I don't see it in existing description files.
fpc 3.0.4 Lazarus 1.8.0  -  AMD A8-6600K  -  Windows 10  64bits
bad english... sorry :)