Author Topic: Program pic microcontrollers and coding language?  (Read 2447 times)

0 Members and 1 Guest are viewing this topic.

Offline mkube396Topic starter

  • Regular Contributor
  • *
  • Posts: 51
  • Country: us
Program pic microcontrollers and coding language?
« on: December 26, 2024, 02:40:49 pm »
Well i want to try to learn how to program some pic microcontrollers and i know nothing. right now i am getting over wellmed and i need some guidance. 
What is some easy reading that will show working sample code and how it works, how i can use it to make more complex things?

the most i gotten in to was some arduino code that worked as a ROM switcher for my Commodore 64 witch i have working and works good switching 4 banks ina nd out on my EPROM. And a 10M CW beacon for a friend but that was all code that i found online.

I ordered some PIC12F675 to upload "picdiv"  for an over complicated digital clock running off a 10Mhz OCXO because i was board and it would be cool. 
but i would all so like to play with the PIC12F675 i ordered the only thing i seen on youtube was people making lights blink.
« Last Edit: December 26, 2024, 02:53:29 pm by mkube396 »
 

Online Old Printer

  • Frequent Contributor
  • **
  • Posts: 793
  • Country: us
Re: Program pic microcontrollers and coding language?
« Reply #1 on: December 26, 2024, 05:28:00 pm »
I would stick with Arduino until you get to a situation where the Nano wont fit. For a beginner there is so much information available that will make your learning much easier. and faster.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: us
Re: Program pic microcontrollers and coding language?
« Reply #2 on: December 26, 2024, 06:18:45 pm »
Things you will need to program PIC microcontrollers:
  • You need a programmer - PICKit 3 clone at a minimum or a PICKit 4.  PICs DO NOT have a bootloader.

  • I suggest downloading MPLAB X IDE and XC8 C compilier.  Don't beat yourself up with assembly language.  Leaving the Arduino community will be a BIG shock!

  • I would get some PIC16 or PIC18 microcontrollers.  Look for a basic MCU in larger DIL package for a breadboard.  Also, pick one with an internal oscillator so you don't need to mess with crystals.  Those PIC12 4-pin packages are very limiting and you end up dealing with limited I/O pins and the programming pins.  A PIC16F1509 at Mouser is only $1.98  There are PICs that have greater capabilities but they are much harder to program and learn.  Stay away from a PIC32 in the beginning.

  • Download the datasheet for your chosen PIC and get familiar with its registers.  The simpler the PIC the easier it will be to program.

  • You seem to indicate that you don't have much programming experience?  A PIC or any other MCU may be a step too far for a novice programmer.  The Arduino hides a lot of the details to make it easy for beginners.  I would think you can Google some basic PIC examples to get your feet wet before investing a bunch of hardware.  You can write and compile programs without a PIC or programmer to see how difficult it's going to be for you.

 

Offline mkube396Topic starter

  • Regular Contributor
  • *
  • Posts: 51
  • Country: us
Re: Program pic microcontrollers and coding language?
« Reply #3 on: December 26, 2024, 07:22:49 pm »
do i need the "PICKit 3" to program it If have the HEX file can I just program it with my TL866II? I see the chip in the listing? i dont have the chip its on the way but i have my project all wired up to just pop it in and go.

i may just focus on arduino I seem to remember people saying the tools for Pic are kind of a mess to use.
But like i was saying i am being overloaded with all the info out there even if i just concentrate on Arduino i just need a recommendation on where to get a solid start.

 i start looking stuff up and my brain just goes into mush.  so yes i have zero programming experience other then loading other peoples stuff.

i know i can do this if i just have a little guidance i learned how to run and set up a Doosan CNC at work lol.
« Last Edit: December 26, 2024, 07:37:30 pm by mkube396 »
 

Online Picuino

  • Super Contributor
  • ***
  • Posts: 1058
  • Country: es
    • Picuino web
