New with PIC18 - Page 1
Forum section: electronics / general

author: ect_09
author_rank: Contributor
timestamp: October 16, 2014, 07:44:32 am
content: 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.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 membersRegards,

author: dannyf
author_rank: Super Contributor
timestamp: October 16, 2014, 10:30:12 am
content: QuoteIt is really quite simple:1) read the device datasheet;2) read the compiler / ide manuals;3) code from a simple blinky;4) code more.

author: dexters_lab
author_rank: Unknown
timestamp: October 16, 2014, 11:06:06 am
content: 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/)Quote from: dannyf on October 16, 2014, 10:30:12 am

author: dannyf
author_rank: Super Contributor
timestamp: October 16, 2014, 12:41:35 pm
content: 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.

author: Palmitoxico
author_rank: Regular Contributor
timestamp: October 16, 2014, 02:19:02 pm
content: 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.

author: JTR
author_rank: Regular Contributor
timestamp: October 16, 2014, 03:38:57 pm
content: Quote from: dannyf on October 16, 2014, 10:30:12 am5) 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.

author: ect_09
author_rank: Contributor
timestamp: October 16, 2014, 04:55:56 pm
content: Quotewhat should i do please

author: Palmitoxico
author_rank: Regular Contributor
timestamp: October 16, 2014, 04:59:29 pm
content: Quote from: JTR on October 16, 2014, 03:38:57 pmI'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.

author: Wilksey
author_rank: Super Contributor
timestamp: October 16, 2014, 05:03:52 pm
content: Quote from: ect_09 on October 16, 2014, 04:55:56 pmTop 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.

author: Wilksey
author_rank: Super Contributor
timestamp: October 16, 2014, 05:09:05 pm
content: Quote from: Palmitoxico on October 16, 2014, 04:59:29 pmEh, 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!

author: macboy
author_rank: Super Contributor
timestamp: October 17, 2014, 12:46:34 pm
content: Quote from: Palmitoxico on October 16, 2014, 04:59:29 pmFor 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 programand debugevery 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.

author: the_memristor
author_rank: Newbie
timestamp: October 22, 2014, 09:12:06 pm
content: 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

author: Unknown
author_rank: Unknown
timestamp: October 22, 2014, 10:37:33 pm
content: 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 projetselect the pic that you want to use (PIC18F452)select your programmerselect the compiler (XC8)save the projectCreate 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 picgo to Window -> Pic memory view -> configuration bitsa 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.cCode:#include <p18f452.h>#include "config.h"void main (void){OSCCON = 0 ; //READ THE DATASHEET FOR SETTING THE OSCILLATOR AND CAHNGE THE 0while (1){}}config.hRC OSCILLATORLVP OFFWDT OFFCode:// 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

author: dannyf
author_rank: Super Contributor
timestamp: October 22, 2014, 11:16:02 pm
content: 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.

author: dannyf
author_rank: Super Contributor
timestamp: October 22, 2014, 11:29:42 pm
content: QuoteMy approach as well, for all mcus.Code:#include <p18f452.h>I would just use xc.h instead.Code:#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,

author: 22swg
author_rank: Frequent Contributor
timestamp: October 23, 2014, 08:50:37 am
content: 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

author: dannyf
author_rank: Super Contributor
timestamp: October 23, 2014, 10:28:56 am
content: Quote from: 22swg on October 23, 2014, 08:50:37 amThat reminds me of my ghetto PIC24F boards as well.Yeah, the PIC24 is really a wonderful chip.

author: 22swg
author_rank: Frequent Contributor
timestamp: October 23, 2014, 12:44:18 pm
content: Quote from: dannyf on October 23, 2014, 10:28:56 amI'm surprised PIC24 does not seem to have taken off with hobbists , do you have a link to your PIC24 board ?

author: dannyf
author_rank: Super Contributor
timestamp: October 23, 2014, 02:01:05 pm
content: It is a ghetto-style board on a 44 pin device. I can post a picture when I get some time.

author: Unknown
author_rank: Unknown
timestamp: October 23, 2014, 02:51:06 pm
content: +1 for the pic24, i love this family i always have a breadboard with one and also two of this boardshttp://www.settorezero.com/orbit16/home/that are very handy.

author: 22swg
author_rank: Frequent Contributor
timestamp: October 23, 2014, 04:08:31 pm
content: dannyf. Got you. I'm not got into the ' ghetto-style ' term , so dont think i need a pic tarexapod. Orbit16 looks an interesting PIC24 dev board perhaps room for a 64 pin PIC24H version in future...

author: atferrari
author_rank: Frequent Contributor
timestamp: October 23, 2014, 04:15:58 pm
content: Quote from: dannyf on October 23, 2014, 02:01:05 pmWhat does "ghetto-style" means?

author: dannyf
author_rank: Super Contributor
timestamp: October 23, 2014, 10:46:47 pm
content: Its nicknamed for a bare minimalist low part count almost deadbug mcu application. It was started here for some stm32 chips.

author: dannyf
author_rank: Super Contributor
timestamp: October 24, 2014, 01:18:16 am
content: QuoteIt 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.

author: glatocha
author_rank: Regular Contributor
timestamp: October 24, 2014, 10:16:52 am
content: For breadboard use I can recomend the Micristick II board. Really nice one in my opinion, but could have one button for user

author: dannyf
author_rank: Super Contributor
timestamp: October 24, 2014, 11:16:25 am
content: QuoteIt is a good board for the PIC chips.If you are willing to go outside of it, lots of el cheapo boards, like the discovery or nucleo boards. Much more value / performance for less money. But the learning curve is steeper.