Help! How to program PIC microcontrollers using MPlab X IDE? - Page 1
Forum section: electronics / general

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 09:45:53 am
content: hello everyone,UPDATE:if anybody have any questions on this topic they can ask it in this thread.-------------------------------------------------------------------------------------I have been trying to program PIC16F77 ; see datasheet:http://ww1.microchip.com/downloads/en/DeviceDoc/30325b.pdfI'm programming this device using a pickit3 and XC8 compiler toolchain in Mplab X IDE, and so far I'm not able to make the PIC do anything, not even blinking LEDs or reading inputs from a switch...this is a picture of the code in the Main.c file and below it is what i saw at the output window:

author: Wilksey
author_rank: Super Contributor
timestamp: March 20, 2017, 10:41:38 am
content: It says that the IDE can't connect to the programmer.Did you try running the MPLABX Driver switching tool?It should have been installed along with the IDE.If no shortcut exists you can find it:C:\Program Files (x86)\Microchip\MPLABX\v3.XX\SwitcherWhere 3.XX is the version of the IDE installed.Inside there will be a 32 or 64 bit folder, and inside there will be a file called MPDDSwitch64.exe (or 32 depending on version).Note, this only applies if you have both MPLABX and MPLAB IDE installed.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 10:58:50 am
content: Quote from: Wilksey on March 20, 2017, 10:41:38 amis it this; see picture below:also what should i do with it?

author: jmag999
author_rank: Contributor
timestamp: March 20, 2017, 11:22:49 am
content: It looks like you have both the IDE and IPE open at the same time. Try closing the MPLAB IPE as it may be connected to the debugger.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: March 20, 2017, 11:26:24 am
content: I don't think the driver switcher is needed for PICKit 3

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 11:38:35 am
content: Quote from: jmag999 on March 20, 2017, 11:22:49 amI closed Both the IDE & IPENOTE:that was to open the switcher.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 12:03:23 pm
content: did i make a mistake in the code?i have to say I'm a newbie in the PIC microcontollers stuff, but i would really want to know how to use them...

author: Ian.M
author_rank: Super Contributor
timestamp: March 20, 2017, 01:19:42 pm
content: You haven't configured the oscillator, and your _XTAL_FREQ #define indicates you probably are attempting to use a 32.768KHz watch crystal, so I'd bet the oscillator isn't running. See datasheet FIGURE 12-3: RC OSCILLATOR MODEand try it with a 100pF capacitor and a 10K resistor, which should get it runing at approximately 2MHz. Once you have satisfied yourself that you can run code on it, you can reconfigure it for LP mode and try the watch crystal again, in the FIGURE 12-1: CRYSTAL/CERAMIC RESONATOR OPERATION (HS, XT OR LP OSC CONFIGURATION) circuit.To get the configuration right use the MPLAB X wizard:View and Set Configuration Bits.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 01:38:35 pm
content: Quote from: Ian.M on March 20, 2017, 01:19:42 pmsee picture below:

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 01:41:36 pm
content: I will change it to a RC oscillator, as u suggested...just give me a few minutes...

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 01:51:24 pm
content: i have changed it but still the code out of the config bit did not change.see picture:

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 01:57:21 pm
content: i will remove the #define _XTAL_FREQ 32768...

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: March 20, 2017, 01:58:06 pm
content: From memory I think on that part there is no internal RC osc, so if you config as RC you need to add an external RC.Any reason you're using such an old part?

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 02:18:04 pm
content: Quote from: mikeselectricstuff on March 20, 2017, 01:58:06 pmtrue, it probly dose not have an internal RC type oscillator despite it saying in 5.0 TIMER0 MODULE the following:The Timer0 module timer/counter has the followingfeatures:• 8-bit timer/counter• Readable and writable• 8-bit software programmable prescaler•Internal or external clock select• Interrupt on overflow from FFh to 00h• Edge select for external clocki think there is no relation with whither the chip has an internal oscillator or not, however this is rather confusing

author: Ian.M
author_rank: Super Contributor
timestamp: March 20, 2017, 02:19:56 pm
content: If setting the oscillator in the CONFIG wizard didn't generate a matching #pragma config line, its probably a bug and you should add:Code:#pragma config FOSC = LPmanually to your program if you want to use the watch crystal.IIRC it will default to ext. RC mode, but you should still add a line for it, if you are using it:Code:#pragma config FOSC = RCIt will do sweet F.A if you don't provide external oscillator components as per fig 12-1, 12-2 or 12-3 with corresponding FOSC setting, and also a pullup to Vdd on /MCLR - 10K is a good choice.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 02:33:41 pm
content: Quote from: mikeselectricstuff on March 20, 2017, 01:58:06 pmIt is one of the cheapest and powerful chips in the one of the few electronics in the eastern province...

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 03:22:42 pm
content: i add it give me a couple of minuets to test the circuit...see code below:

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: March 20, 2017, 03:30:31 pm
content: You need to fix that programmer issue before even looking at code issues.Try a reboot.

author: BrianHG
author_rank: Super Contributor
timestamp: March 20, 2017, 03:59:58 pm
content: I don't think his PC is even seeing the PICkit3 programmer. Are you sure your PICkit3 is directly connected to your PC's USB 2.0 Port? No USB extension cable, no USB hub.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: March 20, 2017, 04:01:47 pm
content: Quote from: BrianHG on March 20, 2017, 03:59:58 pmDoes it appear in Device manager?Does it work with MPLABX IPE ?I've seen issues with PICKit3 on hubs

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 04:30:31 pm
content: Quote from: mikeselectricstuff on March 20, 2017, 04:01:47 pmwell it works in the IPE, but i can not see it in the device manager...

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: March 20, 2017, 04:34:19 pm
content: That confirms that the hardware and connection to chip is OK.Looks like some sort of USB driver issue stopping MPLABX talking to it.

author: cv007
author_rank: Frequent Contributor
timestamp: March 20, 2017, 04:35:55 pm
content: BlinkLed Dashboard - click Refresh Debug Tool Status (second icon down) - will show various pickit3 info if connectedor click Project Properties icon (first one) - if pickit3 listed with no serial number- not connected(also make sure project set to use the pickit3)It looks like it has been connected properly at one time, otherwise there would be no pickit3 serial number listed.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 20, 2017, 04:52:57 pm
content: Quote from: cv007 on March 20, 2017, 04:35:55 pmsee what i saw:

author: cv007
author_rank: Frequent Contributor
timestamp: March 20, 2017, 05:36:54 pm
content: If pickit3 serial# is listed in project properties, it is seen by MPLABX (you can verify- disconnect pickit3, open project properties- pickit3 will be listed with no serial#).Your previous errors indicate MPLABX is not communicating with the pickit3, but also note there is a setting in the project properties for the pickit3 to provide power to your circuit- if you are using the pickit3 to provide power and have not enabled that setting, MPLABX will communicate with the pickit3 ok but the pickit3 will complain that it can't talk to the chip (which does not appear to be happening to you, yet )I would disconnect the pickit3 connections on the 6pin header, then try to program- it will fail of course, but you should see communications happening between MPLABX and pickit3. (I'm not sure what, if anything could go wrong if connecting the pins incorrectly, but this would eliminate that possibility).You may need to Google 'PICkit3PlatformTool' (part of your error message)- I'm sure you are not the first with this error.

author: BrianHG
author_rank: Super Contributor
timestamp: March 20, 2017, 07:14:12 pm
content: Maybe... now,,, I had this problem once last year...When I've done a auto build & program in MPLabxIDE, I accidentally disconnected the PICkit3 from my 6 pin sip header in the middle of programming. MPlab did report an error, but after reconnecting the pickit3 and trying to program again, it failed to see my Pickit3, even after closing MPlab and disconnecting the Pickit USB cable and reconnecting. The way to get it working again was I found in my task manager/processes a second microchip Mplab task frozen there in the background. After killing it, everything worked again. Now, I've accidentally disconnected my programmer a number of times without it affecting MPlab, this 1 time was a fluke chance, but if you have another frozen microchip programmer process, which looked like you closed it, but it is still running as a frozen service in the background, it needs to be 'End Process' before the programmer will work again, or, just do a reboot to clean everything.Note that I was using Win 7 professional 64bit.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 21, 2017, 03:55:05 am
content: Is the operating system important? And could it be a part of the problem?

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 21, 2017, 06:08:57 pm
content: I think i have uploaded the code to the pic...but the PIC is not running properly, the output pin RB0 is not flashing at all and the oscillator is giving a sine wave. see pictures:

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 21, 2017, 06:12:29 pm
content: also to mention that my pickit3 says it is supplying 5v, but testing it with my multimeter it shows around 4.77v to 4.65v

author: Luminax
author_rank: Regular Contributor
timestamp: March 22, 2017, 03:04:05 am
content: Can you provide a capture of your breadboard/perfboard/stripboard/etc?Also provide screenshot of the Project configuration?A note to point out, is that it is better to disconnect the PICKIT3 after programming as it does draw some current, and in some cases (like LCD driving) can drive your circuit a bit bonker

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 23, 2017, 12:05:08 pm
content: Quote from: Luminax on March 22, 2017, 03:04:05 amDo you mean the configuration bits?

author: Ian.M
author_rank: Super Contributor
timestamp: March 23, 2017, 12:32:26 pm
content: Its normal for a crystal oscillator to produce fairly close to a sine wave. Its also normal for a PICkit 3 to be unable to reach 5V out - it can only do 5V out if the USB Vbus is at its upper limit of 5.25V, as it doesn't contain a Vdd boost circuit.Please stop with the <expletive> screenshots!For source code or error messages from the Output window, its far easier for us if you paste them in, in code tags (# button in full editor).In this case we need to see all of your main C file, (assuming that's the one with the #pragma config block in it).Alternatively attach the source file(s), or if you want us to be able to build your project, maybe because you are struggling with a build error, package it as a zip file (from the project menu) and attach that.For dialogs, project properties etc. that cant be copied as text, screenshots are unavoidable, but please crop them to remove unwanted background windows etc.

author: Luminax
author_rank: Regular Contributor
timestamp: March 24, 2017, 01:35:24 am
content: The project dashboard, and the project configuration windows, looks like the two screenshots I attached.Also, yes, we also need to take a peek at your source codes

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 24, 2017, 10:08:45 am
content: Here is my breadboard view:https://drive.google.com/file/d/0B5vW-k7HbsL4c0hHVk1xYng1VzA/view?usp=drivesdkalso sorry for the screenshots I will post the code in a moment.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 24, 2017, 10:22:02 am
content: Code:#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)#pragma config CP = OFF // FLASH Program Memory Code Protection bit (Code protection off)#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR disabled)#pragma config FOSC = LP#define _XTAL_FREQ 32768// #pragma configuration statements should precede project file includes.#include <xc.h>#include <stdio.h>int main(){TRISB = 0xFF; // PortB is an outputTRISBbits.TRISB0 = 0;while(1){PORTBbits.RB0 = 1;__delay_ms(500);PORTBbits.RB0 = 0;__delay_ms(500);}return 0;}this is the code in the main.c file

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 24, 2017, 10:30:51 am
content: Code:#include <xc.h>#pragma config FOSC = LP // Oscillator Selection bits (LP oscillator)#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)#pragma config CP = OFF // FLASH Program Memory Code Protection bit (Code protection off)#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)#define _XTAL_FREQ 32768this code is in the config.h file

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 24, 2017, 10:44:12 am
content: project config window:

