Author Topic: New with PIC18  (Read 9903 times)

0 Members and 1 Guest are viewing this topic.

Offline ect_09Topic starter

  • Contributor
  • Posts: 17
New with PIC18
« on: October 16, 2014, 07:44:32 am »
Hello,
I am new with this site but find a good discussion here. am student and am interested to learn PIC18f . but i dont know how i should started.
i download many books but these book didnt explain the things as i want to know. :palm: |O
please guide me in this way . i want to work on real time hardware. i made a generic board where i can burn the .HEX file to PIC18f452.
am using MPLAB + Hi-Tech compiler. i want to work with it.
please guide me for the language too which language i should prefer for coding.
i know well about C as the beginner and how i can be most familiar with the coding. :(

Respect for all the members ^-^

Regards,

 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #1 on: October 16, 2014, 10:30:12 am »
Quote
i want to work with it.

It is really quite simple:

1) read the device datasheet;
2) read the compiler / ide manuals;
3) code from a simple blinky;
4) code more.
================================
https://dannyelectronics.wordpress.com/
 

Offline dexters_lab

  • Supporter
  • ****
  • Posts: 1890
  • Country: gb
Re: New with PIC18
« Reply #2 on: October 16, 2014, 11:06:06 am »
when i started i found the tons of  sample code supplied with the mikroelectronica compilers very handy to get going, the trial is free but is limited to 2k but thats enough to use sample code (http://www.mikroe.com/mikroc/pic/)

1) read the device datasheet;
:-+ :-+

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #3 on: October 16, 2014, 12:41:35 pm »
PICs are quite easy to get started on. I would suggest that you put together a simple all-in-one blinky as a template and then go from there.

The tricky part about the PICs is:

1) fuse settings;
2) non-gpio functions: turn them off once you power up.
================================
https://dannyelectronics.wordpress.com/
 

Offline Palmitoxico

  • Regular Contributor
  • *
  • Posts: 55
  • Country: br
  • no
Re: New with PIC18
« Reply #4 on: October 16, 2014, 02:19:02 pm »
I've started programming with PIC microcontrollers (PIC16 and PIC18), but I migrated to AVR due the following reasons:

- AVR are less expensive than PIC;
- The AVR architecture is far more easy to use than PIC12/16/18 (no bank switching, powerful instructions);
- The Atmel Studio is FREE and uses gcc as the C compiler, until now I couldn't find any good open source compiler for PIC;
- More RAM, more FLASH and more speed.

I don't know how the PIC24/32/DSPIC compares with AVR32 or ARM Cortex-M microcontrollers, one advantage from Microchip is that they offer PIC24/32/DSPIC in DIP packages.
 

Offline JTR

  • Regular Contributor
  • *
  • Posts: 107
  • Country: au
Re: New with PIC18
« Reply #5 on: October 16, 2014, 03:38:57 pm »
Quote
i want to work with it.

It is really quite simple:

1) read the device datasheet;
2) read the compiler / ide manuals;
3) code from a simple blinky;
4) code more.

5) Use Google to find the many, many examples and tutorials on the web. Please do it quickly before some one post bozo comes along and turns this into a PIC Vs AVR thread.  :palm:
 

Offline ect_09Topic starter

  • Contributor
  • Posts: 17
Re: New with PIC18
« Reply #6 on: October 16, 2014, 04:55:56 pm »
Quote
To late. ;)

what should i do please
 

Offline Palmitoxico

  • Regular Contributor
  • *
  • Posts: 55
  • Country: br
  • no
Re: New with PIC18
« Reply #7 on: October 16, 2014, 04:59:29 pm »
Quote
i want to work with it.

It is really quite simple:

1) read the device datasheet;
2) read the compiler / ide manuals;
3) code from a simple blinky;
4) code more.

5) Use Google to find the many, many examples and tutorials on the web. Please do it quickly before some one post bozo comes along and turns this into a PIC Vs AVR thread.  :palm:

I'm not saying that is not worth to learn how to program PICs, I'm just suggesting another architecture that I think is easier to develop (in my opinion).

I don't know how much you pay for PICs, but here in Brazil an atmega32 (32KB Flash, 2KB RAM, 16MIPS) costs about the same of an pic16f887 (8K words, 368 bytes RAM, 5MIPS).

One thing that I like from Microchip is that they offer dip packages for a lot of their microcontrollers.
 

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1329
Re: New with PIC18
« Reply #8 on: October 16, 2014, 05:03:52 pm »
Quote
To late. ;)

what should i do please

Top Tip!
Read ALL of the posts and not just the last one... Then you shall know what to do.

Quick Tip: RTFDS and use google.
 

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1329
Re: New with PIC18
« Reply #9 on: October 16, 2014, 05:09:05 pm »
Quote
i want to work with it.

