Jump to content

joli

EstablishedMember
  • Content count

    85
  • Joined

  • Last visited

Everything posted by joli

  1. #include <system.h> typedef unsigned char uchar; void main() { uchar j=20; uchar i = (j/10); } Compiling the little snipet above under mplabx, it return errors like this: Error: Unresolved external function:'__div_8_8(unsigned char,unsigned char)' depending of the evaluated expression the error could be: Error: Unresolved external function:'__div_16_16(unsigned char,unsigned char)' Surprinsingly, the same not happens to 16/32 bit multiplications. The solution is to include libc.pic16.lib or libc.pic18.lib, depending the pic family we are using. This could be done, under mplabx/File/Project Properties. Now in the Project Properties Window, select Libraries and Add Library/Object File, choose <libc.pic1x.lib> and thats it. Alternately, it can be done following the procedure above but picking Linker instead Libraries and add <libc.pic1x.lib> in the Additional Options. P.S. the same procedure works with floats.
  2. Is there any trick for float lib to work with mplab x? The code below compiles ok in sourceboost editor but not in mplabx. #include <system.h> #include <float.h> void main() { float f = float32_mul(2.5, 2.5); } Here is some errors when compiling this code in mplabx ide: Error: Unresolved external function:'__mul_32_32(unsigned long,unsigned long)' ... same error above repeated n times ! Error: Unresolved external symbol, function:__mul_32_32 ... same error above repeated n times ! make[2]: *** [dist/default/production/float.X.production.hex] Error -2 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 BUILD FAILED (exit value 2, total time: 5s) float.pic18.lib was included as explained in the FoatMath.pdf page 9 PIC18LF67K40 / c++ pro licence / sourceboost 4.43 / mplab x 4.15
  3. Answering to my self. Its working now. Under mplabx the libraries should be added to the project through Project Properties and add it to BoostLink / Additional options. By the way, the compiler/linker finish the job in about 3 minutes > 72 module_files / 273 functions - 4 core, i7, 2.8GHZ, 16gb_ram The compiler takes 30 seconds. The rest of the time is spent by the linker (2.5 minutes)... It would be great if linker could be improved.
  4. Hi there, As far as I can see, J94 types are not supported and I have no idea if the compiler will continue to be upgraded or not. The 18(l)fxxk40 types, they are supported, but the header files are incomplete, so i wrote a simple tool to generate them from the "inc" files included in the mplabx/v4.10/mpasmx. I can put them here if the owners of sourceboost allow me to... i have no idea about legal stuff. Optionally it can be done by modifying the files provided by microchip, using an editor with macros in order to turn the job less painfull... for instance, p18lf67k40 has about 6700 lines. regards
  5. try this out instead of your #pragma's: // FUSES #pragma config OSC = INTOSCPLL // Internal osc PLL can be enable/disable #pragma config CP0 = OFF // Program memory is unprotected #pragma config FCMEN = ON // Enable osc monitor #pragma config WDTEN = OFF // Watchdog OFF #pragma config WDTPS = 512 // 1:512 #pragma config XINST = OFF // Disable extended instruction set (mandatory) #pragma config IOL1WAY = OFF // works either way
  6. There is a clean crc16 code, based in the example given in the sourceboost / examples, to all that needs it The code is working pretty well in a real app that uses several industrial modbus devices. // crc16 table hi/lo rom char *aucCRCHi = { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 }; rom char *aucCRCLo = { 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0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85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 }; uint CRC16( uchar *pucFrame, uchar usLen ) { uchar ucCRCHi = 0xFF; uchar ucCRCLo = 0xFF; uint iIndex; while( usLen-- ) { iIndex = ucCRCLo ^ *( pucFrame++ ); ucCRCLo = (uchar)( ucCRCHi ^ (uchar)aucCRCHi[iIndex] ); ucCRCHi = (uchar)aucCRCLo[iIndex]; } return (uint)( ucCRCHi << 8 | ucCRCLo ); } br
  7. This is another way of doing things instead of using objects as posted yesterday in http://forum.sourceboost.com/index.php?showtopic=5515 // file: students.h #ifndef _STUDENTS_H_ #define _STUDENTS_H_ typedef unsigned char uchar; #define STUDENTS 64 // S T U D E N T D A T A S T R U C T typedef struct { uchar s_id; // id uchar s_age; // age }Student; extern Student StuList[STUDENTS]; // turn it global / not needed if we plan to use it only by the students.cpp module #endif // file: students.cpp #include <system.h> #include "students.h" Student StuList[STUDENTS]; // array of struct void AddStudent( uchar *pstudent, uchar index ) // add student { StuList[index].s_id = *pstudent++; StuList[index].s_age = * pstudent; } void main() { uchar adata[2]; for( uchar i=0; i<STUDENTS; i++ ) // all 64 { adata[0] = i+1; // id data to be stored adata[1] = i+1; // age data to be stored AddStudent( adata, i ); // add_student } } The advantage of this approach is that the entire collection consumes 128 bytes instead of 192 bytes when objects is used. br
  8. I did an atempt to use this in a real application by using several lists of structures but the compiler boostc/bostc++, failed. After several tests i concluded that the compiler do doesn't like to have "methodes" inside of the structure. So, until better oppinion, i believe that this is a compiler issue. Modifications: 1. delete AddStudent( uchar *pstudent ) "methode" inside of structure. 2. instead of StuList.AddStudent( adata ), StuList.s_id = data[0] and StuList.s_age = data[1] should be used. br
  9. Same here with xp, vista, w7, w10. I remember that this worked in previous versions, 6.97 for instance. br
  10. ANDYp, looking at datasheet, timer 1 section, i can't see how to achieve 20 minutes with timer 1 interrupt... lets see: clock = 4000000 Hz maximum prescaler = 8 maximum timer 1 count = 65536 t1_tick = 1 ( 4000000 / 4 / 8 / 65536 ) = 0.524288 secs But it can be used by polling the timer 1 interrupt flag and count the number of times that the TMR1IF rises. To achieve 20 mins the number of counts is 20*60/ t1_tick = 2288 Then you can call your function to change state or whatever you want timer 1 interrupt isn't need, polling pir1.TMR1IF is enough. write a function to do it and call this function from main. If my math is right it should work pretty well br
  11. im glad you got it working. about Dave and Pavel, i see no activity from him in here for a long time. but company keep selling cause i brought a boostc++ pro weeks ago i don't know what that absence means, i just know that in my oppinion they have a great product with a very competitive price br
  12. Forgot to mention the basis of it is on boostc++ manual page 83. br
  13. This is just an example for who needs something alike also to c++ experts comments that are very welcome. Purpose: .create a list of objects and do something with them Device: pic18Fxxx // file: students.h #ifndef _STUDENTS_H_ #define _STUDENTS_H_ typedef unsigned char uchar; #define STUDENTS 64 // max number of students class Student // { private: uchar s_id; // data member uchar s_age; // data member public: void AddStudent( uchar *pustudent ); // function member }; extern Student StuList[ STUDENTS ]; // studets list #endif // file: student.cpp #include <system.h> #include "students.h" class Student StuList[STUDENTS]; // list of students void Student::AddStudent( uchar *pstudent ) // AddStudent { s_id = *pstudent++; // update id s_age = *pstudent; // update age } void main() { uchar adata[2]; // buffer from where data comes from for( uchar i=0; i<STUDENTS; i++ ) // Lets fill all students [0..63] { adata[0] = i+1; // data to be stored adata[1] = i+1; StuList[i].AddStudent( adata ); // add student id&age } while(1); } i did AddStudent member this way because i needed to pass a buffer with data received from the serial port. It works perfect, but suggestions are welcome. I also did it with an array of structures that results shorter in ram resources. Using classes an additional byte is consumed for each element. br
  14. With just the code fragment you show is not possible to comment. http://www.microchip.com/forums/m816748.aspx http://ww1.microchip.com/downloads/en/AppNotes/00000734C.pdf br
  15. Another way to do the same with less code on set/clear output, imagining that the Green output is a led with cathode connected to the ground This is also faster than previous example because just one instruction is needed to change the output state #include <system.h> #define GREEN 1 // Green pin gpio = (1<<GREEN); // precondition(HI) when triso.1 = 0 (as output) trisio = ~(1<<GREEN); // all pins = inputs except for GREEN pin = output // macro #define SET_GREEN_HI ( trisio &= ~(1<<GREEN)) // <=> trisio.GREEN=0 #define SET_GREEN_LO ( trisio |= (1<<GREEN)) // <=> trisio.GREEN=1 void main( void ) { SET_GREEN_HI; // turn Green out = high SET_GREEN_LO; // turn Green out = low } reedited: Forgot to mention that this issue only happens when u want to modify one or more port pin state(not the entire port). This means if u write the entire port, mirror is not needed, but as a rule for devices without latx i use to write everything through the mirror. hope this helps, br
  16. A more elegant way to do the same... // header file #ifndef _STUDENTS_H_ #define _STUDENTS_H_ typedef unsigned char uchar; #define STUDENTS 64 // S T U D E N T D A T A S T R U C T struct Student { uchar s_id; // id uchar s_age; // age void AddStudent( uchar *pstudent ) // add function member { s_id = *pstudent++; s_age = *pstudent; } }; extern Student StuList[STUDENTS]; // turn it global if need #endif // c file #include <system.h> #include "students.h" Student StuList[STUDENTS]; void main() { uchar adata[2]; for( uchar i=0; i<STUDENTS; i++ ) // all 64 elements { adata[0] = i+1; // data to be stored adata[1] = i+1; StuList[i].AddStudent( adata ); } } br
  17. Actually is not so hard set config fuse bits, unless you are using on of the rare devices that comes with missing defines. In that case you need to write all defines in the include file Anyway, it depends of device you are using Here is an example for pic18f4620 #pragma config CP0 = OFF // Code Protection bits (Program memory code protection off) #pragma config OSC = INTIO67 //XT // Oscillator Selection bits (RC oscillator w/OSC2 configured as RA6) #pragma config IESO = OFF // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source)) #pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config BOREN = ON // Brown-out Reset Enable bit (Brown-out Reset enabled) #pragma config BORV = 0 // Brown-out Reset Voltage bits (VBOR set to 2.5V) #pragma config WDT = ON // Watchdog Timer Enable bit (WDT enabled) #pragma config WDTPS = 128 // Watchdog Timer Postscale Select bits (1:128) #pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET) if i remember, when we start a new project using the sourceboost wizard, "he" do it for us, but this feature not cover all devices.... again... since i remember br
  18. Hi there, Thats weird.. it works ok here. tested again minutes ago. The missing defs you saw on your header file, is missed on mine too. There are another files with missing stuff... good luck this is the test i did: #include <system.h> #ifndef _EEPROM #define _EEPROM 0xF00000 #endif #pragma DATA _EEPROM, 0x10, 0x11, 0x12, 0x13 void main( void ) { while(1); // nothing to do } br
  19. As mentioned by RichardC in a previous post Whenever you want to write to an output, a mirror (register) should be used, then you may write to the output through this mirror, like the example below: #define Green 1 #define Out1 5 unsigned char gpio_mirror; // usage... gpio_mirror.Green = 1; // to set pin hi gpio = gpio_mirror; gpio_mirror.Green = 0; // to set pin lo gpio = gpio_mirror; // same methode to Out1 pin Except for devices with LATx br
  20. About eeprom issue, you may use this in your code: #ifndef _EEPROM #define _EEPROM 0xF00000 #endif #pragma DATA _EEPROM, 0x10, 0x11, 0x12, 0x13 or you may just insert "#define _EEPROM 0xF00000" in the pic18f45k50.h don't use 0xF000 as i saw in a previous post. I have imported a snipet to mplab 8.92 with #defines as showed above and saw all four values ok in the eeprom watch window. The section related with fuses, etc, you may try to copy them from a closest model... ideally verifing values with datasheet and after check them within mplab. br
  21. unsigned char xpd=9; unsigned char xpm=38; unsigned int xpf=4534; unsigned long xr; xr = ((xpd*600000)+(xpm*10000)+xpf); // 5456854 <<< error xr = xpd*600000; xr += xpm*10000; xr += xpf; // 5784534 <<< ok Simulated by sb_7.30 Check again and again the math section of sourceboost manual and not see anything that tell me that i can't do it all in one single line. br
  22. Please explain why your method is more preferable? Regards, Pavel In the particular case where he just write the entire port and he do nothing more, its irrelevant the use of a port shadow. I point it just a general rule to follow just in case. Actually in some load circumstancies pic12/16/18 all them have this issue, the difference is that the pic18 and new pic16 have the lat(x). google for "microchip DS31009A" pag 9 br
  23. Please explain why your method is more preferable? Regards, Pavel In the particular case where he just write the entire port and he do nothing more, its irrelevant the use of a port shadow. I point it just a general rule to follow just in case. Actually in some load circumstancies pic12/16/18 all them have this issue, the difference is that the pic18 and new pic16 have the lat(x). google for "microchip DS31009A" pag 9 br
  24. This is a delayed answer but in any case maybe it could be usefull to the ones that start trying to do it, also because i saw several guests seeing this thread. as far i can see the changes that should be made, are: includes: replace both by #include <system.h> __CONFIG replace it by: #pragma DATA _CONFIG, 0x3b32 note: this is an oggly way to do it, in the future try to replace literal 0x3b32 by the fuse names you want to set, separated by commas (edit pic16f877.h under "c:\.....\sourceboost\include" to see what correct names are defined. ex: #pragma DATA _CONFIG, _WRT_ENABLE_ON & _WDT_ON .... whatever you want.. this is just an example This is more readable to see what fuses are defined at a first glance. pic registers: all them should be in lower case... ex: use tmr1h instead of TMR1H. pic register bits: use "intcon.TMR1IF = 0;" instead of "TMR1IF = 0;" (the same to all others you use) side comments: As this old pic is one of many that have the rmw issue (read modify write), i recomend you use the below methode to change ports: unsigned char portb_mirror = 0xfe; portb = portb_mirror; instead of: portb = 0xfe; br
  25. Hello everyone, When MPLAB IDE is used with sourceboost to compile a project consisting of multiple files, is there any way to it compile just the modified files, as SourceBoost IDE does? Same question to mplabx. thx in advance, br
×