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

pic 18f6722 uart

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



Joined: 08 Mar 2014
Posts: 7
Location: India

View user's profile Send private message

pic 18f6722 uart
PostPosted: Sat Apr 26, 2014 12:00 pm     Reply with quote

i am not able to run a simple uart program. I am using a max232 for level shifting and hardware is perfect, it works with pic18f452.
below is the code
Code:
#include "serial.h"


void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_low_volt_detect(FALSE);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);

   // TODO: USER CODE!!
   while(1)
   {
      printf("hello");
      delay_ms(500);
   
   }

}


below is the header file
Code:

#include <18F6722.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC                    //Internal RC Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV25                   //Brownout reset at 2.5V
#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 NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                    //Extended set extension and Indexed Addressing mode enabled
#FUSES BBSIZ1K                  //1K words Boot Block size

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


can anyone please help me in correcting the code!
Ttelmah



Joined: 11 Mar 2010
Posts: 19330

View user's profile Send private message

PostPosted: Sat Apr 26, 2014 12:09 pm     Reply with quote

Several faults/possible faults.

LVP.

Are you sure?. 99.9% of systems must have NOLVP. If LVP is selected (only is programming from a specific low voltage programmer), then you must have a resistor to ensure the programming line is held 'off' when you want to run.

setup_spi(SPI_SS_DISABLED);

No. Syntax is setup_spi(FALSE);

You are enabling both SPI ports, and turning off slave select. This is a common fault from setting things incorrectly in the wizard...

When using the hardware UART, you should (must...) always have 'ERRORS' in the #use RS232. Omitting this can hang the UART, unless _you_ add code to handle errors.
A search here will find a lot about this.

You are enabling MCLR. Have you got this pin pulled up?,
amit



Joined: 08 Mar 2014
Posts: 7
Location: India

View user's profile Send private message

PostPosted: Sat Apr 26, 2014 9:04 pm     Reply with quote

I have code similar to this for LCD and keypad. So the possible faults of LVP and MCLR does not apply to this.
Setup_spi(false) and errors also does not works.
Ttelmah



Joined: 11 Mar 2010
Posts: 19330

View user's profile Send private message

PostPosted: Sun Apr 27, 2014 12:06 am     Reply with quote

Seriously, how are you programming the chip?.
LVP _will_ give problems unless LVP is being used, and unless you are using an LVP cable, then this should be off. The faults may well change with different hardware connected.....
amit



Joined: 08 Mar 2014
Posts: 7
Location: India

View user's profile Send private message

PostPosted: Sun Apr 27, 2014 1:19 am     Reply with quote

Ttelmah,

I tried setup_spi(FALSE) as suggested by you, the message hello appeared for 4-5 times and then no action. Also, this output does not repeat everytime I switch ON. I think there may be problem related to oscillator.

I also tried NOLVP. I am using pickit2 for programming.
Ttelmah



Joined: 11 Mar 2010
Posts: 19330

View user's profile Send private message

PostPosted: Sun Apr 27, 2014 1:46 am     Reply with quote

You definitely want NOLVP then.

Are you sure your actual supply is stable?. Once the oscillator starts it is 'rare' for it to stop without external cause. Spike on supply, line on the chip being overloaded etc..
Now you say the hardware works with a 452, but this is a 40pin chip versus a 64/80 pin chip. So you can't actually be using the same hardware....
Generally you have to be much more careful about good grounding, to all the Vss pins on the chip, and good smooth supply to all the Vdd pins, with these larger chips. Good HF decoupling capacitors right adjacent to the chip's supply pins.
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