![]() |
Forum Index : Microcontroller and PC projects : uM2(+): CFunctions
![]() ![]() |
|||||
Author | Message | ||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2950 |
Hey Jim, Showing my ignorance here... but as an idea do you think you might be able to modify MMEdit to effectively put "inline C" into a MMBasic program? I dont talk C (yet.... I am going to have another go at learning it --- any one suggest a good book for dummies like me?) so I cant really say if that idea is even feasible of practical. Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Short answer is no. CFUNCTIONS or any other C code for the uM really needs a compiler such as MPlab and all the support libraries. A good place to start is with Pelles C. Free and plenty of documentation. http://www.pellesc.de/ or http://www.smorgasbordet.com/pellesc/index.htm Just don't ask me to explain any of it... Jim VK7JH MMedit |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Jim All looks good and the output checks out perfectly on all my tests - great work. I can't see any reason for a command line input given the GUI Would you post the code? I'd really like this version to be completely open source even though most people won't have access to Purebasic Peter |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
If you want to do something like that you would need something like a 'Project File'. You could then include the C files in a 'Project Explorer' and edit them from MMEdit. A Project file could be simple, just a list of files. I think the compiler can be run from the command prompt, just needs the right make file/batch file. An option to 'Compile' would then just be running that batch file. If the batchfile can control where the output of the files go, then that could be a parameter. Maybe someone with more knowledge asbout running a compile from the command prompt can help with that. I am not sure if it is that useful as most CFunctions are library functions better made in their own programming environments. It would be nice though to link the source code (maybe readonly) of those CFunctions in a project. Just to keep everything in one place. Microblocks. Build with logic. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Would you post the code? I'd really like this version to be completely open source even though most people won't have access to Purebasic Peter Yes. I need to clean up some of the 'types' and put some more comments. Also change some globals to locals etc. I need a day or two - need another rainy day. You will find that I haven't changed to main code much from your MMBasic version. You can get a free demo copy of Purebasic to play with. I forget what the restrictions are. Jim VK7JH MMedit |
||||
Chris Roper Senior Member ![]() Joined: 19/05/2015 Location: South AfricaPosts: 280 |
I can't suggest a book as such but I can suggest you try the ChipKIT platform. It is PIC32MX based so you already know the architecture and probably have a board capable of running it. If not you can quickly build up my breadboard ChipKIT http://caroper.blogspot.co.za/2013/06/this-will-be-home-for-my-pic32mx.html It is Arduino Style, but can be plain C if you ignore the Arduino Libraries. Access to the Libraries helps get you started, and there is lots of Example code to study. Cheers Chris http://caroper.blogspot.com/ |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
This should be the final version of cfgen.exe although I will change the icon eventually. No changes to functions but code tidied up. The ZIP also includes the source code for anyone interested. 2015-09-10_220228_cfgen.zip I will be adding the program to the MMEdit setup file in the next update. Jim VK7JH MMedit |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Jim Many many thanks - much less "clunky" than my version ![]() Peter |
||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2950 |
Hi Jim, All, Short answer is no. CFUNCTIONS or any other C code for the uM really needs a compiler such as MPlab and all the support libraries. I told you I was showing my ignorance.. OK I understand, you would have to recreate all of the compiler functionality into MMEdit... Yep ! Understand (sort of) now Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1003 |
CFGEN update to switch between CFUNCTION and CSUB Not sure if CFGEN.EXE has changed since this thread, but attached is an update with source that allows the selection of CFUNCTION or CSUB as the output. 2016-02-23_113328_CFGEN120.zip My first dabble with PureBasic after many years of VB3 and VB6. I never really tackled VB.NET, seemed too convoluted, but PB seems like a good thing. Thanks Jim for the introduction. The demo version can handle this source OK. Regards Gerry Latest F4 Latest H7 FotS |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Gerry Jim is just finishing a significant update to CFGEN to incorporate new functionality in the interpretation of the .ELF file so your changes would need folding into that. Can I suggest you liaise with him direct by PM Thanks Peter |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I was going to ask about CSUB/CFUNCTION differences. I have added the option to choose either. I have assumed that the only difference as far as cfgen is concerned is the sub/function labels. This update to cfgen also includes the changes that Peter referred to above. Usage is the same as previous versions. I will leave the changes in creating the ELF files to Peter to explain. The ZIP includes the exe file and the PureBasic source. AS usual, the code is a conversion from Peters BAS file. 2016-02-23_213203_cfgen.zip Jim VK7JH MMedit |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
AS usual, the code is a conversion from Peters BAS file. QUOTE] @Jim. very appreciated! Thanks! ![]() Michael causality ≠correlation ≠coincidence |
||||
MustardMan![]() Senior Member ![]() Joined: 30/08/2019 Location: AustraliaPosts: 175 |
... I have assumed that the only difference as far as cfgen is concerned is the sub/function labels. Sorry for rehashing an old thread, but there isn't much talk about what the differences actually are. Is the only difference down to whether basic will treat it as a 'command' (on the left side eg: ClearDisplay(colour) ) or a 'function' (on the right side eg: x=Temperature) Unfortunately P.Mathers most excellent tutorial on CFunctions does not mention CSubs at all, or how to go about creating one, and I can't find any examples (with the C source included - only pre-compiled hex). Cheers, |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
The only difference between a CSUB and a CFUNCTION is whether the C code returns a value. In CFGEN you then select whether you want a CSUB or a CFUNCTION and it puts the appropriate header on the code. Lots of older code will appear as CFUNCTIONS even though they don't return anything because they pre-date the inclusion of the CSUB in the MM firmware. e.g. CFUNCTION shellsort long long shellsort(long long a[], long long *nn) { long h, l, j, n=*nn; long long k; for (h = n; h /= 2;) { for (l = h; l < n; l++) { k = a[l]; for (j = l; j >= h && k < a[j - h]; j -= h) { a[j] = a[j - h]; } a[j] = k; } } return 0; } should be CSUB: void shellsort(long long a[], long long *nn) { long h, l, j, n=*nn; long long k; for (h = n; h /= 2;) { for (l = h; l < n; l++) { k = a[l]; for (j = l; j >= h && k < a[j - h]; j -= h) { a[j] = a[j - h]; } a[j] = k; } } } You can use CSUB on a routine that returns a value in which case the return is just ignored. NB: re PM the scroll demo is very old and pre-loadable drivers. The source is long gone - sorry. Edited 2020-04-25 20:36 by matherp |
||||
MustardMan![]() Senior Member ![]() Joined: 30/08/2019 Location: AustraliaPosts: 175 |
Thanks for the clarification Peter, and no worries about the scroll demo C source. Cheers! |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |