View previous topic :: View next topic |
Author |
Message |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Dec 04, 2011 3:30 pm |
|
|
I avoid delay_ms () ALWAYS and will only use as a last resort.
Consequently I am not at the mercy of compiler version variations.
This is a typical delayMS I use.
Of course timer0 and any other timer that can be driven by the master oscillator is easy to adapt
and it is EZ to add 1 ms interval POLLING as well.
Code: |
setup_timer_1(T1_DIV_BY_2|T1_INTERNAL); // set each "tick' 1 usec
//.... with 8 mhz master clock
void delayMS( unsigned int16 tix){
if (!tix) return; // never zero
else set_timer1(64537); // 1 us / tick preset rollover-1000 comp for loadup time
tmr1if=0;
do {
if (tmr1if) { set_timer1(64537); --tix; tmr1if=0; } // insert your polled function inside these braces
}while (tix);
}
|
|
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Problem solved! |
Posted: Sun Dec 04, 2011 8:51 pm |
|
|
The problem was that MPLAB IDE somehow had DEBUG selected. I changed it to RELEASE and everything started to work correctly.
Some of us are novices, like the originator of this thread, and something so simple can be a disaster to learning to program in C. I used to use asm on an 8085 many years ago under CPM. Life was much simpler then and I had a good grasp on what was happening. Now we live in a world where software is a bit of a mystery and only the brilliant know much about what is happening.
I hope this helps another novice programmer. |
|
|
Surfer83
Joined: 25 Nov 2011 Posts: 7
|
|
Posted: Mon Dec 05, 2011 12:19 am |
|
|
Ttelmah wrote: | You talk about the ICD2. Does this mean you have the 18 to 28pin adapter AC162053?. If not, you are aware the ICD, is _not_ available on the 18pin device?.
Hopefully you are just using the ICD2 as a programmer.
You don't show the NOMCLR fuse. Do you have the MCLR pin pulled up?.
Best Wishes |
Yeah was using it just as a programmer. I have MCLR pin pulled up by 10Kohm resistor.
asmboy wrote: | you said :
Quote: |
just to blink this led
|
why did you write so such code ? LOL
try this:
Code: |
void main(){ while(1) { output_toggle(PIN_B5); delay_ms(100);}}
|
now THATS the easy way |
Yeah nice code I'm changing my long code for this one thank you. |
|
|
Surfer83
Joined: 25 Nov 2011 Posts: 7
|
|
Posted: Mon Dec 05, 2011 12:21 am |
|
|
ckielstra wrote: | What is your compiler version number? It looks something like 4.xxx, i.e. 3 digits after the dot.
NOMCLR fuse is used by default for this chip when you specify nothing, but best to specific about your choice and add it to the list of fuses.
A delay of 10ms is way too short for debugging as your eye is to slow to see it. Even 100ms is tricky. Be safe and use something like 500ms.
I tried it in the MPLab simulator with CCS v4.077 and got a delay as expected. |
I'm using v4.103 and I changed the delay to 100 |
|
|
Surfer83
Joined: 25 Nov 2011 Posts: 7
|
PROBLEM SOLVED! |
Posted: Mon Dec 05, 2011 1:10 am |
|
|
Thank you so much guys for assisting me and giving advices on this problem. After posting the first thread, I already had a feeling there must be something simple going wrong but the frustration of unable to run the simplest code really gets on my nerves and that why I decided to post in the forum.
At first I suspected it had to do on the fuses that I set or on how I called the delay function. Looking from codes from googling and this forum, it seems that my code is ok even though it wasn't that efficient.
I checked the board, thinking probably there something shorted or opened in the circuit so I changed to another position on my solder less project board. I even build the circuit on a veroboard but still can't get it to blink.
Next, I suspected there something wrong with my Uc (I got a few of them 16f628A, 16f628, 16f84a ). I decided to buy a new PIC16F88, seem like it’s a newer and better choice than my old Uc. I just change the header in the code and replace it on previous circuit and IT WORKS.
Guess it’s a combination of the project board and the Uc.
Quote: | I used to use asm on an 8085 many years ago under CPM. Life was much simpler then and I had a good grasp on what was happening. Now we live in a world where software is a bit of a mystery and only the brilliant know much about what is happening. |
Yeah, I really agree with you there. You know what actually happening like changing bank and selecting the tris for input and output then back to previous bank than making it high or low. Delay was a simple counter looping. Well maybe I’m new that’s why I’m complaining but I still love to get better at this. |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Is your debug on? |
Posted: Mon Dec 05, 2011 8:36 am |
|
|
Surfer83:
Have you solved your problem?
Is DEBUG selected in MPLAB IDE. This was my problem and caused even simple code to compile incorrectly. I suspect it was also the cause of my not being able to set my INT OSC and having to resort to a XTAL. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 05, 2011 5:13 pm |
|
|
Here is a way to force MPLAB to select "Release" as the default build
configuration, instead of Debug:
Quote: |
1) Open regedit and navigate to registry key "HKEY_CURRENT_USER\Software\Microchip\MPLAB IDE".
2) Create a new string value called 'DefaultBuildConfiguration".
3) Set the value of this string to "Release".
|
This is from Microchip tech support department (via Temtronic).
I edited my registry (on Windows XP) and added this new key and
it works. All my new MPLAB projects start up in "Release" mode. |
|
|
|