Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:39 05 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Cfunction

Author Message
tantay
Newbie

Joined: 30/10/2016
Location: Vietnam
Posts: 15
Posted: 07:16am 17 Nov 2016
Copy link to clipboard 
Print this post


Hi everyone!

I'm try on convert Cfunction to MMbasic but when use it in MMEdit then notify Unknown command.

I'm write simple Function to test convert:

//#define _DISABLE_OPENADC10_CONFIGPORT_WARNING
#define _SUPPRESS_PLIB_WARNING

#include <plib.h>
#include "cfunctions.h"

#pragma config JTAGEN = OFF


long long set_pinout(unsigned int *pin)
{
ExtCfg(*pin, EXT_DIG_OUT, 0)
}

void main(){}

I do same thread :http://www.thebackshed.com/forum/forum_posts.asp?TID=7965

Help me.
Thanks all read.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4034
Posted: 07:42am 17 Nov 2016
Copy link to clipboard 
Print this post

You sound not to have followed the tutorials e.g. that you haven't used MPLABX / compiled the Cfunction.

John
 
tantay
Newbie

Joined: 30/10/2016
Location: Vietnam
Posts: 15
Posted: 03:48pm 17 Nov 2016
Copy link to clipboard 
Print this post


Hello John

I was setup MPLabX V3.10 and XC32 v1.33. I'm create Project with MPLabX and build successful when convert to MMbasic no error but when use it in MMEdit then notify Unknown command.

Thanks
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1000
Posted: 05:16pm 17 Nov 2016
Copy link to clipboard 
Print this post

Tantay,

Your C function does not return anything so I am guessing you are probably calling it like a sub.
e.g
set_pinout(x)
This will give an 'unknown command error.
y=set_pinout(x) is how you call a function.





When you convert to MMBasic select the CSUB option instead of CFUNCTION
and you will get something like below.
'
CSUB set_pinout
00000000
3C03BF81 8C65F220 3C020661 7CA5D800 3444A053 50A40009 2402002C 8C64F220
2443A053 7C84D800 00832026 2402001C 2403002C 0064100A 3C03BF81 8C66F220
8C64F220 3C030580 3463A053 7CC6D800 00C33026 24050040 7C84D800 24631000
10830006 00A6100A 00022FC3 00402021 00801021 03E00008 00A01821 24040064
00002821 00801021 03E00008 00A01821
End CSUB

This can be called as a Sub. e.g.
set_pinout(x)

We can help a lot easier if you post the MMBasic code.

Regards
Gerry


Latest F4 Latest H7 FotS
 
tantay
Newbie

Joined: 30/10/2016
Location: Vietnam
Posts: 15
Posted: 06:06pm 17 Nov 2016
Copy link to clipboard 
Print this post


Hello Gerry
Thanks Gerry help me.

I'm convert using CFGEN.EXE but I don't see choose CSUB or CFUNCTION.Software CFGEN.EXE I download in forum.



Thanks.
Edited by tantay 2016-11-19
 
tantay
Newbie

Joined: 30/10/2016
Location: Vietnam
Posts: 15
Posted: 06:53pm 17 Nov 2016
Copy link to clipboard 
Print this post


Hello Gerry

I edit code: return 0 for function set_pinout

#define _DISABLE_OPENADC10_CONFIGPORT_WARNING
#define _SUPPRESS_PLIB_WARNING

#include <plib.h>
#include "cfunctions.h"

#pragma config JTAGEN = OFF


long long set_pinout(unsigned int *pin)
{
ExtCfg(*pin, EXT_DIG_OUT, 0);
return 0;
}


void main(){}

And convert using CFGEN.EXE



program MMedit:

OPTION EXPLICIT
OPTION DEFAULT NONE
cpu 40
pause 50


CONST SDA = 24 'SDA of FT6206


dim i% = set_pinout(24)

do while(1)

loop
end


CFunction set_pinout
00000000
27BDFFE8 AFBF0014 AFBE0010 03A0F021 AFC40018 3C029D00 34420010 8C420000
8FC30018 8C630000 00602021 24050008 00003021 0040F809 00000000 00001021
End CFunction

When load program in to microcontroller then error




Thanks all
Edited by tantay 2016-11-19
 
tantay
Newbie

Joined: 30/10/2016
Location: Vietnam
Posts: 15
Posted: 09:01pm 17 Nov 2016
Copy link to clipboard 
Print this post


Thanks all help
I was successful not error but program don't work

OPTION EXPLICIT
OPTION DEFAULT NONE
option autorun on

cpu 40
pause 50

CONST SDA = 24 'SDA of FT6206
CONST SCK = 27 'SCK of FT6206


dim i% = set_pinout(SCK)

do while(1)
PIN(24)= 1
PAUSE 1
PIN(24) = 0
PAUSE 1
loop
end

CFunction set_pinout
00000000
27BDFFE8 AFBF0014 3C029D00 8C420010 8C840000 24050008 0040F809 00003021
00001021 00001821 8FBF0014 03E00008 27BD0018
End CFunction

Edited by tantay 2016-11-19
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10202
Posted: 09:58pm 17 Nov 2016
Copy link to clipboard 
Print this post

  Quote  Thanks all help
I was successful


Well done

For future reference you need to be careful with plib

You can only use plib calls that are implemented as #define in the appropriate plib header file. Anything that is implemented as an actual subroutine will fail as the CFunction can't link the subroutine.

Also in your code above the pragma can't be used as this sets config bits in the processor and is only relevant when the chip is flashed.

Finally, do make sure you have all the compiler and linker settings set up as defined in the tutorials
 
tantay
Newbie

Joined: 30/10/2016
Location: Vietnam
Posts: 15
Posted: 10:16pm 17 Nov 2016
Copy link to clipboard 
Print this post


Hello Matherp and Gerry

I'm try on write I2C software talk with FT6206 touch controller. I refer one article in forum but when convert to MMbasic then Error and i don't talk with FT6206

this is project

2016-11-18_081543_CapTouch.X.zip

The optimization level is set to 1 and add "-fPIC -mno-abicalls" under "XC32(Global Options)"
Help me
Thanks all
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10202
Posted: 12:00am 18 Nov 2016
Copy link to clipboard 
Print this post

Your issue is that you can't call one routine from another. Do read all the tutorials to see how I do it.

All calls must go through "main" which than acts as a switch to call the other routines. CFGEN is then used in "merge" mode to create a single CFunction with a single entry point.

In 5.3 it will be possible to write loadable drivers for touch as well as for displays. I've already done this for a client using the FT6206 and a modified version of 5.2. Geoff is including the hooks for this in 5.3

Tutorial 1

Tutorial 2

Tutorial 3

Tutorial 4 Edited by matherp 2016-11-19
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025