It is really quite simple:

1) read the device datasheet;
2) read the compiler / ide manuals;
3) code from a simple blinky;
4) code more.

5) Use Google to find the many, many examples and tutorials on the web. Please do it quickly before some one post bozo comes along and turns this into a PIC Vs AVR thread.  :palm:

I'm not saying that is not worth to learn how to program PICs, I'm just suggesting another architecture that I think is easier to develop (in my opinion).

I don't know how much you pay for PICs, but here in Brazil an atmega32 (32KB Flash, 2KB RAM, 16MIPS) costs about the same of an pic16f887 (8K words, 368 bytes RAM, 5MIPS).

One thing that I like from Microchip is that they offer dip packages for a lot of their microcontrollers.

Eh, six of one, half a dozen of another, you pays your money you takes your choice.

I find it's best to use both, then pick (no pun intended) the right platform.

I use PIC and AVR (Including Arduino), as well as ARM based (Cortex M3/M4 and ARM9) processors, each one has a right place for a particular task.

As for PIC vs AVR and which one should you choose? Whichever ones makes you happier or has the largest online codebase to beg / borrow / steal from.
There really is too many advantages and disadvantages between them to make that choice for you.  Don't forget the MSP430! :)
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2256
  • Country: ca
Re: New with PIC18
« Reply #10 on: October 17, 2014, 12:46:34 pm »
...I don't know how much you pay for PICs, but here in Brazil an atmega32 (32KB Flash, 2KB RAM, 16MIPS) costs about the same of an pic16f887 (8K words, 368 bytes RAM, 5MIPS).

One thing that I like from Microchip is that they offer dip packages for a lot of their microcontrollers.
For hobby use, the cost of the micro itself is of virtually no concern. If you are going to produce 100 or 1000000 of something, then it matters. But for hobby use, you need cheap, accessible, and easy to use tools to get the project going and done. For PIC, the MPLABX IDE is free and the C compilers are free too (with limitations on the free version). MPLABX comes with a simulator for all PIC micros. The PICkit3 can program and debug every PIC in production, and most PICs that have ever been produced. I love the simulator. I usually test blocks of code in the simulator as I write them, so that by the time I put it all together, it usually just works. I have a PICkit3 and have never used the in-circuit debug for that reason; by the time I program a device, the code works. The PICkit3 is not expensive, but is still several times the price of the micros themselves. You can get AVR programmers for much less, but they are just programmers, not debuggers. An AVR programmer/debugger is comparable in cost to PICkit3. If you need really cheap tools, you can get a PICkit2 clone for $10 to $15 that will program and debug most PICs that take 2.5 to 5 V, but not the newest low voltage ones.
 

Offline the_memristor

  • Newbie
  • Posts: 7
  • Country: de
Re: New with PIC18
« Reply #11 on: October 22, 2014, 09:12:06 pm »
I also started programming with PICs. My advice to you is to catch up a Pickit3 Debug express boundle to get started with PICs. Debugging with this Pickit is very pleasant and reliable.
(http://www.microchipdirect.com/productsearch.aspx?keywords=DV164131)
You can also easily debug your code through MPLAB X. On the microchip website are so many code and application examples from whom you can learn from (http://www.microchip.com/CodeExamplesByFunc.aspx) It's a lot easier to start with the debug express board than building your own PCB because of the possible traps which result in frustration for beginners.

Have much fun and ask if you want more info to begin with PICs ;)
« Last Edit: October 22, 2014, 10:12:17 pm by the_memristor »
 

exapod

  • Guest
Re: New with PIC18
« Reply #12 on: October 22, 2014, 10:37:33 pm »
It is pretty easy to start with the pic18.
What i usually do is create a basic template that i can use for different project.
The first thing that you do is :
open mblabx-> file -> new project -> standalone projet
select the pic that you want to use (PIC18F452)
select your programmer
select the compiler (XC8)
save the project

Create a main.c in the source files folder and a config.h in the header files folder.

Now you have to set the configuration bits of the pic
go to Window -> Pic memory view -> configuration bits
a window pops up and you can configure the bits and then generate a small source code that you can paste in your source files.
The key parts of the configuration bits for a basic project are : the oscillator , the watchdog timer and the lvp ( both off) .

Now that you have the config bits you write your main including the p18f452.h and all the other libraries that you want.

main.c
Code: [Select]
#include <p18f452.h>
#include "config.h"

void main (void)
{
OSCCON = 0 ;  //READ THE DATASHEET FOR SETTING THE OSCILLATOR AND CAHNGE THE 0
  while (1)
    {

    }
}

config.h
RC OSCILLATOR
LVP OFF
WDT OFF
Code: [Select]
// PIC18F452 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1H
#pragma config OSC = RC         // Oscillator Selection bits (RC oscillator)
#pragma config OSCS = OFF       // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source))

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bit (Brown-out Reset enabled)
#pragma config BORV = 20        // Brown-out Reset Voltage bits (VBOR set to 2.0V)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 128      // Watchdog Timer Postscale Select bits (1:128)

// CONFIG3H
#pragma config CCP2MUX = ON     // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)

// CONFIG4L
#pragma config STVR = ON        // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET)
#pragma config LVP = OFF        // Low Voltage ICSP Enable bit (Low Voltage ICSP disabled)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000200-001FFFh) not code protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) not code protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) not code protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) not code protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000200-001FFFh) not write protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) not write protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) not write protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) not write protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)

These code is not tested ...

edit: read the documents in Microchip\xc8\v1.31\docs
« Last Edit: October 22, 2014, 10:41:29 pm by exapod »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #13 on: October 22, 2014, 11:16:02 pm »
I am a big fan of pickit2 - reliable and disposable. With the logic / uart tool, it is indispensible if you work on pics.

It does have limited support for newer chips, however.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #14 on: October 22, 2014, 11:29:42 pm »
Quote
What i usually do is create a basic template that i can use for different project.

My approach as well, for all mcus.

Code: [Select]
#include <p18f452.h>

I would just use xc.h instead.

Code: [Select]
#include "config.h"

My approach as well. If you use conditional compilation, you can keep growing config.h each time you work on a new chip so it can be reused in the future.

My config.h is over 100KB now, :)

