Jump to content

joli

EstablishedMember
  • Content count

    81
  • Joined

  • Last visited

Community Reputation

0 Neutral

About joli

  • Rank
    Regular

Profile Information

  • Gender
    Male
  • Location
    Portugal
  1. 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
  2. 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, 0xD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, 0x4C, 0x8C, 0x44, 0x84, 0x85, 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
  3. 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
  4. Same here with xp, vista, w7, w10. I remember that this worked in previous versions, 6.97 for instance. br
  5. 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
  6. 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
  7. Forgot to mention the basis of it is on boostc++ manual page 83. br
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  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. 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
  15. 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
×