Program pic microcontrollers and coding language? - Page 1
Forum section: electronics / beginners

author: mkube396
author_rank: Regular Contributor
timestamp: December 26, 2024, 02:40:49 pm
content: 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.

author: Old Printer
author_rank: Frequent Contributor
timestamp: December 26, 2024, 05:28:00 pm
content: 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.

author: MarkF
author_rank: Super Contributor
timestamp: December 26, 2024, 06:18:45 pm
content: 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.

author: mkube396
author_rank: Regular Contributor
timestamp: December 26, 2024, 07:22:49 pm
content: 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.

author: Picuino
author_rank: Super Contributor
timestamp: December 26, 2024, 07:31:42 pm
content: 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).

author: mkube396
author_rank: Regular Contributor
timestamp: December 26, 2024, 08:56:36 pm
content: Well this video popped up at random ill give it a watch.

author: MarkF
author_rank: Super Contributor
timestamp: December 26, 2024, 09:45:25 pm
content: 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).

author: fzabkar
author_rank: Super Contributor
timestamp: December 26, 2024, 10:19:43 pm
content: https://picaxe.com/

author: mariush
author_rank: Super Contributor
timestamp: December 26, 2024, 10:37:51 pm
content: 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%3DBasically 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.

author: MathWizard
author_rank: Super Contributor
timestamp: December 26, 2024, 11:59:22 pm
content: 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 ??

author: lakis70
author_rank: Contributor
timestamp: December 27, 2024, 12:03:01 am
content: The way i learnedDownload gpsim simulator, sdcc c compiler, gputils and bought a cheap programmer from ebayRead the datasheetlearn how to make the ports inputs, outputs and blink leds,simulate them and after write your program and retry itDont 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.

author: MathWizard
author_rank: Super Contributor
timestamp: December 27, 2024, 12:16:17 am
content: 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.

author: SteveThackery
author_rank: Super Contributor
timestamp: December 27, 2024, 11:01:07 am
content: Quote from: mkube396 on December 26, 2024, 02:40:49 pmI have to agree with the others: if you have no programming experience, PIC isnotthe place to start. Get up to speed on Arduino first, then you might take a look at PIC later on.

author: Electro Fan
author_rank: Super Contributor
timestamp: December 27, 2024, 11:08:39 am
content: 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=1https://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

author: jpanhalt
author_rank: Super Contributor
timestamp: December 27, 2024, 12:22:31 pm
content: 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.htmhttp://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.pdfThere 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 somePIC12F675'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.

author: Gyro
author_rank: Super Contributor
timestamp: December 27, 2024, 01:15:02 pm
content: 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.

author: Ian.M
author_rank: Super Contributor
timestamp: December 27, 2024, 01:31:25 pm
content: 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-tutorialsGrab 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'sCode:ANSEL=0;and in MPASM assembler, that'sCode:bsf STATUS,RP0clrf ANSELbcf STATUS,RP0Note 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.

author: wilfred
author_rank: Super Contributor
timestamp: December 27, 2024, 01:47:32 pm
content: 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.

author: PGPG
author_rank: Frequent Contributor
timestamp: December 27, 2024, 03:19:08 pm
content: Quote from: MathWizard on December 27, 2024, 12:16:17 amSince 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.

author: Le_Bassiste
author_rank: Frequent Contributor
timestamp: December 27, 2024, 03:27:50 pm
content: Quote from: Ian.M on December 27, 2024, 01:31:25 pmand 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 Windows2.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\GnuWin323.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.exeto C:\Program Files\Microchip\MPLABX\v5.35\gnuBins\GnuWin32\bin\gnumkdir.exe.

author: Ian.M
author_rank: Super Contributor
timestamp: December 27, 2024, 04:20:42 pm
content: That's odd, because I normally run MPLAB 8.92's MPASMWIN and also MPLAB X 5.25 on64 bitWin10 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 !

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 27, 2024, 04:26:22 pm
content: 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.