================================
https://dannyelectronics.wordpress.com/
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: New with PIC18
« Reply #15 on: October 23, 2014, 08:50:37 am »
I started eons ago with RCA 1802 then Z80 etc and on to mcus 16F84 , asm and DIY programmer . eventually grew up skipped PIC18s now having fun with PIC24 , learning all the way .

http://digitaldiy.io/forum/general-electronics/2396-a-diy-pic24h-dev-board#16996

 
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #16 on: October 23, 2014, 10:28:56 am »
now having fun with PIC24 , learning all the way .

http://digitaldiy.io/forum/general-electronics/2396-a-diy-pic24h-dev-board#16996

 

That reminds me of my ghetto PIC24F boards as well.

Yeah, the PIC24 is really a wonderful chip.
================================
https://dannyelectronics.wordpress.com/
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: New with PIC18
« Reply #17 on: October 23, 2014, 12:44:18 pm »
now having fun with PIC24 , learning all the way .

http://digitaldiy.io/forum/general-electronics/2396-a-diy-pic24h-dev-board#16996

 

That reminds me of my ghetto PIC24F boards as well.

Yeah, the PIC24 is really a wonderful chip.

I'm surprised PIC24 does not seem to have taken off with hobbists , do you have a link to your PIC24 board ?
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #18 on: October 23, 2014, 02:01:05 pm »
It is a ghetto-style board on a 44 pin device. I can post a picture when I get some time.
================================
https://dannyelectronics.wordpress.com/
 

exapod

  • Guest
Re: New with PIC18
« Reply #19 on: October 23, 2014, 02:51:06 pm »
+1 for the pic24, i love this family i always have a breadboard with one and also two of this boards http://www.settorezero.com/orbit16/home/ that are very handy.
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: New with PIC18
« Reply #20 on: October 23, 2014, 04:08:31 pm »
dannyf.  Got you. I'm not got into the ' ghetto-style ' term , so dont think i need a pic tar  :)

exapod. Orbit16 looks an interesting PIC24 dev board perhaps room for a 64 pin PIC24H version in future...   
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline atferrari

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: ar
Re: New with PIC18
« Reply #21 on: October 23, 2014, 04:15:58 pm »
It is a ghetto-style board on a 44 pin device. I can post a picture when I get some time.

What does "ghetto-style" means?
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #22 on: October 23, 2014, 10:46:47 pm »
Its nicknamed for a bare minimalist low part count almost deadbug mcu application. It was started here for some stm32 chips.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New with PIC18
« Reply #23 on: October 24, 2014, 01:18:16 am »
Quote
also two of this boards

It doesn't seem to me that those boards offer much value if you are working with pdip chips: breadboard + jump wires and you are in business.

I particularly like the lower-end PIC24F chips, for their remappable pins, abundance of timers, and dedicated input capture and output compare / pwm generation, not to mention numerous change notification pins. Just plain wonderful hardware.

Microchip could have done a better job promoting those chips, however.
================================
https://dannyelectronics.wordpress.com/
 

Offline glatocha

  • Regular Contributor
  • *
  • Posts: 114
Re: New with PIC18
« Reply #24 on: October 24, 2014, 10:16:52 am »
For breadboard use I can recomend the Micristick II board. Really nice one in my opinion, but could have one button for user
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf