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

18F4550 and int osc hangs with getc

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



Joined: 11 Jan 2009
Posts: 3

View user's profile Send private message

18F4550 and int osc hangs with getc
PostPosted: Sun Jan 11, 2009 4:28 am     Reply with quote

I'm trying to convert a project that i have developed for mikroc and that runs correctly in my board.
The problem i have is that getc() and kbhit() locks the execution.
I've tryed with interrupts too, but nothing changes.
Putc() sends correctly data.
The project runs perfectly with a mikroc version, so cannot be an hardware problem.
The oscillator is internal, 8Mhz.
This is the code:
(main.h)
Code:
#include <18F4550.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTHS                    //Internal Oscillator, HS used by
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#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 NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOMCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV1                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES NOVREGEN                 //USB voltage regulator enabled
#FUSES ICPRT                    //ICPRT enabled

#use delay(clock=8000000)
#use rs232(baud=38400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS)
#use i2c(Master,Slow,I2C1)

(main.c)
#include "main.h"
#include <string.h>

#define VERSION   "1.3.1"

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)

void main()
{
 char ch;

 set_tris_a(0b00001110);
 set_tris_b(0b10010100);
 set_tris_c(0b11000100);
 set_tris_d(0b00010000);
 set_tris_e(0b00000000);
 
 setup_spi(FALSE);
 setup_adc_ports(AN0_TO_AN2|VSS_VDD);
 setup_adc(ADC_CLOCK_INTERNAL);
 setup_psp(PSP_DISABLED);
 setup_wdt(WDT_OFF);
 setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT);
 setup_timer_1(T1_DISABLED);
 setup_timer_2(T2_DISABLED,0,1);
 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);

 disable_interrupts(GLOBAL);

 setup_comparator(NC_NC_NC_NC);
 setup_vref(FALSE);

 enable_interrupts(INT_TIMER0);
 enable_interrupts(INT_EXT2);
 enable_interrupts(INT_RDA);

 setup_oscillator(OSC_8MHZ|OSC_INTRC);

 putc('#');  // this is ok
 for (;;)
 {
  if (kbhit())  // << stops running
  {
   ch = getc();
   putc(ch);
  }
 }
}

Can someone help me about the code?
Thanks,
Alberto
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jan 11, 2009 5:33 am     Reply with quote

The present code can't work, cause it enables interrupts without an interrupt service routine. This also doesn't make sense with any other C compiler, I suppose.

If global interrupts are disabled, this doesn't hurt, but then I don't see a reason for the observed behaviour.
bertocar1974



Joined: 11 Jan 2009
Posts: 3

View user's profile Send private message

PostPosted: Sun Jan 11, 2009 8:23 am     Reply with quote

I have extracted a part of the project.
The other compiler version is different, obviously.

Commenting out the interrupt enable parts, (if you have observed there is global interrupt set to off) nothing changes.

Thank you.
Alberto
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Jan 11, 2009 11:00 am     Reply with quote

Try commenting out the setup_oscillator() line.
My experience is that sometimes this function causes problems.
_________________
Every solution has a problem.
bertocar1974



Joined: 11 Jan 2009
Posts: 3

View user's profile Send private message

PostPosted: Sun Jan 11, 2009 12:20 pm     Reply with quote

Thank you!

That is the problem, setting OSCCON manually resolved the problem.

Maybe a CCS bug?

Best regards,
Alberto
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