author: Le_Bassiste
author_rank: Frequent Contributor
timestamp: December 27, 2024, 07:18:26 pm
content: Quote from: Ian.M on December 27, 2024, 04:20:42 pmmpasmwin.exe (named "MPASM for Windows 9x" on the HELP window) does work on Windows 10 64-bit (just tested it), but mpasm does not.

author: MarkF
author_rank: Super Contributor
timestamp: December 27, 2024, 07:34:07 pm
content: 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 ithere (page 4).Newer versions of MPLAB X have/or won't connect to the PICKit 3.I'm using Win7.

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 27, 2024, 07:49:21 pm
content: 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

author: MrAl
author_rank: Super Contributor
timestamp: December 27, 2024, 08:22:41 pm
content: Quote from: mkube396 on December 26, 2024, 02:40:49 pmHi there,If you want to get started with the PIC chips you should check out the forum for that there is a forum just for Microchip products. They have people that help there. They had a better forum before that, but for some reason they seem to have switched to a different one.Anyway, it is true that PIC chips are harder to program than Arduinos, but if you go to the Microchip site (or whatever they call it now) you can download examples. They have quite a collection last time I checked.Assembler for the 12F675 is not that bad because there are not many instructions to learn, but if you never programmed like that it may be hard to grasp. You have to visualize what each instruction does and how it affects the registers and the outside world pins.Also, the 12F675 is probably the easiest chip to learn that also has a built in AD converter, and you definitely want that or you miss out on a lot.Programming in ASM (assembler) means you will also learn the registers in the chip, and there are quite a few registers. To see if this is something you might want to do, download the data sheet for the chip and take a quick look through it. See if the descriptions of the registers make sense to you. If they don't you will have to read more on this or watch some videos.The registers control everything, even the clock speed. To use the AD converter or the built in EPROM you will have to look up code for that because there are special sequences you have to execute to get these to work, although some of that may be on the data sheet. They also control the interrupts.There's also another pdf file that you should download that tells you the basic operation of the mid range chips. It's the reference manual for Midrange Pic chips.If you have doubts that your current programmer can handle a pic like the 12F675, you might download the programming reference manual also, but it may be hard to follow.ASM is great if you want to take complete control over every aspect of the chip. You can see what every step is doing. It takes longer to write a program though, and to do math you usually have to download a math library. That would be a set of code you use in a routine to do the regular math like adding 32 bit numbers and stuff like that. If you intend to display any data on an LCD, you also need a conversion routine to convert from the N bit 'hex' numbers into M digit decimal representation. For example, 0x0F would convert to "15" which you could then send to the display.The C language makes it faster to program, but you do lose some of the details of the why the chip handles certain operations. A lot of people choose this though because with ASM it takes a long time to produce a complex program.There's also memory 'banks' that you have to consider, via none other than the registers. Some registers are stored in one bank, the others in the secondary bank. You have to pay attention when to switch banks if using ASM. The 12F675 has two banks, and some chips have more than two banks.It can be a lot of fun to get one up and running after studying the resistors and the instructions.If you get the PICKit 3 you will of course get a manual with that which should get you started. I have not used that particular one though so I can't say how good it works. You do have to make sure the kit you get handles your chip, if you end up getting a ready made programmer.They also make prototype boards with support components. They would also come with examples and also you can program the chips with that, but the chip parts they can handle may be limited you'd have to check that.One of the nicest things about the PIC chips is that you can use the low power mode, and also set the chip into a sleep mode. This allows you to use very little power for applications that only have to measure something once in a while, like every 10 minutes or something like that. You can create a temperature meter for monitoring a freezer that uses two AA batteries and they last for 2 years. This is harder to do with the Arduino, but if you like using the chip they use for the Uno for example you can learn to program that or use the IDE and a programmer and start with the raw chip. That would be a bit more versatile although you have to add support components.There are a lot of options out there:1. Raw Pic chips.2. Development board for Pic chips.3. Raw Arduino chips.4. Arduino dev boards.It's amazing what these chips can do. Years ago it would take a LOT more hardware to get even close to what these chips can do. I've been involved in development of such hardware years ago and it was almost nuts compared to today with the huge number of microcontrollers out there.

author: MarkF
author_rank: Super Contributor
timestamp: December 27, 2024, 10:26:34 pm
content: Quote from: DavidAlfa on December 27, 2024, 07:49:21 pmNo. I am talking about the PICKit 3.Yes, MPLAB X newer versions list the PICKit 3 in its list of programmers.But those newer versions of MPLAB X running on Win7 do not recognize that the PICKit 3 is plugged in.You can fool around and get it to appear 1% of the time if you're lucky.Verion 3.55 connects first time, every time without issue.Just my experience. Take it or leave it.

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 28, 2024, 04:28:45 am
content: No idea, might be caused by Win7, works perfectly fine in W10 or W11.

author: lakis70
author_rank: Contributor
timestamp: December 28, 2024, 09:16:27 pm
content: How hard is to read the datasheet and read-write some registers that govern the pic periferals?Dont use mplab or request a free hard disk from Microchip with theirs staff. Use open source tools

author: wilfred
author_rank: Super Contributor
timestamp: December 29, 2024, 05:45:19 am
content: Quote from: lakis70 on December 28, 2024, 09:16:27 pmDon't forget you're replying like that in the beginner's section. And people in forums might also seek to find like-minded people with whom they might share their interest. Obviously not you.

author: SteveThackery
author_rank: Super Contributor
timestamp: December 29, 2024, 12:40:30 pm
content: Well, I still think PIC is the wrong place to start. Start with Arduino, then graduate to PIC.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 29, 2024, 12:48:02 pm
content: 12f675 is pretty old - I'd suggest using something more recent like the 16F15313/325/345 etc. series- more peripherals, most pins can map to any peripheral, and a range of different pin counts for essentially the same part. Also cheaper.

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 29, 2024, 12:48:33 pm
content: I'd say the opposite, Arduino won't teach anything about the hardware and the CPP libraries won't help either.Pic 12/16/18 registers have the complexity of Lego, and it only needs setting up ~5 registers to get it up and running.

author: tooki
author_rank: Super Contributor
timestamp: December 29, 2024, 01:56:29 pm
content: Quote from: Electro Fan on December 27, 2024, 11:08:39 amHuh? ArduinoisC/C++.Learning programming involves multiple things:1. learning how to think in logical steps, and how to structure software2. learning the programming language3. learning the target hardware/environment/frameworkLearning Arduino teaches you the first two, for C/C++.And nothing in the Arduino framework actually stops you from controlling the hardware directly. You don’t have to use built-in functions, nor libraries. But using them can let you learn #1 and 2 without having to immerse yourself in #3 yet.Then, when you bump into the limitations of the Arduino framework (for example, if you find that digitalWrite is too slow), you can explore how to get around that. It’s not either-or, it’s a fluid continuum.

author: tooki
author_rank: Super Contributor
timestamp: December 29, 2024, 02:15:39 pm
content: Quote from: DavidAlfa on December 29, 2024, 12:48:33 pmI think it depends entirely on what one’s learning goals are, one’s skills/talents, and on one’s learning style.Me, for example: I am not a naturally gifted programmer. I’m not the worst, but not the best. If I had had to learn MCU programming completely without the use of libraries (or, god forbid, in assembly) I’d never have been able to do anything useful with MCUs, not because any one aspect of programming is particularly hard to learn, but because learningallaspects of MCU programming (see my previous post) at the same time would just be too much, and a hurdle in one blocks you from learning the others. So for me, and for many others, learning it progressively works better.IMHO, learning #1 and 2 (in my post above) is more important overall than #3, insofar as #1 and 2 are “portable” skills that one can apply to whatever #3 comes along. In other words, it’s more important overall to learn how to program than to learn the innards of a particular target, because knowing #3 is useless unless you know #1 and 2.In school, we used STM32 Discovery boards, and sometimes we’d run into some error that required some obscure MCU-specific setting in Keil to be changed for things to work. The teacher understood what it meant, but it was complete gibberish to me, because I didn’t know enough about STM32 to understand what it was. And I didn’t know enough to even understand the documentation about that setting or the error message that prompted it. Without assistance I would have just given up because it was not a surmountable problem. That’s the problem with a lot of bare-metal stuff: beginners don’t yet know enough to even be able to understand documentation, so you can’t dig yourself out with any reasonable amount of effort.Most of my real coding experience is with the Arduino framework, but what I learned there was directly applicable to both PIC and STM32, the other families I’ve used. (My PIC code is used in managing well over $1 million of liquid xenon, so it has to work. It’s been in use for 2 years and counting, and they haven’t come back for any bug fixes, so it must be working properly.)