author: Ian.M
author_rank: Super Contributor
timestamp: March 24, 2017, 10:52:22 am
content: The code in main.c looks OK apart from the misleading comment when you set TRISB to 0xFF. It should be running and toggling RB0.config.h isn't doing anything as main.c doesn't include it. It is a bad idea to put the #pragma config block in a header as it should never be in or included from more than one .c file. If you want to remove the config block from main.c, save the code generated by the config wizard (or cut/paste it from main.c) as config.c and add it to the project.I would suggest enabling PWRTE as it extends power-on reset allowing a bit more time for Vdd to stabilise, and can help improve reliability. Also for the same reasons, if Vdd is guaranteed to be above the BOR threshold during normal running, enable BOREN, to hold the PIC in reset till Vdd is well above the minimum operating voltage.Sorry cant see the breadboard, you need to either use aPUBLICphotosharing site, or drop the resolution and increase the JPEG compression to get it under 500K so you can upload it here. A resolution of approx 1500 to 2000 pix on the long side is generally acceptable if you started with a good photo on a hi-res camera. Try to pick a resolution that is an integer factor of the camera resolution for optimal image quality. If you don't have a photo editor with a save for web function, and are using Windows, consider the freeIrfanViewas its JPEG save options include the ability to limit the image file size.Attaching the image here is vastly preferable as it preserves the topic for future readers as linked images tend to vanish after a few years because external photo sites may go down, break links or you may simply close your account.

author: BrianHG
author_rank: Super Contributor
timestamp: March 24, 2017, 03:45:27 pm
content: You forgot to change PortB0 analog select bit. By default it is in analog mode. The PIC is made like this just in case you have analog signals feeding some IOs during powerup.Place this before the TRIS...ANSELB = 0; // make all of port B into digital IOs

author: Ian.M
author_rank: Super Contributor
timestamp: March 24, 2017, 03:55:51 pm
content: True, but that shouldn't stop RB0 toggling as its alternately being set and cleared by BSF and BCF instructions. However if any other analog capable pins on port B were outputs,, without clearing ANSELB, they'd be unexpectedly reset to 0 with every transition of RB0.

author: BrianHG
author_rank: Super Contributor
timestamp: March 24, 2017, 04:28:29 pm
content: Quote from: Ian.M on March 24, 2017, 03:55:51 pmFunny, on my last project, where I swapped an ADC input between digital and analog, and do to a bug in my code, after leaving the input as an analog, it ignored any tris setting & bit setting of the IO port. It had to be configured as a digital IO before it would output data and go high and low.I was using a PIC18F46K22, MPLAB & XC8 compiler.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 25, 2017, 02:39:22 pm
content: Quote from: Ian.M on March 24, 2017, 10:52:22 amsorry for that...here is the breadboard view:https://drive.google.com/file/d/0B5vW-k7HbsL4c0hHVk1xYng1VzA/view?usp=sharingalso here is the main.c code:Code:#include "config.h"#include <xc.h>#include <stdio.h>int main(){TRISB = 0xFF; // PortB is an outputTRISBbits.TRISB0 = 0;while(1){PORTBbits.RB0 = 1;__delay_ms(500);PORTBbits.RB0 = 0;__delay_ms(500);}return 0;}

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 25, 2017, 02:50:20 pm
content: code in config.h :Code:#include <xc.h>#pragma config FOSC = LP // Oscillator Selection bits (LP oscillator)#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)#pragma config CP = OFF // FLASH Program Memory Code Protection bit (Code protection off)#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)#define _XTAL_FREQ 32768

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 25, 2017, 02:52:20 pm
content: Quote from: BrianHG on March 24, 2017, 03:45:27 pmi did, and it displayed an error icon...

