|
|
View previous topic :: View next topic |
Author |
Message |
Arclite
Joined: 02 Jul 2004 Posts: 16 Location: UK
|
Pic18F452, delay_ms() stops code executing. |
Posted: Fri Dec 03, 2004 7:13 pm |
|
|
Hi guys,
I have a simple problem, the code i have fails to run past the delay function and i would like to know why and how to get around it.
CCS compiler 3.200
MPLAB 6.30
I am using a 4Mhz Resonator ZTT type with built in caps, and can see 4Mhz on Osc2
Code:
Quote: |
Proj1.H file>
#include <18F452.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,HS, NOPROTECT, NOOSCSEN, BROWNOUT, NOPUT, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
|
Quote: |
Proj1.C file>
#include <Proj01.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Defines
// Variables
// Procedures
//===================================
// Interrupts
#INT_TIMER0
Timer0_isr()
{
}
#INT_RDA
RDA_isr()
{
}
void SetupMCU()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_1,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
disable_interrupts(INT_TIMER0); //<< don't need these yet
disable_interrupts(INT_RDA);
disable_interrupts(GLOBAL);
}
// Main routine
void main()
{
SetupMCU();
do{
output_high(PIN_E0);
// delay_ms(1000);
output_high(PIN_E1);
delay_ms(1000); // << stuck here, why?
output_high(PIN_E2);
// delay_ms(1000);
output_low(PIN_E0);
// delay_ms(1000);
output_low(PIN_E1);
// delay_ms(1000);
output_low(PIN_E2);
// delay_ms(1000);
}while(TRUE);
}
|
It is just a simple staged LED flasher program that should work, no black magic or rocket science added yet. So what is the problem with it?
Regards. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Dec 03, 2004 8:05 pm |
|
|
Where is your #fuse statement?
Check your config bits. The wdt is probably enabled causing it to reset;
This Code: | setup_wdt(WDT_OFF); | does not turn off the WDT if it is enabled. |
|
|
Guest
|
|
Posted: Sat Dec 04, 2004 8:18 am |
|
|
Hi,
It is in the Header file with the '#use RS232' statements.
Regards |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Dec 04, 2004 8:45 am |
|
|
Well it would help for us to see it!! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1938 Location: Norman, OK
|
Comment out the Delay statements when using SIM |
Posted: Sat Dec 04, 2004 10:13 am |
|
|
If you are using the MPLAB simulator this is normal. What you are seeing the the Delay routine looping as it should. The simulator does not run at full speed so the delays take a VERY long time.....
While using the Simulator you have to comment out the delays. Put them back in for the final text with the hardware.
To make it easier I set a SIM flag in my code and put conditionals around the delay statements.... |
|
|
Guest
|
|
Posted: Sat Dec 04, 2004 10:54 am |
|
|
Hi Mark,
If you look at the 1st msg at the top of this post, it is in the 1st quote box.
Dyeatman,
I am burning the chip with code to run it, not using the simulator.
I appreciate that issue with the delays and i do exactly that (comment them out during the simulation). |
|
|
Arclite
Joined: 02 Jul 2004 Posts: 16 Location: UK
|
|
Posted: Sat Dec 04, 2004 10:57 am |
|
|
Just to mention the last two Guest posts are mine.
I appears that the server had logged me out twice. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 04, 2004 11:47 am |
|
|
In your original post, you refer to your include file as: Proj1.H
But in your program, it is called '01'.
#include <Proj01.h>
Do you have two separate include files, called Proj1.H and Proj01.h ?
Perhaps one of them enables the watchdog, and the other does not ?
-------
You have two #use rs232() statements:
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
It's clear that this code is all just typed in. It's not a verbatim test
program. So this makes it difficult to know what's real.
-----
You need to make a short test program that shows the problem,
and then use Ctrl-C and Ctrl-V to copy it into a post. That way,
we can examine the exact code that's causing the problem.
The test program should be one program, and the only include file
in it, should be the CCS .H file for the PIC. Put all compiler directives
such as #fuses, etc., at the top of the file. |
|
|
Arclite
Joined: 02 Jul 2004 Posts: 16 Location: UK
|
This is code with comments removed |
Posted: Sat Dec 04, 2004 12:03 pm |
|
|
Hi
The code has had all of the comments removed as they are all app related, and removed for clarity.
The remaining code does exactly the same thing, and as for the name Proj1.H etc, that is a typo error when i copied the code from the machine i'm working on. Besides, my reference statement "Proj1.H file> " wouldn't compile.
The two RS232 statements are for different devices i have, one i will define with the pins listed, the other i'm to define.
In all, if you were to execute the two files naming them 'Proj01.h' & 'Proj01.c', the same problem should manifest itself again. |
|
|
Arclite
Joined: 02 Jul 2004 Posts: 16 Location: UK
|
Problem solved!!!! |
Posted: Sat Dec 04, 2004 1:22 pm |
|
|
I think i have cracked it.
I think it is something to do with the port settings in the CCSC project wizard, i may have overlooked them, and it lets some pins work and not others prior to the use of delay_ms().
It is somethink i take for granted since moving from assembler to CCSC.
It is a reproducable fault, so problem solved.
Thanks all for your input. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|