author: Electro Fan
author_rank: Super Contributor
timestamp: December 29, 2024, 05:31:46 pm
content: Quote from: tooki on December 29, 2024, 01:56:29 pmWith all due respect tooki (and btw I very often read and consistently enjoy and appreciate your posts including the insight you provided in this thread), while Arduino is related to C and C++ and while all 3 are related to each other they are not identical.So saying “ArduinoisC/C++” might be a tad overly simplified. All matter is made of atoms (I think) but if I learn to shape some matter or apply some matter I haven’t necessarily learned the intricacies of atomic structures.Of course you know the relationships between Arduino, C, and C++ but a beginner might not know or see the relationships. Arduino and C and C++ each have some unique attributes. One unique attribute of Arduino is that it shields beginners from some complexity found in C and C++. Another unique and valuable attribute of Arduino is that it provides an ecosystem designed to introduce beginners into electricity and hardware along with software. Different courses for different horses, ie, different “paths” as I suggested in my post.So, changing metaphors, yes, the beginners wading pool and an Olympic pool both are filled with water. The activities and levels of challenge in both will provide an exposure to water, no doubt - but is one also the other?

author: SteveThackery
author_rank: Super Contributor
timestamp: December 29, 2024, 07:04:28 pm
content: Quote from: DavidAlfa on December 29, 2024, 12:48:33 pmThat's my point. Arduino gives you an easy on-ramp to programming in C/C++, and getting some cool successes under your belt early on. Once you've got a little way with Arduino,thenis the time to get closer to the metal with some PICs.There is nothing controversial about what I'm saying. Arduino is so incredibly successful because it's the perfect choice for beginners. I did it the other way round: PIC first, then Arduino. I wish I'd done Arduino first, but it didn’t exist back then.

author: Electro Fan
author_rank: Super Contributor
timestamp: December 29, 2024, 11:12:43 pm
content: Quote from: SteveThackery on December 29, 2024, 07:04:28 pmI agree with this - that Arduino provides an easy on-ramp to programming.Not to split too many hairs but when we say Arduino doesn’t teach anything about the “hardware” it’s probably worth clarifying what we mean by “hardware.” For an intermediate to advanced coder hardware can be registers, memory addresses, assembly and machine level code, etc - and no, Arduino isn’t going to provide much visibility into that with the IDE and the typical Arduino beginner environment. But, for some beginners “hardware’ might be the physical world of circuits including resistors, capacitors, and other passive components, and active components, and it might mean how electricity operates in those circuits (independent of code, or possibly in concert with code).Net, net: Arduino can be a very good on-ramp for beginners interested in electricity or hardware or software - and in the case of software it can provide a good path to C/C++. So for beginners Arduino is ideal because it provides a path to all 3: electricity, hardware, and software - and as a result it can help beginners experience the intersections of analog and digital. Back to PIC, no doubt PIC offered beginners a similar path back in the day and it continues to do so today, but it’s hard to compete with Arduino for “beginners” given all that the Arduino ecosystem offers - including shielding but not locking beginners out of complexities to the extent a beginner wants to go deeper.

