Building on the Microcontrollers and Assembly Code post this is my first project based on the amazing work from circuitbread.com.
Turning on a LED (Hello World)
- Getting Started with MPLAB X IDE - Part 4 Microcontroller Basics (PIC10F200)
- Your First Assembly Program - Part 5 Microcontroller Basics (PIC10F200)
Diagram from circuitbread.com
1 | #include "p10f200.inc" |
#include "p10f200.inc"
tells the IDE & compiler there are parameters already pre-defined for the chip that we can include, things like theGP2
which would reference the bit in the register for us; CONFIG
this is comment telling the human we are going to do the configuration__CONFIG
setup the micro controller (p10f200)_WDT_OFF
watch dog timer off (else it will reset itself every once in a while)_CP_OFF
code protection off_MCLRE_OFF
means we can use pin 8 as a GP input and not a reset pin
ORG 0x0000
origin, this is the begin of the program to executeINIT ; We are initializing the microcontroller over the next three lines.
- this is aINIT
is alabel
telling us where we will initialize / setup the controller anything after the;
is a human readable commentMOVLW ~(1 << GP2)
MOVLW
is aninstruction
which moves the literals you pass it to the working register- the tilda
~
is a bitwise operations that inverts 1 and 0s. IE: 1 becomes 0 and 0 becomes 1 - the left shit
<<
takes what we have and shifts it to the left
1 | bits 7 6 5 4 3 2 1 0 |
TRIS GPIO
theTRIS
instruction
always takesGPIO
as anoperand
. It meansTriState
so the GPIO can behigh voltage
,low voltage
orhigh impedance (OFF)
. This means take the values we put in the register and load them into theTRISGPIO
. SoGP2
is an output because its value is0
BSF GPIO, GP2
- set the bit in the register, this is setting GP2 to1
/HIGH
turning on the LEDLOOP
- just a lableGOTO LOOP
- go back to the loop above, which will jump down toGOTO LOOP
, so this is an infinite loopEND
- the end of our program