CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Works in Debug but not in Normal mode [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Works in Debug but not in Normal mode [Solved]
PostPosted: Fri Dec 20, 2013 9:11 am     Reply with quote

My new project uses a PIC18F67K22 with 10MHz Crystal.
Just to get the project started a wrote a simple program that
flashes an LED and Sends a string to hardware UART #2 which uses port G.

In Debug mode everything works as expected.
The LED flashes at 1 second interval and the string is transmitted at 9600 Baud.

When I disconnect the debugger (ICDU64) and compile without debugging info. then program the chip to unit stand alone the RS232 does not output anything. The LED flashes at 1 second interval.

After much ado. I changed the LED interval to flash at 2 Seconds and Erase the chip, Check that chip was erased and reprogrammed it.

The LED still flashes at 1 Second! not 2 and there is no output on the RS232 port.

So I assume I'd loaded the wrong file.

Cleared all compiler output files and recompiled. Loaded the new HEX (checking the date and time on the file) and programmed the chip.

The LED still flashes at 1 Second! not 2 and there is no output on the RS232 port Confused

Started all over making sure I'm awake. Erased chip. Check it is erased.
Checked that compiler issues no errors or warnings. Check that the Oscillator is running at 10MHz (scope) checked that the debugger produces working code. Recompiled for normal stand alone code. Erased chip again to start fresh, Checked my sanity. had a cup of tea and after programming the code that should flash the led at 2 second interval and send the string "hello port2"
I fired up and really did expect the LED to flash at 2 second interval and the string to appear on the terminal.

The LED still flashes at 1 Second! not 2 and there is no output on the RS232 port ... even more Confused

Now I have to stop as I'm beginning to sense that Albert is testing me... Repeating the same thing over and over and expecting different results is not working out...

Should I check myself into an institution or what ?
Code:

#include <18F67K22.h>
#device adc=16

#FUSES NOWDT
#FUSES WDT128
#FUSES HSM
#FUSES NOPLLEN
#FUSES PUT
#FUSES NOBROWNOUT
#FUSES WDT_NOSLEEP
#fuses NOPROTECT
#fuses SOSC_DIG
#fuses NOBROWNOUT

#use delay(clock=10000000)

///////////////////////////////////////////////////////////////////////////////////
#use rs232(baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,errors)

void SendMyString(char* p)
{
  printf("%s",p);
}
///////////////////////////////
void main()
{
 
  set_tris_G(0b00000100); //

// this block of code was generated by the PIC-Wizard I really don't think I need this. I think timers are disabled at power up.

   setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_timer_5(T5_DISABLED | T5_DIV_BY_1);
   setup_timer_6(T6_DISABLED,0,1);
   setup_timer_7(T7_DISABLED | T7_DIV_BY_1);
   setup_timer_8(T8_DISABLED,0,1);
   setup_timer_10(T10_DISABLED,0,1);
   setup_timer_12(T12_DISABLED,0,1);

   setup_comparator(NC_NC_NC_NC);
   setup_oscillator(OSC_NORMAL|OSC_PLL_OFF);

   enable_interrupts(GLOBAL); // tried not enabling interrupts.
///////////////////////////////////

  // this works in debug mode, but not in stand alone.
  while(1)
   {
      delay_ms(2000);
      output_high(PIN_B1);
 
      sprintf(SendBuf,"Hello Port 2\r\n");
      SendMyString(SendBuf);

      delay_ms(2000);
      output_low(PIN_B1);
  }


}
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Solution
PostPosted: Fri Dec 20, 2013 11:20 am     Reply with quote

Thanks Richard of CCS Tech Support.

#FUSES NOWDT // Correct I did not want a WDT at this time.

#FUSES WDT_NOSLEEP // output by the Pic-Wizard project setup feature.

The WDT_NOSLEEP re-enables the WDT and causes the PIC to restart. The restart made the LED blink at the faster rate, and of course the restart prevented the RS232 from sending the string.

My mistake is using an old version V4.134 the newer Pic-Wizard does not make this mistake.

Happy at last... Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 20, 2013 2:09 pm     Reply with quote

nice you got it 'up and running'

I don't use the wizard as I'm 'old school', I did suspect a 'fuse' though.
More of them than instructions !!

once i got my 46k22 running right, I saved the fuses as an include file ( 46k22.fuz) , so I have a KNOWN good setup and it reduces typos on future projects.

cheers
jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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