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 members
Regards,
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.
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;
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.
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.
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.
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.
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.
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.
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.
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!
...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.
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
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
#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
// 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
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.
What i usually do is create a basic template that i can use for different project.
My approach as well, for all mcus.
#include <p18f452.h>
I would just use xc.h instead.
#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,
It is a ghetto-style board on a 44 pin device. I can post a picture when I get some time.
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...
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?
Its nicknamed for a bare minimalist low part count almost deadbug mcu application. It was started here for some stm32 chips.
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.
For breadboard use I can recomend the Micristick II board. Really nice one in my opinion, but could have one button for user