author: tooki
author_rank: Super Contributor
timestamp: December 30, 2024, 01:17:34 am
content: Quote from: Electro Fan on December 29, 2024, 05:31:46 pmLike what? The fact that it offers a bunch of libraries and functions doesn’t change the fact that the fundamental syntax is bog-standard C/C++. It uses the standard gcc C++ compiler. It’s not similar to C++, it is C++.Arduino code is, save for calls to its library functions and some macros, portable to standard C/C++ (and the reverse is true too) — but that applies to any environment: thelanguageis not thetarget/environment/framework. The same caveat applies to every piece of code written for every platform: it has to targetsomething, so the names of system calls or hardware calls will have to be either changed, or use a wrapper of some sort.I just don’t understand why people discount Arduino as being “not C/C++” simply because it has a few ready-to-use functions, wrappers for main(), and generates function prototypes automatically. The code language is still C++, unambiguously. I feel like people discount Arduino because they’ve been told they should, not because there is any rational reason for doing so.I’ll spell it out once more (not in this thread, but in many others) since this point still seems to escape many people:Arduino means 3 things, really:1. Arduino-branded dev boards and clones thereof2. The Arduino framework (the libraries)3. The Arduino IDEOne can pick and choose any combination of these (with the exception that the Arduino IDE only supports the Arduino framework), or replace them with something else. Heck, my favorite combination is non-Arduino ESP32 or STM32 boards using the Arduino framework within the PlatformIO IDE.But if you’re using the Arduino framework, then you’re using C/C++, and the fundamental C/C++ skills one learns by doing so are absolutely transferable to other environments.Quote from: Electro Fan on December 29, 2024, 05:31:46 pmThe wading and Olympic pools aren’t the same thing — but the water they’re filled with is, and the skills you learn in the water do transfer.

author: brumbarchris
author_rank: Regular Contributor
timestamp: December 30, 2024, 09:36:31 am
content: QuoteI started the same way: PIC first, then other (sometimes higher level) embedded platforms. And I am absolutely thankful it happend this way. I would have had serious difficulties to understand what's happening ''under the hood'' otherwise. Doing a limited amount of assembler and stepping through code, seeing the effect on individual registers at every instruction (and interrupt) was very... eye opening.Also initially working with resource limited micros, gives you later a better appreciation of the more powerfull platforms you have in front of you, on the desk.Regards,Cristian

author: SteveThackery
author_rank: Super Contributor
timestamp: December 30, 2024, 11:33:48 am
content: Quote from: brumbarchris on December 30, 2024, 09:36:31 amWe can agree to differ on this. In my experience, working at the register level when you just want to multiply two numbers is a pretty steep learning curve. Higher level (than assembly) languages are the right place to learn about some of the universal concepts such as if/then, switch/case, functions, for, while, basic arithmetic, etc.Once you've got your head around those concepts, then you can have a look at how they are implemented down at the register level.Also, the great thing about Arduino is how readily you can get some successes under your belt. Your first flashing LED is a "Hah!" moment, and I think that most beginners would get a real kick from modifying 'Blinky' so it flashes "SOS" in Morse code, or whatever. That kind of kick really does motivate you to press on with the next learning challenge.Anyway, I'll shut up now.. As I say, we can agree to differ.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 30, 2024, 12:09:38 pm
content: There is really no need to do assembler on PICs these days. The C compiler, even in free mode is good enough for the vast majority of cases. The increased use of banking in larger PICs makes assembler more error-prone

author: PGPG
author_rank: Frequent Contributor
timestamp: December 30, 2024, 02:06:58 pm
content: Quote from: brumbarchris on December 30, 2024, 09:36:31 amEveryone starts as conditions allow.I have never started with microcontroller programming. In our 2 person team it is my brother who writes microcontroller programs.Our first microcontroller program should be bug-free from first shot as we had to pay (and it was expensive for us) for EPROM programming service to have it burn into EPROM and you couldn't check it in any way before paying for that service.It's easy to guess what that program was doing.No! Like probably no one else our first program was not LED blinking.It was program for 8048 that was receiving data via RS232 (8048 had no UART so bit by bit byte sending and receiving and whole communication protocol was coded 'manually') and then programming them into EPROM (switching 25V VPP and so on). I have written the program working at IBM-XT to read HEX file and send it by RS232 to our device.After getting our EPROM programmed first what we have done was to program new EPROM with the same program and check if it is working.Even programming and verification passed successfully our EPROM didn't worked!My brother made a mistake resulting in programming all 256 byte pages (except the first one that was programmed correctly) in random locations (verification was done at the same page address so passed).To avoid paying next time for EPROM programming our next task was to shorten being longer than 2 pages program to fit into one page and be able to program at least 2 pages. Removing all communication error checking and EPROM program verifying we did it being one or two bytes shorter than 256.Being able to program EPROMs ourselves was the first step to be able to use microcontrollers.I think one explanation can be needed to people coming from 'normal' countries.In Poland those time things like EPROM programmer (being imported) had 'normal' prices while everything else (salary and living) was may be 100 times cheaper (my academic teacher salary was about $13 per month). So if someone bought EPROM programmer for his may be 3 month salaries he offered EPROM programming for the price resulting from this.