author: Ian.M
author_rank: Super Contributor
timestamp: March 25, 2017, 03:50:00 pm
content: Sorry about that - Brian gave you bogus info and I didn't notice. On a PIC16F77, port B has NO analog capable pins and its ADC module is far too old to have a separate pin configuration for each port, or even to have individual pin configuration bits at all. To turn off analog mode for all pins on an 'F77', use:Code:ADCON1bits.PCFG=0b111;See datasheet REGISTER 11-2: ADCON1 REGISTER for details. However it wont make any difference to whether or not your code works, as its only important if you are trying to use ports A or E.Please post a photo of your board here so we can see how you are testing if RB0 toggles.Also it would be worth trying a different pin in case you've blown RB0.

author: BrianHG
author_rank: Super Contributor
timestamp: March 25, 2017, 04:10:59 pm
content: Sorry about that error, I saw in 'Luminax' post's screenshot, that a newer device 18F45K22 was selected in the compiler. My fault, I should have re-checked the original OP for which PIC was being used.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 26, 2017, 03:34:43 am
content: Quote from: BrianHG on March 25, 2017, 04:10:59 pmNo problem m8.

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 26, 2017, 03:38:18 am
content: Quote from: Ian.M on March 25, 2017, 03:50:00 pmI will try to change the pin today and see what happens...Also what dose this code do I didn't quite get it:Code:ADCON1bits.PCFG=0b111

author: Ian.M
author_rank: Super Contributor
timestamp: March 26, 2017, 05:35:31 am
content: It turns off analog mode for all analog capable pins (ADC inputs). While in analog mode, any attempt to read the pin as a digital input returns 0, which messes up bit output instructions on the same port.

author: lwatts666
author_rank: Unknown
timestamp: March 26, 2017, 11:02:33 am
content: I think you have a few problem with power connections on your breadboard.1) Vdd should connect to pins 11 and 32. You have only connected to pin 32.2) Vss should connect to pins 12 and 31. The photo shows it connected to pin33.3) The right hand vertical ground bus appears to be floating - not connected to ground.

author: Ian.M
author_rank: Super Contributor
timestamp: March 26, 2017, 11:23:24 am
content: Always connect all power pins together and all ground pins together with a 0.1uF decoupling cap for each power/ground pair. That's Vdd and Vss for this PIC as it doesn't have any dedicated power pins for its ADC.What's that unholy mess of capacitors round the crystal? Do you have any single caps within 30% of the value you are trying to get to? If so, use them on their own for now.Due to the sensitivity of the LP oscillator circuit, you should connect the caps as dorectly as possible between the OSC pins and the adjacent Vss pin. Long wires are NOT a good idea . . . .

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 26, 2017, 03:27:07 pm
content: Quote from: lwatts666 on March 26, 2017, 11:02:33 amQuote from: Ian.M on March 26, 2017, 11:23:24 ami suspected this, also I'm using 10pf caps.i will fix the connections and upload the photos soon...

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 27, 2017, 06:46:01 pm
content: Quote from: Ian.M on March 25, 2017, 03:50:00 pmit worked see code of main.c:Code:#include "config.h"#include <xc.h>#include <stdio.h>int main(){ADCON1bits.PCFG=0b111;TRISB = 0xFF; // PortB is an outputTRISBbits.TRISB0 = 0;while(1){PORTBbits.RB0 = 1;__delay_ms(500);PORTBbits.RB0 = 0;__delay_ms(500);}return 0;}see output:Code:make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-confmake: Entering directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'make -f nbproject/Makefile-default.mk dist/default/production/BlinkLed.X.production.hexmake: Entering directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --pass1 --chip=16F77 -Q -G --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/main.p1 main.c"C:\Program Files (x86)\Microchip\xc8\v1.41\bin\xc8.exe" --chip=16F77 -G -mdist/default/production/BlinkLed.X.production.map --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" --memorysummary dist/default/production/memoryfile.xml -odist/default/production/BlinkLed.X.production.elf build/default/production/main.p1Microchip MPLAB XC8 C Compiler (Free Mode) V1.41Build date: Jan 24 2017Part Support Version: 1.41Copyright (C) 2017 Microchip Technology Inc.License type: Node Configuration:: warning: (1273) Omniscient Code Generation not available in Free modeMemory Summary:Program space used 24h ( 36) of 2000h words ( 0.4%)Data space used 4h ( 4) of 170h bytes ( 1.1%)EEPROM space None availableData stack space used 0h ( 0) of 60h bytes ( 0.0%)Configuration bits used 1h ( 1) of 1h word (100.0%)ID Location space used 0h ( 0) of 4h bytes ( 0.0%)You have compiled in FREE mode.Using Omniscient Code Generation that is available in PRO mode,you could have produced up to 60% smaller and 400% faster code.See http://www.microchip.com/MPLABXCcompilers for more information.make: Leaving directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'make: Leaving directory 'C:/Users/hadaw/MPLABXProjects/BlinkLed.X'BUILD SUCCESSFUL (total time: 6s)Loading code from C:/Users/hadaw/MPLABXProjects/BlinkLed.X/dist/default/production/BlinkLed.X.production.hex...Loading completedi think it will work now...