Re: Program pic microcontrollers and coding language?
« Reply #4 on: December 26, 2024, 07:31:42 pm »
ChatGPT can help you program what you want to do, with sample programs in C (which is the language I recommend, along with Microchip's own XC8 compiler).

But why would you want to leave the comfortable world of Arduino to use PIC microcontrollers? The only reason I can find is that you want to use one of their special peripherals (like the CTMU, CLC, etc).
 

Offline mkube396Topic starter

  • Regular Contributor
  • *
  • Posts: 51
  • Country: us
Re: Program pic microcontrollers and coding language?
« Reply #5 on: December 26, 2024, 08:56:36 pm »
Well this video popped up at random ill give it a watch.

 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: us
Re: Program pic microcontrollers and coding language?
« Reply #6 on: December 26, 2024, 09:45:25 pm »
If you already have the TL866II, I would wait and try it.  I'm not familiar with it.
You will probably want one of the PICKit's if you get into PIC in a big way.  You may be limited in which PIC's you can program with the TL866II.

The video you linked is for doing 'assembly' language.  Just DON'T!!!
I gave up assembly language back in the early 90s.  Unless you have a REAL need for speed or memory, it it much easier to program in C (similar to what you did with the Arduino).
 

Offline fzabkar

  • Super Contributor
  • ***
  • Posts: 2798
  • Country: au
Re: Program pic microcontrollers and coding language?
« Reply #7 on: December 26, 2024, 10:19:43 pm »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5166
  • Country: ro
  • .
Re: Program pic microcontrollers and coding language?
« Reply #8 on: December 26, 2024, 10:37:51 pm »
For majority of modern PIC microcontrollers, you can use the cheaper Microchip SNAP :  https://eu.mouser.com/ProductDetail/Microchip-Technology/PG164100?qs=w%2Fv1CP2dgqoaLDDBjfzhMQ%3D%3D

Basically pretty much all modern microcontrollers that use low voltage programming would be supported by this programmer.

Easiest to start would be to install MPLAB-X IDE -  https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide - and XC8 free C compiler (also made by Microchip) which will be downloaded during installation of MPLAB-X if you choose.

When you start MPLAB-X, you can start a new project and select your microcontroller and your programmer and you start writing your C program.

It starts by including your microcontroller's header file, and in your main function, you start by setting up the configuration registers which tell the microcontroller what pins are inputs and which are outputs, if it uses the internal oscillator or not and so on.

The datasheet of the microcontroller will have those two registers explained, and MPLAB-X will also have a wizard that you can use if you're too lazy to write the stuff yourself.

So next step would be watching some youtube videos where one writes a basic program in C for a pic microcontroller, just so you can see the microcontroller doing something.
 

Online MathWizard

  • Super Contributor
  • ***
  • Posts: 1741
  • Country: ca
Re: Program pic microcontrollers and coding language?
« Reply #9 on: December 26, 2024, 11:59:22 pm »
Overall I'm enjoying assembly level coding of AVR MCU's, I automated most of it in a spreadsheet, and it creates the Intel Hex lines, so it's not that tedious.

Just as a hobbist, I had done a little bit of ArduinoIDE C coding over the years, and I just wanted to feel more connected to the hardware, and now it all makes way more sense.

If you aren't familar with the basic parts of an MCU, and want to feel more connected, just watch some video's and/or read some data sheets. And really with BJT's, make some simple circuits on a breadboard, like some logic gates, an SR-latch, an astable multi-vibrator, JK-flip flop, then maybe try some shift registers and 555 timers. You can do all that in simulators too.

So how does bare-metal programming of AVR compare to PIC or ARM ??
« Last Edit: December 27, 2024, 12:09:58 am by MathWizard »
 

Offline lakis70

  • Contributor
  • Posts: 11
  • Country: gr
Re: Program pic microcontrollers and coding language?
« Reply #10 on: December 27, 2024, 12:03:01 am »
The way i learned
Download gpsim simulator, sdcc c compiler, gputils and bought a cheap programmer from ebay
Read the datasheet
learn how to make the ports inputs,  outputs and blink leds,
simulate them and after write your program and retry it
Dont use libraries, you will never learn. Only study how they do it and do it your self.
Also Microchips official ide is a crap some gigabytes.
 

Online MathWizard

  • Super Contributor
  • ***
  • Posts: 1741
  • Country: ca
Re: Program pic microcontrollers and coding language?
« Reply #11 on: December 27, 2024, 12:16:17 am »
I see the company Microchip makes both AVR and PIC MCU's, I need to read the basic's on PIC, and the history of these MCU lines and companies again.
 

Offline SteveThackery

  • Frequent Contributor
  • **
  • Posts: 787
  • Country: gb
Re: Program pic microcontrollers and coding language?
« Reply #12 on: December 27, 2024, 11:01:07 am »
I ordered some PIC12F675 to upload "picdiv"  for an over complicated digital clock running off a 10Mhz OCXO because i was board and it would be cool. 
but i would all so like to play with the PIC12F675 i ordered the only thing i seen on youtube was people making lights blink.

I have to agree with the others: if you have no programming experience, PIC is not the place to start.  Get up to speed on Arduino first, then you might take a look at PIC later on.
 

Offline Electro Fan

  • Super Contributor
  • ***
  • Posts: 3316
Re: Program pic microcontrollers and coding language?
« Reply #13 on: December 27, 2024, 11:08:39 am »
Sounds like you are enthusiastic about PIC and enthusiasm can be fun and energizing - so if you can find the right book or tutorial or teacher or other guidance that meets you where you are and speaks to your interests and needs that might be a good path.

I think choosing a programming language / environment is a little like a new computer user deciding between Microsoft and Apple - either can be a good platform but if the user is on the fence go with the platform where you will have access to the most support from someone or something you can relate to and depend upon. 

As others have suggested, the Arduino might be the best (easiest) way to learn coding in that it will teach some (but not all) coding fundamentals and it provides a ton of readily available resources.  In addition to being a gateway into software it sits close to the entry level intersections of software and hardware, analog and digital, and electricity itself - it has a lot to like for beginners who want to learn and explore by project building.

Another way to get a reasonably quick start with software might be with python.  Tons of resources and you can head toward scripting or compiling as you choose.

Another path - harder but potentially super valuable - would be with C (and/or C++).



https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628?dplnkId=1a3f6186-e360-4b9c-ad16-25ae35f3ac27&nodl=1

https://www.learncpp.com/

A consideration:  In addition to where you can get the best resources for your interests it might depend on how close you want to get to the 1s and 0s of specific hardware vs learning software in general.

https://www.tutorialspoint.com/assembly_programming/assembly_introduction.htm
« Last Edit: December 27, 2024, 11:10:38 am by Electro Fan »
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3974
  • Country: us
Re: Program pic microcontrollers and coding language?
« Reply #14 on: December 27, 2024, 12:22:31 pm »
Some have suggested that PIC's are not the place to start.   Historically, they have been and are where I started.  In 1998, I was making a controller for launching my sailplanes using only hardware logic.  It was getting complicated, and I stumbled on PIC's as they were considered simple.  There were many tutorials for using Assembly and PICList was active.   

Here's a partial list of the tutorials (some may no longer be available):
http://www.amqrp.org/elmer160/lessons/ (seems to be gone)
http://winpicprog.co.uk/pic_tutorial.htm
http://www.gooligum.com.au/PIC-Tutorials (gone -- probably relocated)
http://www.gooligum.com.au/tut_enhanced.html (gone)
http://www.microchip.com/forums/m778472.aspx (links to updated enhanced mid-range)

This link mirrors one of the older tutorials that I used:
https://groups.csail.mit.edu/lbr/stack/pic/pic-prog-assembly.pdf

There were/are so many tutorials that my advice is to pick one and stick with it.  Gooligum is often recommended (it's not what I used at the time).  I have referred to his  set occasionally since.  Winpicprog was also used, but the author (Nigel) gave an example of some code and used the symbol "$" without defining what it meant.  Aside from that, his tutorial seems pretty easy to follow.  The tutorial I used most was "elmer" (first link) and referred to the mstracey one in the MIT link for help.

I started with the PIC12F509 (12-bit core).  It had a couple of fewer instructions than the 14-bit cores had and no interrupts.  In short order, I got the launch gadget done and working.  That hooked me.   I then went to the 12F6xx (14-bit core and interrupts) but still didn't see the need for or use interrupts.  Then slowly advanced to the enhanced mid-range (16F1xxx and later) and started using interrupts when I needed to and not just as a crutch.  I have considered going to the 18F and 24F, but just haven't seen the need to them; although, they do have obvious advantages.

Why did I pick Assembly instead of C?  I am goal oriented and saw Assembly not much different from flowcharting and laboratory porcedure manuals that I had been writing for years.  Simply put, I wanted to get the project done, not waste time learning a higher level language.  In almost no time and without a lot of blog questions, I was able to do that.  I am still stuck in that rut.   If you are serious about doing programming and not just making gadgets, the arguments for C are persuasive.  However, some of the best C-programmers I know have a good basis in Assembly.

The TS has some experience with Arduino.  That may change his direction, but for the time being, he has some
PIC12F675's.  They are perfect for learning Assembly and getting to know the hardware.

EDIT: I checked the above links.  As feared, several are missing or relocated.  Comments have been added.  There are still many more on the internet.



« Last Edit: December 27, 2024, 12:28:39 pm by jpanhalt »
 

Offline Gyro

  • Super Contributor
  • ***
  • Posts: 10134
  • Country: gb
Re: Program pic microcontrollers and coding language?
« Reply #15 on: December 27, 2024, 01:15:02 pm »
The picDIV dividers are written in assembler, this is because they are using exact numbers of CPU clock cycles to perform the frequency division. You will probably find it an easier learning ramp because 1) the code is very simple in this case, 2) you are modifying the existing code rather than starting from scratch and 3) it is a very low-end pic (12F675 iirc) with very simple I/O and very small instruction set.

