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

Oscillator Problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
OE8PCK



Joined: 19 Apr 2009
Posts: 14
Location: Klagenfurt, AUSTRIA

View user's profile Send private message

Oscillator Problem
PostPosted: Tue Apr 21, 2009 4:36 am     Reply with quote

I am a complete beginner and have just got past the blinking led stage.
I have successfully got the blinking led programs working on the 18F452 but BUT now my problem is that the 20 MHz Crystal works with a PIC 18F452 and the blinking led program but when I use the same program and only change the processor to PIC18F4550 and compile it the oscillator does not work. The fuse is set to HS. I have changed all the oscillator components and crystal but still it does not work. When I use a more complicated program then the oscillator does not work with either processor. I am beginning to think that I have a setting wrong in MPLAB and PICC but have no idea where to start looking... any ideas???
Thanks for reading, Paul OE8PCK
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Apr 21, 2009 7:51 am     Reply with quote

care to :
1- post the actual code , showing your full fuses statement ?
2- compiler version ?
3- and you are programming the PIC with WHAT ?
OE8PCK



Joined: 19 Apr 2009
Posts: 14
Location: Klagenfurt, AUSTRIA

View user's profile Send private message

PostPosted: Tue Apr 21, 2009 9:02 am     Reply with quote

I have now got the oscillator working. It was an electronic problem. Program still does not work but I need to look into it more carefully. I am using a ICD2LE in combination with MPLAB ver. 8.00. the compiler is PCWH ver.3.212 IDE. I will post the problem if I cannot get any further.
Thank you very much for your kind help.
Paul OE8PCK
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

that compiler ver
PostPosted: Tue Apr 21, 2009 4:06 pm     Reply with quote

BTW:

3.1xx is a pretty old compiler - ESPECIALLY if using 18F parts
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Apr 21, 2009 4:59 pm     Reply with quote

Even worse, v3.212 was an unstable version with some serious PIC18 problems. The v3.2xx version of the compiler became usable at v3.226.
Guest








PostPosted: Tue Apr 21, 2009 11:01 pm     Reply with quote

Thanks for the comments. Got everything working except for the LCD display in one line but I will get that going too. I am just a hobby programmer, if you can call me that, so newer version of compilers are out of my financial reach. Sad
Thanks again,
Paul OE8PCK
OE8PCK



Joined: 19 Apr 2009
Posts: 14
Location: Klagenfurt, AUSTRIA

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 12:32 am     Reply with quote

Sorry for some reason I was a guest. Everything is now working and the LCD displays everthing in one line. This all works on the 18F452 but not on the 18F4550. I suppose the compiler is at fault as you mentioned.
Thanks for your help. If anyone knows a work around so that the 18F4550 works too since it compiles ok then please comment.
Regards, Paul OE8PCK
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 12:38 am     Reply with quote

Post the #define statements for the pins that you are using for LCD
on the 18F4550.
OE8PCK



Joined: 19 Apr 2009
Posts: 14
Location: Klagenfurt, AUSTRIA

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 12:57 am     Reply with quote

I have posted all that I am using. It works well with 18F452.

Paul OE8PCK


Code:
#include<18f4550.h>
#include<stdlib.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
#include<Flex_lcd_16x1.c>
#fuses HS,NOPROTECT,NOWDT,NOLVP,NOBROWNOUT
#define Wandlerkonstante 0.0196

main()
{
      
      int wert1=0;
      float spannung;
      lcd_init();
      delay_ms(100);
      setup_port_a(AN0);
      setup_adc(ADC_CLOCK_INTERNAL);
      set_adc_channel(0);

      while(true)
      {
         delay_ms(1000);
         output_high(pin_c1);
         printf(lcd_putc,"\f");
         printf(lcd_putc,"AD-Wandlung");
         set_adc_channel(0);

         delay_ms(10);
         wert1=Read_ADC();
         delay_ms(10);

         printf(lcd_putc,"\f");
         printf(lcd_putc,"Eingang1:%3u",wert1);
         delay_ms(1);
         printf(lcd_putc,"\f");
         printf(lcd_putc,"Messung ende");
         delay_ms(1);
         spannung=(wert1*Wandlerkonstante);
         printf(lcd_putc,"\f");
         printf(lcd_putc,"Spannung=%3.2f V",spannung);
         printf("Spannung = %3.2f Volt  ",spannung);
         printf("delay_ms(2000);
         output_low(pin_c1);
      }
}







// Flex_lcd_16x1.c

// These are randomly assigned pins, used to test
// that the driver can work with any arrangement
// of i/o pins.
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7

#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_E PIN_D2

/*
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7

#define LCD_RS PIN_E0
#define LCD_RW PIN_E1
#define LCD_E PIN_E2
*/

// If you want to use a 6-pin interface for your LCD, then
// connect the R/W pin on the LCD to ground and comment
// out the following line. A 6-pin interface to the LCD
// is used if only have a few free i/o pins available on
// your PIC, and you want to use the smallest possible
// number of pins for the LCD.
#define USE_LCD_RW 1

//========================================
// Use "2 lines" as the lcd type for the 16x1 LCD.
// The LCD is the same as an 8x2 LCD, but with the
// bottom line appended on the right side of the first line.
#define LCD_TYPE 2 // 0=5x7, 1=5x10, 2=2 lines
#define LCD_2ND_HALF_ADDRESS 0x40

#define LCD_WIDTH 16
#define LCD_HALF_WIDTH (LCD_WIDTH)

int8 const LCD_INIT_STRING[4] =
{
0x20 | (LCD_TYPE << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};

int8 lcd_xcoord;


//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note: !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));

delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}

//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine. For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.

#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3

retval = 0;

output_high(LCD_E);
delay_us(1);

retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);