author: Luminax
author_rank: Regular Contributor
timestamp: March 28, 2017, 04:54:48 pm
content: I wonder how effective the code 'conversion' will be if you actually purchased the XC8 License... hmmmm

author: ali6x944
author_rank: Frequent Contributor
timestamp: March 30, 2017, 05:45:04 pm
content: It finally worked! thanks for all the helpI will post a video of it soon in the form of a tutorial so no body have to suffer through this like many others -including me- did,so if u can or wish post anything that might be helpful to include in the video...and if anybody have any questions on this topic they can ask it in this thread.thanks a lot for all who contributed here , this is greatly appreciated

author: ali6x944
author_rank: Frequent Contributor
timestamp: April 01, 2017, 05:13:44 am
content: Here is the flashing led:https://drive.google.com/file/d/0B5vW-k7HbsL4dDRaLUZVa1JCVG8/view?usp=drivesdk

author: ali6x944
author_rank: Frequent Contributor
timestamp: April 09, 2017, 01:32:21 pm
content: here is the video I made, A big thanks goes to you guys for the great help which made the video possible ...also I hope u correct me if I got anything wrong in the video, so I can benefit from this experience too and can deliver better content in the future.https://youtu.be/eypsp_32PtworI hope it is informing... sorry if I didn't explain the code thoroughly, or overgeneralised when describing the function of certain registers or calling them ports all the time...give me anything that u guys think might need improving so this thread can deliver the low-level/beginner-level documentation a lot of people may need.thanks a lot for all support

author: ali6x944
author_rank: Frequent Contributor
timestamp: April 09, 2017, 05:06:24 pm
content: so what do u think??

author: Ian.M
author_rank: Super Contributor
timestamp: April 09, 2017, 05:43:07 pm
content: lthough its nice to see the face we've been helping, as its a long video few of us will have watched it. If you want people to review a video, best keep it under 5 minutes till you've built up a good reputation, and if you cant cover a topic in such a format, consider blogging it or writing an instructable, with short embedded videos for key points to back-up your text.You lost me 1 minute in when it became obvious that you hadn't prepared, checked and practised a script. Dave can get away with unscripted stuff on EEVblog because he knows the field so well, but even so he puts a lot of work into locating technical data before making tutorial, design or review videos. Its inexcusable NOT to know the part number you chose as an example of an unsupported part, and suggesting that the best way of identifying if a part is supported is to check in MPLAB is unhelpful due to the slowness and difficulty of checking multiple parts, especially as Microchip provide a concise HTML PIC vs tool compatibility chart as part of the MPLAB release notes.