author: brumbarchris
author_rank: Regular Contributor
timestamp: December 30, 2024, 09:32:50 pm
content: QuoteI agree.Why I still look fondly to ''my'' approach is that I continued for a very long time to actually use microcontrollers for low level relates stuff. Only much later did I come across the need to actually multiply numbers or do more complex algorithms with micros and had the need to move to C. To each their own, I suppose.What I fear is that if you start with such higher level things which shield you to a considerable extent from the register an single cycle stuff, you might not find it necessary to look under the hood until much, much later. And at that point one might find it a nuisance, rather than a natural step.Regards,Cristian

author: mkube396
author_rank: Regular Contributor
timestamp: January 03, 2025, 03:43:15 pm
content: ok there is a lot of reading in here for me to look at here..right now i might be a little in over my head with the "pic" stuff I guess ill try to focuses on "Arduino" I'm all ready semi familiar with the Arduino IDEi did try to understand how to wright code for a month. but i was lost and was not able to get anything i made to work.

author: ahsrabrifat
author_rank: Regular Contributor
timestamp: January 05, 2025, 06:26:22 pm
content: The easiest way is to download Mikro C for PIC. I has a free version. The coding language is quite easy and there are lots of in built examples.

author: shabaz
author_rank: Frequent Contributor
timestamp: January 05, 2025, 07:32:08 pm
content: Quote from: mkube396 on January 03, 2025, 03:43:15 pmTo get the basics solved first:A very friendly, beginners book for C programming is:"Problem Solving and Program Design in C"An old, used edition of this (no need for the latest) shouldn't cost more than $10.That will get you familiar with the language, on a PC, within a few weeks with just an hour or two of study every few days.After that, you'll have a lot more confidence with your Arduino code. It makes little sense to try a PIC for now, because for beginners (who naturally may need some help along the way), there is a lot more beginner material focused on Arduino.Also, although you may have specific projects in mind, it's worth trying a few simple projects, before embarking on something complex. The simple projects will show you how to use print statements, the serial console for debugging, how to control input and output, and so on. Look around for decent projects (not all are), ideally ones that reveal interesting patterns about structuring things. For instance, at a basic level, look to see how arrays and loops can help reduce coding and potential errors.Regarding:"the only thing i seen on youtube was people making lights blink."That can still be an important step. That exercise shows you how to configure and control outputs to blink the lights. Depending on the blinking project, it may also demonstrate how to pull in libraries of code and call functions to operate more complex LED modules. You could use these concepts for debugging code (for instance, turning on an LED to confirm when your code reaches a certain point).Then, look to see how some of the extra features inside the microcontroller (known as 'integrated peripherals') are used, again, one feature at a time.All these things will become the building blocks for larger projects, but one step at a time can be helpful. It's pretty much what I do when using a new microcontroller. First, I'll try blinking an LED. Then, I'll get the serial console operating (known as the UART integrated peripheral) to send print statements for debugging purposes. Then I might try getting a timer running, and seeing how I can get timer events. Then maybe try to make the microcontroller sleep and wake up. All small bite-sized chunks before embarking on a larger project. But first it's worth just concentrating on the C programming language by picking up a book on it, because it doesn't take a lot of time to study and try some of the exercises, and you'll need that knowledge to make your experience with microcontrollers more productive.