Programming the PIC16F84A in C with MPLAB X

preview_player
Показать описание
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.
Рекомендации по теме
Комментарии
Автор

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!

michaeljohnston
Автор

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

watchvdos
Автор

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...

giovaniguillenrosas
Автор

Nice demo of how to leverage in built simulation tools

relativenormality
Автор

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

bernag
Автор

Very nice! Simulation will help a lot.

dotdissonance
Автор

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 .

andrewvernon
Автор

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.

douglasthomson
Автор

well explained thanks James but your sreen is not very clera

tamburaimashonganyika
Автор

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.

tolgaozkacar
Автор

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.

J-yh
Автор

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

fernandohood
Автор

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


There is also no mention of declaring the XTAL clock frequency

Eg

#define _XTAL_FREQ // 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. 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 = ;


Or far better if setting for input

TRISA = (1<<4) ; RA4 Now becomes input its far clearer and more understandable in the long run


Setting this can also be done via this command

TRISAbits.TRISA0 = 0; // refers to bit 0 or RA 0 on latch

Similarly

PORTABits.RA0 = 1 ; // I know can see very clearly that RA0 is logic one or at 5volts straight away since i can map this directly to the case outline, pin outline as described in the data sheet

How about a link to data sheet as well Don't you think that this might be just slightly advantageous at this stage The shear lack of informations these days not to mention accuracy is quite bad and also I might add very noticeable in trade and industry Its appalling

We want professionals not two bit have a go results

Incredible, just incredible

A link for you

Not that hard is it really with a little bit of extra informations to activate hidden senses in thought

Finally Its the difference between 318 likes and 130000 likes

Says it all for you !!

markharrington
Автор

PlZ do more videos with different interface and debug them

Gadgetgyan
Автор

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 <xc.h>. Do you . can you help me ?

remiboulanger
Автор

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 ?

tl
Автор

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

eloyrolandocanchanyabalbin