author: ali6x944
author_rank: Frequent Contributor
timestamp: April 10, 2017, 01:19:03 pm
content: Quote from: Ian.M on April 09, 2017, 05:43:07 pmtrue I fully agree, and I will do a "re-do/shot" of the video and I will upload it to YouTube taking all your points in consideration...sorry if the audio quality was bad near the middle of the video for all who watched the hole video and prior to those who didn't watch it in hole...I will try to hopefully upload it this week or next week, I would like to thank you all for ur help especially Ian.M for his great constructive commentin the next video I will cover in order:1.the programmer compatibility with the PIC2.Compiler choosing3.IDE installation4.code explanation (includes a general description of the the 4 main registers -port,tris,ANSEL and ANSELH-)if anyone wants to add anything I missed or correct any thing wrong feel free to do so because i need to improve the kinds of videos i make

author: ali6x944
author_rank: Frequent Contributor
timestamp: June 27, 2017, 08:50:04 pm
content: not re-shot yet:i will re-shot it soon...

author: ali6x944
author_rank: Frequent Contributor
timestamp: July 01, 2017, 08:08:01 pm
content: just a quick question:are all Pickit2 compatible chips compatible with Pickit3?

author: Ian.M
author_rank: Super Contributor
timestamp: July 01, 2017, 10:31:39 pm
content: I just checked the MPLAB 8.92 device support (PICkit 2 device support was frozen somewhat earlier than v8.92, and was then ported to MPLAB X with no further changes), as I have it in a spreadsheet for easy searching, and there are NO PICs that have PICkit 2 programming support but aren't supported by the PICkit 3.

author: ali6x944
author_rank: Frequent Contributor
timestamp: July 02, 2017, 08:00:05 pm
content: Thanks

author: Luminax
author_rank: Regular Contributor
timestamp: July 06, 2017, 12:21:48 am
content: I think we can safely say that there are NO PICs that are NOT supported by PicKit3... it's their flagship programmer after all

author: Ian.M
author_rank: Super Contributor
timestamp: July 06, 2017, 12:47:37 am
content: Actually it doesn't support any of the old EPROM program memory PICS*. They are mature products but many are still in production. It supports all FLASH program memory PICs. If you need to program the EPROM PICs with a currently supported programmer, you need a Microchip PM3. However unless you've got deep pockets, it makes more sense to pick up a second hand PICstart Plus and maintain a legacy MPLAB 8.92 install to run it.* IIRC the algorithms for programming the PIC18Cxxx and PIC16Cxx parts could easily be ported to it, but its Vpp generator isn't beefy enough. As a minimum it would require an external Vpp buffer and supply for it.

author: NorthGuy
author_rank: Super Contributor
timestamp: July 06, 2017, 01:22:25 am
content: Quote from: Ian.M on July 06, 2017, 12:47:37 amExcept PIC18F4539 and family. Not that this matters ...More importantly, it supports newer parts, such as PIC18 K42 and will support PICs which appear in the future.