Your first step is to download the datasheet and study it in conjunction with the code. That should give you a good start.
Best Regards, Chris
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13204
Re: Program pic microcontrollers and coding language?
« Reply #16 on: December 27, 2024, 01:31:25 pm »
Miccrochip Snap cant program older PICs that need high voltage programming.  e.g PIC12F675  OTOH it works nicely for most newer PICS that are low voltage programming only.   


Universal programmers like the TL866II are OK if you are working with socketed DIP chips, but it is generally either not possible or a royal PITA to use a universal programmer for programming a chip in-circuit if you want to use SMD parts, and clam-shell socket adapters for SMD chips are expensive and again a PITA to use.   Therefore if you are doing serious development with PICs you want a supported Microchip ICSP programmer/debugger - MarkF's advice above is good, and jpanhalt has made some good points.   

The Gooligum tutorials can be found on Github: https://github.com/gooligumelec/PIC-tutorials
Grab Midrange.Zip and Midrange_C.zip, which have the tutorial PDFs and sourcecode.  It will start you off with the PIC12F629 which is basically the same chip as the '675 only without an ADC module.  To use a '675 with '629 sourcecode you need to tell the chip to put all pins in digital mode*[ and ignore the ADC before you do anything else with GPIO.   In C that's
Code: [Select]
ANSEL=0;
and in MPASM assembler, that's
Code: [Select]
   bsf STATUS,RP0
   clrf ANSEL
   bcf STATUS,RP0

