medelec35 0 Report post Posted April 30, 2014 I have an issue with my first sourceboost C code: #include <pic16f877a.h> #include <system.h> #pragma CLOCK_FREQ 4000000 //Set clock frequency #pragma DATA _CONFIG, _PWRTE_OFF & _WDT_OFF & _HS_OSC & _CP_OFF //Target PIC16F877A configuration word void main() { trisb=0; while(1) { portb.0=1; delay_ms(500); portb=0x0; delay_ms(500); } } The issues are. The timing are suppose to be 500ms but stop watch and a different simulator are both showing the delay as 244ms: Also the green simulation step line is going below the last brace for some reason? Since this since my first attempt, it's more than likely I'm doing something daft. I'm grateful for any advice with what is going wrong please. Thank you. Quote Share this post Link to post Share on other sites
Reynard 0 Report post Posted May 1, 2014 You cannot have a any timer argument greater than 255. The timer functions take a char value (8 bits). Turn on "All Warnings" and the compiler will say something about it. Enjoy SourceBoost. Cheers Reynard Quote Share this post Link to post Share on other sites
medelec35 0 Report post Posted May 1, 2014 Thanks for your reply Reynard, much appreciated. I did not realise delays are char only since I was using a tutorial called WINK LED. one of the lines stated: delay_ms(500) // pause 0.5 seconds Since it's my first bit of coding was following it to the letter & blindly as the author new much more than I do. Shame delays can be initialised as unsigned int. All the best. Quote Share this post Link to post Share on other sites
medelec35 0 Report post Posted May 1, 2014 Forgot to mention: The tutorial is from these forums: it was from a tutorial called 'pic Micro Programming In Boostc For Beginners' http://forum.sourceboost.com/index.php?showtopic=2399 Apart for that, it's a great tutorial and I plan to finish it. So my thanks goes out to the author Quote Share this post Link to post Share on other sites
Pavel 0 Report post Posted May 2, 2014 Forgot to mention: The tutorial is from these forums: it was from a tutorial called 'pic Micro Programming In Boostc For Beginners' http://forum.sourceboost.com/index.php?showtopic=2399 Apart for that, it's a great tutorial and I plan to finish it. So my thanks goes out to the author I have corrected the tutorial code to produce correct delays. Regards, Pavel Quote Share this post Link to post Share on other sites
medelec35 0 Report post Posted May 2, 2014 (edited) Thanks Pavel. This would also apply to: if(duration==1000) // if duration equals 1000ms, { duration=990; // make it 990ms. } // this will limit the max delay. } if(button3) // if button3 is pressed, execute { // the following statements. duration-=10; // reduce delay by 10ms. if(duration==10) // if delay equals 10ms, { duration=20; // make it 20ms. } // this will limit the min delay. } if(button1==0) // if button1 pin is not pressed, { // execute the statements below check1(); // call routine check1. portb <<= 1; // shift bits in portb to its left, ones. delay_ms(duration); // pause for the value of duration. Further down. Unless it does not apply to this since: int duration; so ms is no longer a char but integer? But if : Reynard, on 01 May 2014 - 10:15 AM, said: You cannot have a any timer argument greater than 255. The timer functions take a char value (8 bits). Then I can't see it being the case. Edited May 3, 2014 by medelec35 Quote Share this post Link to post Share on other sites