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

PIC18F26j50 Example code

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



Joined: 31 Oct 2014
Posts: 7

View user's profile Send private message

PIC18F26j50 Example code
PostPosted: Fri Oct 31, 2014 9:59 am     Reply with quote

Hi,

I would like to see an example code of a PIC18F26J50 running? could be a simple Titled LED ... Does anybody has one?

I need also the FUSES and specifying me if you are using an external crystal and the version of the CCS compiler.

I tried different version of the CCS compiler, with and without Ext Crystal and don't have succes!

Thanks!

Matt.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 10:05 am     Reply with quote

Why don't you show us what you have code wise and and what configuration
you want then we can help you figure out where you went wrong?
_________________
Google and Forum Search are some of your best tools!!!!
matamicen



Joined: 31 Oct 2014
Posts: 7

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 10:12 am     Reply with quote

Ok, good idea ...

I have an externa 12mhz OSC.

This is the code:


the "MAIN.H"

#include <18F26J50.h>
#FUSES NOWDT
#FUSES NODEBUG
#FUSES NOXINST
#FUSES NOPROTECT
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES NOCPUDIV
#FUSES HSPLL
#FUSES PLL3
#FUSES RTCOSC_INT

#USE fixed_io(c_outputs = PIN_C0, PIN_C1)

#use delay(clock=48000000)



THE MAIN.C


#include <main.h>


#define LED PIN_C0

void main()
{
setup_adc(ADC_OFF); //disable ADC

setup_oscillator(OSC_PLL_ON);

set_tris_c(0xFF);
//Example blinking LED program
while(true){
output_high(LED);
delay_ms(1000);
output_low(LED);
delay_ms(1000);
}

}
matamicen



Joined: 31 Oct 2014
Posts: 7

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 10:20 am     Reply with quote

I deleted set_tris_c(0xFF); and add set_tris_c(0x00); and no success :(
temtronic



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

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 11:15 am     Reply with quote

1) learn to use the 'code' button when posting code. It'll make it a LOT easier for us to debug, cut and paster, etc.
2) get rid of the use fixed_io() statement.Let the compiler handle the I/O. CCS makes it easy to do and until you're really,really good at coding and NEED a wee bit faster operation, fixed_io() is not necessary.

hth
jay
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 11:51 am     Reply with quote

This code works using the internal oscillator on the 25J50 which is the exact same chip with less memory.
Code:

#include <18F25J50.h>
#FUSES INTRC_IO
#FUSES NOWDT
#FUSES NODEBUG
#FUSES NOXINST
#FUSES NOPROTECT
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES NOCPUDIV
#use delay(internal=8000000)

#define LED PIN_C0

void main()
{
    setup_adc(ADC_OFF); //disable ADC

    //Example blinking LED program
    while(true)
         {
           output_toggle(LED);
           delay_ms(500);
          }

  }

_________________
Google and Forum Search are some of your best tools!!!!
matamicen



Joined: 31 Oct 2014
Posts: 7

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 2:33 pm     Reply with quote

Thanks dyeatman, I will try it.

By the way, Which compiler of CCS are using you with this code?

Thanks.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 3:09 pm     Reply with quote

The latest PCWHD version 5.030
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 3:51 pm     Reply with quote

Have been using the 26J50 for ages.

The following configuration has worked successfully for the last 30+ compiler versions for an almost identical setup:
Code:

#include <18F26J50.h>
#device adc=10
#FUSES HSPLL, NOWDT, PLL3, NOXINST, NOCPUDIV, NOFCMEN, NOIESO, NOIOL1WAY
#use delay(clock=48MHz)


Originally compiled with 4.137, then 4.141, then 5.010, then 5.028. All worked the same.
matamicen



Joined: 31 Oct 2014
Posts: 7

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 9:48 pm     Reply with quote

Ttelmah thanks for your answer, with that fuses you use a 12mhz external Osc?

Matt
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sat Nov 01, 2014 1:31 am     Reply with quote

Yes.

Remember that MCLR needs to be pulled up (these chips don't have a NOMCLR fuse).
Even if not using USB, you need the supply connection to Vusb, if you are going to use RC4/RC5. They say the pin can be left floating if you don't use these pins, but behaviour is then erratic, unless the pin has a decoupling capacitor on it.
Look carefully at your supply connections. If you are running from 3.3v, you need the capacitor on Vddcore. For USB operation, the easiest configuration is to use 3.3v as the main supply, which can then also feed Vusb, with two decoupling capacitors close to the pins, and then another decoupler on Vddcore. The decoupling on Vddcore is vital. I use a 10uF SMD ceramic capacitor right adjacent to the chip.
matamicen



Joined: 31 Oct 2014
Posts: 7

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 8:30 am     Reply with quote

Thanks guys! it's working, both examples are working.

The thing is the example with the 12Mhz OSC I changed the delay, I put 12MHZ instead of 48MHZ in de delay ... the blinking LED it was taking 4 seconds instead of one second.

The example without OSC, it's ok with the DELAY but in the pickit2 there is a warning message: "Warning: No Configuration words in hex file. In MPLAB use File-Export to save hex with config"

Do you know what is this message? This message don't appear in the example with the 12Mhz OSC.

Thanks!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 10:19 am     Reply with quote

To run correctly at 12MHz, it sounds like HS is being selected, not HSPLL. With HS, the CPU will run 'off' the crystal directly, not from the PLL.

So, it sounds as if something is interfering with the configuration words coming from the compiler. You mention MPLAB for the first time.
Are you compiling 'inside' MPLAB?. If so, are you sure you have got 'release' selected, not 'debug'?. If debug is selected, MPLAB will override some of the fuses (shouldn't include the oscillator), to be compatible with debug operation. This might cause problems. Do you have the CCS IDE?. If so, what Object file format is selected?.

Have you got the latest firmware in the PicKit?. This exact behaviour is what you see if you are running firmware older than 2.32.00
matamicen



Joined: 31 Oct 2014
Posts: 7

View user's profile Send private message

PostPosted: Fri Nov 07, 2014 1:18 pm     Reply with quote

Ttelmah, now everything is working normally, I think it was a bad connection cause by myself Smile

Thanks!!
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