Microcontrollers and Assembly Code

binary-assembly-highlevel

These are notes I made while watching the amazing tutorials from Circuit Bread and circuitbread.com

Assembly Code

In computer programming, assembly language (or assembler language), is any low-level programming language in which there is a very strong correspondence between the instructions in the language and the architecture’s machine code instructions. - wikipedia.org

Four main parts of Assembly

  • labels - is a section of the code, partially for the human to understand what is going on. Can also be used as a reference within the code
  • instructions - its a way of taking a word and shortening it up using a subset of letters (often the first letters of the word). This then reperesents something so you dont have to type out the whole word/sentence each time. These are also known as numonics / operational code
  • operands - these are the parameters that you give your instructions
  • comments - human readable words to understand what the program is doing

Instruction examples

1
2
3
BSF           - Bit Set F. A set bit makes a pin high and clear bit makes a pin low
DECFSZ - Decrement if not zero
MOVLW - MOVe Literal to W. `W` is the working register. You have to put things in the working register to do any logic to/with it (ie: muiltip[ly the value by another value. Both values need to be in the working register)

Hardware & Software

Some key terms and notes

  • IC is integrated circuit (its the microcontroller)
  • PC is the Program Counter which is where you are in the program (feels like the stack in .net)
  • stack this small PIC10F200 has two levels of stack used to store the memory addresses when calling sub routines like a GOTO

There are many microcontrollers on the market and each vendor has proprietary and often trade marked technologies. Most of my notes are on PIC10F200 microcontroller by microchip. Others I found online are

PIC10F200

pic10f200

  • Voltage range is 2.0V to 5.5v
  • 16 bytes RAM (10 -> 1F)
  • 4 mHz / 4 ticks
  • 256 words (instructions) as 12 bits = 1 word
1
2
256 * 12 / 8 (bytes)
= 384 bytes

Logical pins:

1
2
3
4
5
6
                ------
N/C -| 1 8 |- GP3 / MCLR (bar) / VPP
VDD -| 2 7 |- VSS
GP2 / T0CKI -| 3 6 |- N/C
GP1 / ICSPCLK -| 4 5 |- GP0 / ICSPDAT
------
  • N/C no connect, so nothing is connected to these pins
  • VDD power +
  • GP0, GP1, GP2 general-purpose input/output
  • T0CKI
  • GP3 input only
  • MCLR (bar) the bar is the line above MCLR, it means high its inversed so set to low to clear
  • VSS ground -
  • ICSPDAT in-circuit serial programming Data (PICKit connection)
  • ICSPCLK in-circuit serial programming Clock (PICKit connection)

PICKit 3 / PICKit 4

This is the programmer / debugger (The ICD series are the more expensive none hobby ones). This this post at vlrobotech.com has details about the PICKit 3 and a cool 35 light control project!

You can also use an arduino as the programmer but I found a cheap PICKit 3 locally so rolled with it.

PICKit 3

1
2
3
4
5
1 VPP/MCLR          clear
2 VDD power `+`
3 VSS ground `-`
4 ICSPDAT/PGD in-circuit serial programming Data (some controllers mark this as PGD)
5 ICSPCLK/PGC in-circuit serial programming Clock (some controllers mark this as PGC)

MPLAB X / 8.7x

This is the the Integrated Development Environment (IDE)

I could get the sample code to work with v8.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Project -> New 
Project Name = `Blink LED`
Project Directory = `C:\Dev\p10f200\BlinkLED\` / `C:\Dev\p10f200\TurnOnLED\`

Programmer -> Select Programmer -> Picket 3
Programmer -> Settings -> Power -> Enable 5V
Programmer -> Reconnect
Programmer -> Erase Flash Device

View -> Project (if not shown)
File -> Add New File To Project -> main.asm -> Save
Pop in source code
File -> Save

Project -> Build All (Relocatable code if it asks)
Programmer -> Program

I had no luck with MPLAB X

Projects

These are the simple projects involving LEDs that noobs like me can understand! (kind of)