Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by Reynard

  1. Hi Jorge, You should read some of my code and you will see what sloppy is K & R 2nd edition says "the storage class for an externally-declared object may be left empty, or it may be specified as extern or static." So it works either way. Off topic: Your Novo problem is a good one. I have it running on my EasyPIC5 board. It says in the Novo source that the next task can be overridden by priority change or waiting task wakeup. Maybe the last part has something to do with it (waiting task wakeup). Cheers Reynard
  2. Hi Jorge, I suppose everyone has their own coding style. I use extern when using GCC and Keil. I think it makes it clear the function resides elsewhere just like variables. The compilers probably assumes extern unless told otherwise by seeing the full declaration. Using extern for functions is probaly something that came over from assembler days (EXTERN). I will keep writing my style of sloppy code. Cheers Reynard
  3. Hi Jorge, Look inside the SB string.h file and it is full of the little extern blighters The header files for the GCC compiler is full of them too. The extern tells you that the function is not in this module but somewhere else. Maybe something to do with assisting the linker. Perhaps todays compilers silently ignore it. Cheers Reynard
  4. I think what you have here is a bug. SB has a few issues with function pointers probably due to the memory architecture of the small PIC devices. I think the storage class specifier 'extern' should always be used when refering to a function not in the current module. Not using it is sloppy coding even if SB allows you not to use it. Function overloading should not cause the problems here as each overload will have a different signature therefore the internally the function name will be different. All the RAM bank switching does add a lot of overhead to your code which is why I am looking towards the Atmel AT devices with their Harvard architecture. They also have real USARTS with parity for us oldies who are still using RS-232. Cheers Reynard
  5. Hi Chuck, The ADC requires an aquisition time after you change channel to allow the hold capacitor to charge or discharge to the new input voltage. Once you change channel leave about 50us before you begin conversion (adcon0.ADON = 1;). If you are doing continuous reading of the ADC just leave it turned on unless you really need to save power. Cheers Reynard
  6. Is it something like this you want ? #include <system.h> bool myfunc(void) { return true; } bool (*pFunc)(void); char myvar; void main() { pFunc = myfunc(); if (pFunc) { myvar = 1; } else { myvar = 2; } while (1); } Boolean is lower case bool or you can use bit. Cheers Reynard
  7. Have you ever looked at the Atmel range of chips ? The AVR GCC compiler is ANSI C with some C99 thrown in. Does floats and doubles, 64 bits and math. I am playing around with a couple of AT90CAN32 chips when I can find the spare time using Atmel Studio 6. Cheers Reynard
  8. Hi, BoostC is not ansi C as described in K & R second edition. ANSI C was written for a main frame computer like the IBM 360 etc. Embedded microprocessors like the PIC do not have the memory requirements to support all C functions and data types. BoostC does not support float or double but does have a floating point library. It also does not support all the standard library such as math.h It does have some feature of C99 and some features of C++ such as funtion overloading. Features of C11, probably not. BoostC has to work around the target device and its restriction. Cheers Reynard Is ANSI C (C89) not a bit out of date anyway. BoostC is still great value for money.
  9. Hi, The compiler will decide which is the best division to use for the job. If you are dividing a long by an int then the largest type will be used (long). It will also return a long. Cheers Reynard
  10. Hi Jorge, I don't think the manual "clearly states" you have to use the type 2 config only a recommendation. The type 2 config is a fairly new feature. It may have come out in version 7.0 so may not be available to those using version 6.X. If the device .h file defines both config options them you are free to use either. Use type 2 if it is there. The manual also shown an config example for a PIC18 device using type 1 config (Configuration Example 2:). PIC10 devices are not supported by SourceBoost. Cheers Reynard
  11. Hi Sergej, The spec says 4MHz max for XT mode so I would not use it. The oscillator probably would not start due to loading resistance changing when different modes are used. For the config parameters try using the type 2 method rather than the cryptic ANDing of bytes. The type 2 parameters are at the bottom of the device .h file starting with the oscillator section to the end of file. Copy this section and create a config.h file in you project directory. Uncomment all the parameters you need. Make sure you have something enables in each section. Include the config.h file to your main source file. Makes life a bit easier if you just need to disable the watchdog timer etc. The oscillator section is duplicated in the device .h file so just delete the lower one. Someone at SourceBoost got carried away with their cut and paste. Many of the .h files are like this. Cheers Reynard
  12. This works with enum and function with the same name. enum state{ forward, reversed }; enum state getState() { return forward; } void forward(){ int i; enum state currentstate = getState(); trisc.0 = 0; trisc.1 = 0; if(currentstate != forward){ portc.2 = 0; portc.3 = 0; for(i=0; i<5000; i++); } portc.0 = 1; portc.1 = 1; for(i=0; i<30000; i++); } void main() { forward(); } Cheers Reynard
  13. Hi Carlos, Always something simple. Glad you found it. Cheers Reynard
  14. Hi Tom, Casting to bool is not supported in SB. The boolean lvalue I suppose implies casting to bool. Cheers Reynard
  15. Hi Sparky, This appears to be the standard method irrespective of data size (32, 16 0r 8). A quick Google search found it, and seems to work in SB. #include <system.h> typedef unsigned long uint32_t; uint32_t isqrt32 (uint32_t n) { uint32_t root, remainder, place; root = 0; remainder = n; place = 0x40000000; while (place > remainder) place = place >> 2; while (place) { if (remainder >= root + place) { remainder = remainder - root - place; root = root + (place << 1); } root = root >> 1; place = place >> 2; } return root; } void main() { uint32_t result; result = isqrt32(1234567890); } Cheers Reynard
  16. Hi Jakonil, Do you mean it does not work when using the IDE simulator or on the real device. Maybe the simulator thinks it has the comparator 1 enabled for some reason. Cheers Reynard
  17. Now that's a cool feature. Find (Find next) doesn't like a single blank line under the matching line.
  18. Hi Steve, You will have to write your own. It's only a dozen line or so of code. If you have the source code you can copy and change it. The library has not been updated for these newer devices. Cheers Reynard
  19. Hi P, The problem may be that you are calling a function from a library that is contained within another library. The i2c header maybe embedded into the rtc library. The i2c header is also embedded into main. The linker is seeing both headers as being defined. This may not be the exact reason but sound plausible. Dave and Pavel could clarify Remove rtc calling i2c functions and see what that does. (Remove i2c header as well) Cheers Reynard
  20. Hi Carlos, This one is a bit of a mystery. I was only using the default oscillator frequency of 1MHz. I could try cranking it up to 8MHz. I am using silicon version 7 but I don't see anything in the errata sheet that would cause problems. The problem I was getting is the RS signal being left at 0 after the clear display or other command function. Then when I write a single character the RS signal is not being changed to a 1 to write the data. It works using the printf because it sets the RS signal before writing the data. Have you tried writing your own LCD driver. I always avoid using drivers that come with a compiler. They never do exactly what I want and seldom run using inetrrupts for any of the serial ports. It is sad that you have to modify your PCB for something that should work. Good luck. Reynard
  21. Hi Carlos, I have build a simple circuit using the 18F2520 and a 2x16 display. #pragma CLOCK_FREQ 1000000 #define LCD_ARGS 1, /* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \ 0, /* Use busy signal: 1 = use busy, 0 = use time delays */ \ PORTC, TRISC, /* Data port and data port tris register */ \ PORTA, TRISA, /* Control port and control port tris register */ \ 5, /* Bit number of control port is connected to RS */ \ 6, /* Bit number of control port is connected to RW */ \ 7 /* Bit number of control port is connected to Enable */ #include <lcd_driver.h> // LCD template code char *mesg = " Hello World "; void main() { adcon1 = 0x0f; lcd_setup(); // Initialise the LCD display lcd_clear(); // Clear the LCD display lcd_datamode(); lcd_write('A'); lprintf( mesg ); // Display a startup message on the LCD lcd_datamode(); lcd_write('B'); while (1) {} } This is my code using low nibble on port C (0,1,2,3) and control on port A (5,6,7). The LCD is displaying correctly. There is a small problem when using lcd_write() in that you have to set the lcd_datamode() first as you do not know that state of the RS signal. It may have been left RS = 0 which screws up any single character writes. There seems to be a bit of a bug in the lcd_write() function not setting the RS signal when writing a character. Hope this helps. Cheers Reynard
  22. Hi Carlos, Have you got the config set correctly to use RA6 and RA7 as I/O pins ? #pragma config OSC = INTIO67 // Internal oscillator block, port function on RA6 and RA7 I have used this PIC in a project with these pins for I/O. Cheers Reynard
  23. There are several ways to skin a cat. Here's one of them. #include <system.h> typedef struct { /* union{ unsigned char DummyVal; //This will be used when Alarm is to be read struct{ unsigned Day : 3; unsigned ALMIF : 1; unsigned ALMConfig : 3; unsigned ALMPOL : 1; }; }; */ unsigned char Alarm; // Alarm register data. unsigned char Sec; unsigned char Min; unsigned char Hour; unsigned char Date; unsigned char Month; } RTCCAlarm; #define ALM_DAY2 7 #define ALM_DAY1 6 #define ALM_DAY0 5 #define ALM_IF 4 #define ALM_CONFIG2 3 #define ALM_CONFIG1 2 #define ALM_CONFIG0 1 #define ALM_POL 0 #define ALM_DAY_MASK ((1 << ALM_DAY2) | (1 << ALM_DAY1) | (1 << ALM_DAY0)) #define ALM_CONFIG_MASK ((1 << ALM_CONFIG2) | (1 << ALM_CONFIG1) | (1 << ALM_CONFIG0)) RTCCAlarm xRTC, *pxRTC; void main() { unsigned char ucAlarmDay; pxRTC = &xRTC; pxRTC->Alarm = RTC_AlarmRegister; // read RTC chip alarm register. if (pxRTC->Alarm & (1 << ALM_IF)) // test alarm IF bit. { ucAlarmDay = (pxRTC->Alarm & ALM_DAY_MASK) >> 5; // get day value. } } You can access the RTC structure using a pointer or direct addressing. Cheers Reynard
  24. Hi Badejo, BoostC does not allow bit structures. You will have to get access to the bits with a byte with a little of extra code. Cheers Reynard
  • Create New...