Note that MPASM was dropped from MPLAB X from v5.40 onwards.  To follow older tutorials that use MPASM you need MPLAB X v5.35, (or possibly MPLAB v8.92 but that's no good for newer versions of XC8) from the Microchip download archive.  The newer assembler bundled with XC8 is very different from MPASM and you will not get anywhere with it using a tutorial written for MPASM.  :(

* You should also disable the analog comparator by loading CMCON with 7, but as the '629 also has this module, code for it should already do this.
« Last Edit: December 27, 2024, 03:20:12 pm by Ian.M »
 

Offline wilfred

  • Super Contributor
  • ***
  • Posts: 1381
  • Country: au
Re: Program pic microcontrollers and coding language?
« Reply #17 on: December 27, 2024, 01:47:32 pm »
One option is Great Cow Basic that allows you to program a PIC in the BASIC language. I don't know much about it but there is a Youtube channel by Evan Venn who has quite a few videos over many years to give you some understanding of it.

Hobby interest in PICs seems to have faded away since Arduino swept all before it but good on you for being willing to go against the crowd. Respect.

Even if you don't go with GCB these videos cover lots of PIC related things and have examples.
This is one playlist on his channel that will serve as an introduction even if you're not using the exact same chip.
 

Offline PGPG

  • Frequent Contributor
  • **
  • Posts: 396
  • Country: pl
Re: Program pic microcontrollers and coding language?
« Reply #18 on: December 27, 2024, 03:19:08 pm »
I see the company Microchip makes both AVR and PIC MCU's, I need to read the basic's on PIC, and the history of these MCU lines and companies again.

Since 2010 we are using Atmels AtXmega microcontrollers (AtXmega are incomparably better than Atmega). Some time ago they were bought by Microchip and hidden in their homepage so effectively that going through selection menu you were not able to find any data about them. Only if you write exact symbol in search box you were able to get to datasheets. I didn't do it for long time, so I don't know how it is now.
When semiconductor crisis (2021/2022, I think) came AtXmegas were probably at the end of Microchip manufacturing preferences and we were able to get confirmation of delivery for a date in 1.5 years.

With PIC microcontrollers we had a problem around 1992 or may be 1993. We failed with project we were doing for someone abroad.
Problem 1.
Programmer (big, expensive and complicated with separate adapters for each case) officially signed by Microchip had a feature that it burned every processor when trying to do a blankcheck.
We had got 10 microcontrollers to do the project. We burned 5 of them with this programmer before we found the reason.
Programmer had uA78S40 based DCDC to generate VPP. And when its output were switched from 5V to 25V it was going from 5V to 25V but through over 40V what was too high for ICs.
Problem 2.
Bugs in microcontroller.
Trying to write the software we discovered 3 microcontroller internal bugs and found our way-around. But the fourth bug defeated us. The bug effect was that an incoming interrupt was missed about once in 3 thousand interrupts and what we had to do just had be based on counting this interrupts. We couldn't find a way around this problem.
We FAXed to Microchip but get no answer.
About 1.5 years later there were first Microchip seminar in our country ever. There we get promise to get microcontroller we used errata and 3 months later we got it. There were 6 bugs (from which 3 we found ourselves). The way around for bug with interrupt missing from time to time was to build external circuit synchronizing incoming slopes with microcontroller clock.
Our decision was to never more use PIC microcontrollers.
 

Offline Le_Bassiste

  • Frequent Contributor
  • **
  • Posts: 296
  • Country: de
Re: Program pic microcontrollers and coding language?
« Reply #19 on: December 27, 2024, 03:27:50 pm »
... Note that MPASM was dropped from MPLAB X from v5.40 onwards.  To follow older tutorials that use MPASM you need MPLAB X v5.35, (or possibly MPLAB v8.92 but that's no good for newer versions of XC8) from the Microchip download archive.  The newer assembler bundled with XC8 is very different from MPASM and you will not get anywhere with it using a tutorial written for MPASM.  :(

and just to add insult to injury:
1.
mpasm will not work on 64-bit Windows, so you have to install MPLAB X  v5.35 on a 32-bit Windows
2.
however, GnuWin32 is missing in MPLABX_V5.35 distro, you will get a "make.exe not found" error. it must be installed here:
C:\Program Files\Microchip\MPLABX\v5.35\gnuBins\GnuWin32
3.
but then, a typo (either in MPLABX_v5.35 or in the name of the called binary) results in "gnumkdir not found"   error:
copy C:\Program Files\Microchip\MPLABX\v5.35\gnuBins\GnuWin32\bin\gmkdir.exe
to    C:\Program Files\Microchip\MPLABX\v5.35\gnuBins\GnuWin32\bin\gnumkdir.exe.
An assertion ending with a question mark is a brain fart.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13204
Re: Program pic microcontrollers and coding language?
« Reply #20 on: December 27, 2024, 04:20:42 pm »
That's odd, because I normally run MPLAB 8.92's MPASMWIN and also MPLAB X 5.25 on 64 bit Win10 Pro 22H2.   Maybe they <explitive>ed up MPASM between v5.25 and v5.35?

When I get home I'll have to check MPASM still works as its been a while . . .

I haven't had a 32 bit OS on my main machine for over six years.  IIRC it was quite a PITA getting Win16 application support working and re-enabling WinHlp32 for some legacy software !


« Last Edit: December 27, 2024, 04:26:34 pm by Ian.M »
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6366
  • Country: es
Re: Program pic microcontrollers and coding language?
« Reply #21 on: December 27, 2024, 04:26:22 pm »
MplabX IDE, XC8 compiler (It's free up to "O2" optimization, no code size limit).
Any programmer you want, but pickit 3 is cheap and will let you step/debug the code.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Le_Bassiste

  • Frequent Contributor
  • **
  • Posts: 296
  • Country: de
Re: Program pic microcontrollers and coding language?
« Reply #22 on: December 27, 2024, 07:18:26 pm »
That's odd, because I normally run MPLAB 8.92's MPASMWIN and also MPLAB X 5.25 on 64 bit Win10 Pro 22H2.   Maybe they <explitive>ed up MPASM between v5.25 and v5.35?

When I get home I'll have to check MPASM still works as its been a while . . .

I haven't had a 32 bit OS on my main machine for over six years.  IIRC it was quite a PITA getting Win16 application support working and re-enabling WinHlp32 for some legacy software !

mpasmwin.exe (named "MPASM for Windows 9x" on the HELP  window) does work on Windows 10 64-bit (just tested it), but mpasm does not.
« Last Edit: December 27, 2024, 07:22:40 pm by Le_Bassiste »
An assertion ending with a question mark is a brain fart.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: us
Re: Program pic microcontrollers and coding language?
« Reply #23 on: December 27, 2024, 07:34:07 pm »
Just an observation here. 
If you go with the PICKit 3, the latest version of MPLAB X that works with it is version 3.55.
You can download it here (page 4).
Newer versions of MPLAB X have/or won't connect to the PICKit 3.
I'm using Win7.
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6366
  • Country: es
Re: Program pic microcontrollers and coding language?
« Reply #24 on: December 27, 2024, 07:49:21 pm »
I think you're refering to pickit2, the pickit3 works perfectly, at least until v6.10 which I used last time.

Edit: pickit 3 support was gone in v6.25, happened just 6 months ago:
https://www.microchip.com/en-us/about/media-center/blog/2024/discontinued-ide-support-for-gen3-tools
« Last Edit: December 27, 2024, 07:56:09 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf