Programming the PIC16F84A in C with MPLAB X

Поділитися
Вставка
  • Опубліковано 28 сер 2024
  • We start a new C programing project in MPLAB X 5.05 using the XC8 2.0 compiler. We'll use the simulator and the I/O views in the Simulator and Debugging menus to examine Pin 17 (RA0) to see if it does what we intended. This is the equivalent of the "hello world" example from K&R, but targeting microcontrollers that don't have displays.

КОМЕНТАРІ • 31

  • @michaeljohnston406
    @michaeljohnston406 Рік тому

    I updated this to a newer PIC 16F1847 which is more robust that 16 F 84. I did find that you need to turn off the analog select section to make the pin a true digital pin! thank you great video!

  • @relativenormality
    @relativenormality 5 років тому

    Nice demo of how to leverage in built simulation tools

  • @arduinomaquinas
    @arduinomaquinas Рік тому

    Great job ❤🇧🇷😉👍👏👏👏👏

  • @Chen-zd6rx
    @Chen-zd6rx 3 роки тому

    Thanks for your teaching

  • @dotdissonance
    @dotdissonance 4 роки тому

    Very nice! Simulation will help a lot.

  • @markharrington5826
    @markharrington5826 3 роки тому

    Ideally what would have been far better would be to approach this in assembler to start with as then all would learnt about the special function registers, indirect addressing , direct addressing , working registers , rotate left through carry, RRF RLF, the alu , how the different flags in the status registers are affected , timer functions , the ports which can be changed from analogue to digital only pins , interrupts , timer interrupts , hardware interrupts , port pin interrupts spi , i2c
    This would have by the time you reach doing this in c enable many to work out how the CPU actually works and be able to debug and see what your code is actually doing with timing and nop functions and with comparison of C at assembler level
    It great being able to program in c but not much point if you dont know how a byte is latched from the trisb register for example to portb or how you clock data in and out
    Then you would also I think whilst on the topic be explaining about xtal timing , internal , External RC , HS, XT , LP oscillator settings with the different settings with configuration bits for example , as guaranteed what will happen is initially when learning and not knowing this plus before starting to write software many will have a setting of code protect = on and that means can no longer can use IC
    EG
    // CONFIG
    #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
    #pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
    #pragma config PWRTE = OFF // Power-up Timer Enable bit (Power-up Timer is disabled)
    #pragma config CP = OFF // Code Protection bit (Code protection disabled)
    // #pragma config statements should precede project file includes.
    // Use project enums instead of #define for ON and OFF.
    Discussing pipe lining and how that works and why I would think also be introductory before coding as this is quite important as basic fundamentals of how that cpu operates
    In fact there are many topics that have not been discussed or even touched on which again you could have used simulators and other software such as Proteus or shown others how to use simulide for example
    Link here for you
    www.simulide.com/p/home.html
    There is also no mention of declaring the XTAL clock frequency
    Eg
    #define _XTAL_FREQ 20000000 // 20mhz
    Id say that might just be a little important myself before even trying to code any cpu
    ***** Next important point is RA4 ***
    Iff you dont know this and haven ever read a data sheet before then you may find yourself attach the led to ground via RA4 and no output
    Eg please see data sheet on ports
    Quote , " Pin RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI pin. **** The RA4/T0CKIpin is a Schmitt Trigger input and an open drain output. *****All other RA port pins have TTL input levels and full CMOS output drivers ( BIG HUGE DIFFERENCE " )
    Next how to set trisa although yes fine how ever not standard practice so you would need to discuss the advantages of
    TRISA = 0x00 ;
    Or
    TRISA = 0b00000000 ;
    Or far better if setting for input
    TRISA = (1

  • @watchvdos
    @watchvdos Рік тому +1

    Looking for assembler MPLAB V3. 9 for programming 12F509, 14F, 16F. Please guide me.

  • @giovaniguillenrosas2722
    @giovaniguillenrosas2722 Рік тому

    Hi there, excuse me sir, When I started debugging, the output window indicated me the following message "Watchdog timer has caused a reset", how can I fix this? Thank you...

  • @douglasthomson2986
    @douglasthomson2986 5 років тому +1

    Nice explanation. Thanks for doing this. Any other resources / books you would recommend to understanding embedded programming? It's such a complex area to get your head around, but fascinating and very worthwhile. Cheers.

    • @onnimikki2007
      @onnimikki2007  5 років тому +2

      When it comes to PIC, the best recommendation are the books by Lucio di Jasio. He's got two recent ones on the PIC16 that are really good: www.amazon.ca/10-Lines-Code-Lucio-Jasio/dp/1329908031. and www.amazon.ca/Rocket-Science-Lucio-Jasio-2015-03-22/dp/B01K2QYWWI/ref=sr_1_6?qid=1564652468&refinements=p_27%3ALucio+Di+Jasio&s=books&sr=1-6

  • @bernag7297
    @bernag7297 2 роки тому

    Hi, select header and hardware tools does not appear in mplabx i downloaded. What could be the problem? Please help me

  • @andrewvernon9269
    @andrewvernon9269 4 роки тому

    Does anyone know where I can get a C program that I can burn into a pic that will do the following . Have a start button for a 30 minute delay . Once 30 minutes has delayed an LED or Device will vibrate . The user can easily reset the timer . But the kicker is I would to try and fit the circuit and battery and transducer ( led or vibrating buzzer ) into a wrist band preferably rubber , something that's pretty robust . ..something similar to a FIT BIT . any help would be much appreciated .

    • @onnimikki2007
      @onnimikki2007  4 роки тому

      It's doable. But you would probably have to hire someone to do it. Or you could suggest it as a capstone project for undergraduate engineering students.

  • @fernandohood5542
    @fernandohood5542 3 роки тому

    Dont you require a include for the pic? Why did you delete the other two includes?

    • @onnimikki2007
      @onnimikki2007  3 роки тому

      Only include the ones you need. xc.h provides the chip-specific definitions. The other two are added in the template but are unnecessary. None of what I did required them. I typically like to include stdint.h so that I can declare well-defined integer sizes... uint8_t, int16_t, etc. It's especially useful when writing solutions to work on different architectures like PIC16, PIC32 and ARM. But I didn't do it in this example.

  • @tolgaozkacar5401
    @tolgaozkacar5401 5 років тому

    Thank you for the video but when you finish the program, do we can add the language into the proteus simulation? for the see what will be happen.

    • @onnimikki2007
      @onnimikki2007  5 років тому

      There is no Proteus simulation. This can be used to program the chip directly or to simulate in MPLAB X.

  • @ahmednawaz4858
    @ahmednawaz4858 4 роки тому

    Pic microcontroller's programing in ccs pic c compiler video link: m.ua-cam.com/video/psG88sLUSv4/v-deo.html

  • @t4l84
    @t4l84 4 роки тому

    I would like to talk to you directly about solving exercises using MPLAB X IDE, could you please tell me how I could contact you regardless ?

  • @user-we9oe6pr3e
    @user-we9oe6pr3e 4 роки тому

    I just decided after years of using the Arduinos to read these older Benson books. I almost tossed them out. I even still have the 16F84 chips and want to start playing with them again. Thanks very much for this video (!!) even though for now I've loaded the old MPLAB IDE 8.9 but at some point will try the "X". The link to Bensons books is now dead (so is his site) but does anyone know where I can find the book files for the programs?? I dont feel like typing all of that code in for the LCD display. And wonder about an errata documents.

    • @onnimikki2007
      @onnimikki2007  4 роки тому

      Check out the "archive.org" link in the video. Also, I'd suggest moving away from the older '84 chips and using the newer ones like the PIC16F1619. They're almost the same but have better debug support. I would recommend looking at Lucio Di Jasio's books on the PIC16F1 series... and how to use the newer MPLAB X tools, including the code generation in the MCC add-on.

    • @user-we9oe6pr3e
      @user-we9oe6pr3e 4 роки тому

      @@onnimikki2007 Hi James...I did click on the archive link but it seems like its looking for his web site which I'm told is long gone. I'm only using the 16F84 as I have them already but I had used the 16F690's when I was doing some C coding and still have a group of those. Thanks for the info!

  • @remiboulanger4282
    @remiboulanger4282 5 років тому

    hi James, nice video, I have a problem, I downloaded MPLAB X and XC8 and when I send the program I got the message cannot find include file . Do you . can you help me ?

    • @onnimikki2007
      @onnimikki2007  5 років тому

      I have never had that problem before. I would guess that you either installed the compiler wrong or have set up your project badly. You should post details about it on the Microchip forum.

  • @tamburaimashonganyika4757
    @tamburaimashonganyika4757 2 роки тому

    well explained thanks James but your sreen is not very clera

  • @Gadgetgyan1
    @Gadgetgyan1 3 роки тому

    PlZ do more videos with different interface and debug them

  • @eloyrolandocanchanyabalbin4692
    @eloyrolandocanchanyabalbin4692 5 років тому

    Hi and thaks a lot from Perú, Do you can show me some forum about this topics? bye.

    • @onnimikki2007
      @onnimikki2007  5 років тому

      Hola! The best place for specific discussion on the PIC16 is the Microchip forums (www.microchip.com/forums/). If you want a general discussion on microcontrollers, the Adafruit discord channel is good, too: blog.adafruit.com/2017/07/20/adafruit-is-on-discord-discordapp-adafruit-discord-adafruit/

  • @shahzadamin4825
    @shahzadamin4825 5 років тому

    nice mr james i need your email