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 support@ccsinfo.com

PIC18LF4525 and RS232 issue

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



Joined: 10 Jan 2008
Posts: 17

View user's profile Send private message

PIC18LF4525 and RS232 issue
PostPosted: Thu Nov 10, 2011 3:18 am     Reply with quote

Hi, I'm using the PIC18LF4525.
I wrote a lot of firmware and it hasn't problem, but now, I have a problem with the serial port.
I've reduced the firmware at those few line.

Could you help me?
The signal on pin C6 is low and I don't see any activity.

Code:

#include <18F4525.h>
#device ICD=TRUE
#device adc=10
#FUSES NOWDT
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)



#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)




Code:

#include "main.h"

char command;
int1 app_debug=0;
 
void main()
{
   setup_adc_ports(AN0_TO_AN2|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_6);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   //setup_timer_0(RTCC_INTERNAL);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   
   disable_interrupts(INT_RTCC);
   
   setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);

 
while(1)
   {
   command='U';
   putc(command);
 
  if(app_debug==1)
  {
  output_low(pin_d7);
  app_debug=0;
  delay_ms(255);
  }
  else
  {
  output_high(pin_d7);
  app_debug=1;
  delay_ms(255);
 
  }
}

}

Ttelmah



Joined: 11 Mar 2010
Posts: 19439

View user's profile Send private message

PostPosted: Thu Nov 10, 2011 3:59 am     Reply with quote

Are you _sure_ you are using LVP?.
99.9% of programmers do not.
If you are, and with the LVP fuse selected as you have, you _must_ have a pull down resistor on the PGM pin (B5), or the chip won't run.

Secondary comment:

setup_spi(SPI_SS_DISABLED);

is the wrong syntax. The command to turn off SPI is:

setup_spi(FALSE);

This is a bug in the wizard (has been around for years.....).

Third comment. You momentarily enable INT_TIMER0, but don't show any handler for this. This risks crashing the chip. _Never_ enable an interrupt without a handler...

Fourth comment. Add the keyword 'ERRORS' to the #USE RS232 setup. This _must_ always be present, if using the hardware UART, unless _you_ add code to handle serial errors. If it is missed, and the RX input is not permanently high, the UART _will_ become hung.

Fifth comment. Look again at your setup_oscillator line. You can't have three oscillators all selected as the master oscillator.....
All you need is:

setup_oscillator(OSC_8MHZ);

Best Wishes
FMOpt2000



Joined: 10 Jan 2008
Posts: 17

View user's profile Send private message

PostPosted: Thu Nov 10, 2011 9:02 am     Reply with quote

Thx!
I'm not sure about nothing!!
I'm a beginner and I did my schematic copying my colleagues.
I've an ICD-U40;I haven't the resistor on B5 and the PIC is running.

I'm going to correct like you say.

This is the problem on RS232:
I worked on a folder for a week, modifying the firmware.
After I have done a copy of my firmware folder and I've worked on this new folder (I've added the fuse for RS-232 to the main).

But the modify is applied on the old main file (not for the new folder)...

I thought the references were local references, not absolute references.
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