output_low(LCD_E);
delay_us(1);

return(retval);
}
#endif

//---------------------------------------
// Read a byte from the LCD and return it.

#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
int8 low;
int8 high;

output_high(LCD_RW);
delay_cycles(1);

high = lcd_read_nibble();

low = lcd_read_nibble();

return((high << 4) | low);
}
#endif

//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);

#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(), 7)) ;
#else
delay_us(60);
#endif

if(address)
output_high(LCD_RS);
else
output_low(LCD_RS);

delay_cycles(1);

#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif

output_low(LCD_E);

lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}

//----------------------------
void lcd_init(void)
{
int8 i;

output_low(LCD_RS);

#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif

output_low(LCD_E);

// Some LCDs require 15 ms minimum delay after
// power-up. Others require 30 ms. I'm going
// to set it to 35 ms, so it should work with
// all of them.
delay_ms(35);

for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);

// If the R/W signal is not used, then
// the busy bit can't be polled. One of
// the init commands takes longer than
// the hard-coded delay of 60 us, so in
// that case, lets just do a 5 ms delay
// after all four of them.
#ifndef USE_LCD_RW
delay_ms(5);
#endif
}

lcd_xcoord = 1;
}

//----------------------------
// The x-coordinate can be 1 to 16.
// The y coordinate is ignored.
// This x,y interface is kept in order to be
// consistent with other CCS LCD drivers.
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;

// Update the global x-coordinate variable with the
// current x coordinate.
lcd_xcoord = x;

// Convert the x-coordinate from CCS format (1-16) to
// the 0-15 format used by the LCD hardware.
address = x - 1;

// If the x-coordinate is within the 2nd half of the
// LCD line, the address must be adjusted because
// of the special architecture of the 8x2 LCD.
if(address >= LCD_HALF_WIDTH)
{
address += (LCD_2ND_HALF_ADDRESS - LCD_HALF_WIDTH);
}

lcd_send_byte(0, 0x80 | address);
}


//-----------------------------
void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
delay_ms(2);
lcd_xcoord = 1;
break;

case '\n':
lcd_gotoxy(1,1); // Goto start of line 1
break;

case '\b':
lcd_send_byte(0, 0x10);
lcd_xcoord--;
if(lcd_xcoord == LCD_HALF_WIDTH)
lcd_gotoxy(LCD_HALF_WIDTH, 1);
break;

default:
lcd_send_byte(1, c);
lcd_xcoord++;
if(lcd_xcoord == (LCD_HALF_WIDTH +1))
lcd_gotoxy(LCD_HALF_WIDTH +1, 1);
break;
}
}

//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;

lcd_gotoxy(x,y);

// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));

output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);

return(value);
}
#endif
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 24, 2009 1:19 am     Reply with quote

I didn't need the whole driver. All I wanted was the list of pins at the top.
But, I can see that by changing the LCD_HALF_WIDTH value to be the
width of the LCD, all you have done is to turn the 16x1 driver into the
16x2 driver and then use only the first line. This means that the Batron
TN11605 is one of the few 16x1 LCD's that are one continuous line.

To trouble-shoot your problem with the 18F4550:

1. First prove that it will do anything. In other words, prove that it's not
dead. Make a simple test program to blink an LED. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=29387&start=2

2. Then make a simple "Hello World" test program to test your LCD.
Get rid of 90% of your code. Just call lcd_init(), then call lcd_putc()
to display Hello World, and then hit a while(1) statement at the end of
main(). You don't need anything else in main(). Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=25994&start=3
OE8PCK



Joined: 19 Apr 2009
Posts: 14
Location: Klagenfurt, AUSTRIA

View user's profile Send private message

PostPosted: Sat Apr 25, 2009 5:23 am     Reply with quote

OK, so this is getting really spooky! I cannot get the 18f4550 to run a blinking led program. The oscillator runs ok, and wait for it, the chip are new out of a sample set of 5 that I got from Microchip. All 5 do not work!Now do I send them back or is there another test? One thought is that this chip needs something else during programming than the 18f452.
Sorry to be a pain.

Regards, Paul OE8PCK
Ttelmah
Guest







PostPosted: Sat Apr 25, 2009 8:52 am     Reply with quote