author: ali6x944
author_rank: Frequent Contributor
timestamp: July 19, 2017, 11:24:51 am
content: Hi guys,thanks for all the help, but do anyone knows how to use 8 bit ADC in PIC16F77 using XC8, because I'm going to use it to demonstrate this as an example code implementation of an 8-bit ADC and 10-bit ADC of modern PICs in the upcoming video...I tried but with no luck:config.hCode:#include <xc.h>// include processor files - each processor file is guarded.// PIC16F77 Configuration Bit Settings// 'C' source line config statements// CONFIG#pragma config FOSC = LP // Oscillator Selection bits (LP oscillator)#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)#pragma config CP = OFF // FLASH Program Memory Code Protection bit (Code protection off)#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)#define _XTAL_FREQ 32786 // Sets the crystal oscillator frequencyvoid ADC_Init(){ADCON0 = 0b00000001;/**See the the "0b" tells the compiler that this is a binary number,* The number right after the "0b" is MSB, the last number -right before the ";"- is LSB.* Bit 7-6 are A/D Conversion Clock Select bits, which set the sample clock.* Bit 5-3 are Analog Channel Select bits, which will select a particular channel out of 8 Analog channel.* Bit 2 is A/D Conversion Status bit, which initiates A/D conversion and it will be automatically cleared when the conversion completes.* Bit 1 is not used so set to zero.* Bit 0 is A/D On bit, which basically turns on/off the ADC*/ADCON1 = 0b00000000; //All pins as Analog Input and setting Reference Voltages/**See the the "0b" tells the compiler that this is a binary number,* The number right after the "0b" is MSB, the last number -right before the ";"- is LSB.* Bit 7-3 is not used so set to zero.* Bit 2-0 are A/D Port Configuration Control bits, which set the analog pins and refrence.*/}unsigned int ADC_Read(unsigned int channel){if(channel > 7) //Channel range is 0 ~ 7{return 0;}ADCON0 &= 0xC5; //Clearing channel selection bitsADCON0 |= channel<<3; //Setting channel selection bits__delay_ms(2); //Acquisition time to charge hold capacitorGO_nDONE = 1; //Initializes A/D conversionwhile(GO_nDONE); //Waiting for conversion to completereturn ((ADRES));}main.cCode:#include "config.h"void main(void) {TRISAbits.TRISA0=1; // Analog Input pin AN0TRISAbits.TRISA1=1; // Analog Input pin AN1TRISBbits.TRISB7=0; // Digital Output pin RB7ADC_Init(); //Initialize ADCunsigned int ADC; // value of first analog channelunsigned int ADC1; // value of second analog channelADC1=ADC_Read(1); //Initialize channel (1)ADC=ADC_Read(0); //Initialize channel (0)while(1){if (ADC==ADC1){PORTBbits.RB7=1; //if both channels are equal turn RB7 to high}else{PORTBbits.RB7=0;//else turn RB7 to low}}}

author: StillTrying
author_rank: Super Contributor
timestamp: July 19, 2017, 12:36:24 pm
content: ADCON0 = 0b00000001;* Bit 7-6 are A/D Conversion Clock Select bits, which set the sample clock.If the XTAL_FREQ is only 32,768, you'll need to use the ADC's internal RC oscillator.ADCON0 = 0b11000001;

author: ali6x944
author_rank: Frequent Contributor
timestamp: July 19, 2017, 02:22:34 pm
content: will try it in a second....but I want to know why do I have to use the internal oscillator?is the ADC in PIC micros need specific exact frequencies to work at properly?

author: ali6x944
author_rank: Frequent Contributor
timestamp: July 19, 2017, 02:44:31 pm
content: it dose not work...I connected both AN0 and AN1 to ground, and RB7 didn't go high...I did the same thing but connected the inputs to VDD with no luck too.

author: StillTrying
author_rank: Super Contributor
timestamp: July 19, 2017, 03:22:20 pm
content: Yep, the ADC clock speeds are limited ~250kHz - ~1MHz.In ADC_Read(), isADCON0 &= 0xC5;(b11000101) is starting a conversion before you've set the channel number ?In main(void) shouldADC1=ADC_Read(1); & ADC=ADC_Read(0);be inside the while(1) loop ?

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: July 19, 2017, 03:50:29 pm
content: You may be expecting a bit too much from the A/D converter. You only read each channel once, and if they are not identical your code will fail. A/D conversion is inherently noisy and (especially at the extremes) channels may not track precisely.Try connecting one channel to a pot which you can turn to vary the voltage from Vss to Vdd, and the other to a midpoint voltage (eg. using a voltage divider with 2 equal resistors). Then read the channels continuously inside the while() loop, and set the output according to which voltage is higher, like this:-Code:while(1){ADC1=ADC_Read(1); //Initialize channel (1)ADC=ADC_Read(0); //Initialize channel (0)if (ADC > ADC1){PORTBbits.RB7=1; //if channel 0 > channel 1 then turn RB7 to high}else{PORTBbits.RB7=0; //else turn RB7 to low}The LED should turn on/off as the pot is turned through its center position.

author: ali6x944
author_rank: Frequent Contributor
timestamp: July 24, 2017, 11:15:53 am
content: thanks a lot!!