Two comments:
1) Put the 'program' includes (stdlib, and flex_lcd), _after_ the setup lines (clock, and fuses). Not doing so, could lead to problems if there are delay statements in these. This should be treated as the 'right order' for CCS.
2) Add the fuse 'NOXINST'. The 452, doesn't have the extended instruction set, and this must be off for CCS.

Best Wishes
OE8PCK



Joined: 19 Apr 2009
Posts: 14
Location: Klagenfurt, AUSTRIA

View user's profile Send private message

PostPosted: Sat Apr 25, 2009 9:29 am     Reply with quote

Ttelmah wrote:
Two comments:
1) Put the 'program' includes (stdlib, and flex_lcd), _after_ the setup lines (clock, and fuses). Not doing so, could lead to problems if there are delay statements in these. This should be treated as the 'right order' for CCS.
2) Add the fuse 'NOXINST'. The 452, doesn't have the extended instruction set, and this must be off for CCS.

Best Wishes


I have now got a simple led blinker which does not run with the 18F4550. I have followed your instructions and get the following error message.


Regards, Paul OE8PCK

Code:
#include <18F4550.h>
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP, NOXINST
#use delay(clock=20000000)

//====================================
void main()
{

// Blink an LED on pin B1.
while(1)
  {
   output_high(PIN_B1);   
   delay_ms(500);
   output_low(PIN_B1);
   delay_ms(500);
  }

}




Clean: Deleting intermediary and output files.
Clean: Deleted file "Blinking LED18F4550.$$$".
Clean Warning: File "C:\Programme\PICC\Blinking LED18F4550.o" doesn't exist.
Clean: Deleted file "Blinking LED18F4550.HEX".
Clean: Deleted file "Blinking LED18F4550.LST".
Clean: Deleted file "Blinking LED18F4550.PJT".
Clean: Deleted file "Blinking LED18F4550.ERR".
Clean: Deleted file "Blinking LED18F4550.COF".
Clean: Deleted file "C:\Programme\PICC\Blinking LED 18F4550.mcs".
Clean: Done.
Executing: "C:\Programme\PICC\Ccsc.exe" +FH "Blinking LED18F4550.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 111 "C:\Programme\PICC\Blinking LED18F4550.c" Line 2(7,49): Unknown keyword in #FUSES   "NOXINST"
      1 Errors,  0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Sat Apr 25 17:09:48 2009

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 25, 2009 10:43 am     Reply with quote

From ckielstra:
Quote:

Even worse, v3.212 was an unstable version with some serious PIC18
problems. The v3.2xx version of the compiler became usable at v3.226.

Your version apparently doesn't accept the NOXINST fuse. Compile the
blink program without that fuse (so it will compile), and post the list of
fuse settings from the bottom of the .LST file.
For example, when I compile the blink program with vs. 4.090 I get this:
Code:

Configuration Fuses:
   Word  1: 0C00   NOIESO NOFCMEN HS PLL1 CPUDIV1 NOUSBDIV
   Word  2: 1E1E   BROWNOUT NOWDT BORV20 PUT WDT32768 NOVREGEN
   Word  3: 8300   PBADEN CCP2C1 MCLR NOLPT1OSC
   Word  4: 0081   STVREN NODEBUG NOLVP NOXINST NOICPRT
   Word  5: C00F   NOPROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB

If you do this, we can verify that your version is at least using NOXINST
as the default.
OE8PCK



Joined: 19 Apr 2009
Posts: 14
Location: Klagenfurt, AUSTRIA

View user's profile Send private message

PostPosted: Sun Apr 26, 2009 2:54 am     Reply with quote

PCM programmer wrote:
From ckielstra:
Quote:

Even worse, v3.212 was an unstable version with some serious PIC18
problems. The v3.2xx version of the compiler became usable at v3.226.

Your version apparently doesn't accept the NOXINST fuse. Compile the
blink program without that fuse (so it will compile), and post the list of
fuse settings from the bottom of the .LST file.
For example, when I compile the blink program with vs. 4.090 I get this:
Code:

Configuration Fuses:
   Word  1: 0C00   NOIESO NOFCMEN HS PLL1 CPUDIV1 NOUSBDIV
   Word  2: 1E1E   BROWNOUT NOWDT BORV20 PUT WDT32768 NOVREGEN
   Word  3: 8300   PBADEN CCP2C1 MCLR NOLPT1OSC
   Word  4: 0081   STVREN NODEBUG NOLVP NOXINST NOICPRT
   Word  5: C00F   NOPROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB

If you do this, we can verify that your version is at least using NOXINST
as the default.





Configuration Fuses:
Word 1: 2200 HS NOOSCSEN
Word 2: 1E0E BROWNOUT NOWDT BORV20 PUT WDT32768
Word 3: 8383 NOWAIT MCU CCP2C1 MCLR ECCPE
Word 4: 0081 STVREN NODEBUG NOLVP
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 400F NOEBTR NOEBTRB

I hope this is correct.

Regards, Paul OE8PCK
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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