Microcontroller assembly code

The PIC 16 microcontrollers are small microprocessors with on-chip memory that hold a modest amount of code and data. These inexpensive processors are used in "consumer applications" such as CD players and microwave oven controllers.

In CSCI 320, we're going to study the low-end family of the PIC processors, the PIC16C5X. Documentation for the PIC processors is distributed in Adobe's PDF (Portable Document Format). On the CSCI workstations, you may read the documentation for the PIC16C5X family by typing the following command

     acroread /usr/local/csci/320/pic16c5x.pdf

on one of the Sun workstations. If you have a home computer that runs Microsoft Windows, you may want to install an Adobe PDF viewer on your home PC. The file

     /usr/local/csci/320/acroread.exe

will do this for you. You'll have to transfer this file to your home computer and then execute it. Press here if you'd like to connect to Abode's home page and download the latest copy of the Adobe PDF viewer.

The application we will study is a microcontroller simulation of a 3×8 encoder with a "hold" on the inputs. The "hold" pretends that an input of one actually continues for one second after the input returns to zero.

The encoder inputs are received through port A of the PIC processor. The encoder outputs are produced at port B.

Microchip, the producer of PIC processors, distributes assemblers and simulators via the Internet. These programs will be installed on the networked PC's in Robinson Hall. If you have a home PC, you'll want to install these programs on your own computer. Copies of these programs are in the directory /usr/local/csci/320/picsoft.

The next page of this handout is an outline of an assembler program for the 3×8 decoder. You'll be filling in the blanks over the next few weeks. The last page of this handout contain copies of files used by the PIC simulator to "run" the program. Eventually, your program should run on an actual PIC processor.

          LIST      p=16C54,r=dec 
          include   <p16c5x.inc>
; button positions at bit fields
button1   EQU        2
button2   EQU        1
button3   EQU        0

; time to hold a button
maxTime   EQU        5

;various registers
tempR     EQU       19
timeB1    EQU       20
timeB2    EQU       21
timeB3    EQU       22
countLo   EQU       24
valueLED  EQU       25
pattLED   EQU       26


startIt
; set port A for input
; set port B for output
          MOVLW     H'F'
          TRIS      PORTA
          CLRW
          TRIS      PORTB
; initialize registers
          CLRF      timeB1
          CLRF      timeB2
          CLRF      timeB3
          CLRF      countLo
          
mainLoop


; For each input i on port A
;      Set timeBi to maxTime, if input i is pressed
; For each input i
;      Set bit i of valueLED, if timeBi != 0
; Turn on bit valueLED of pattLED
; Set port B to pattLED
; Increment countLo
; If countLo = 0,
;      decrement the TimeBi


          GOTO      mainLoop
  
          ORG       H'1FF'
          GOTO      startIt
 
          END

Stimulation files

Below is a "stimulation file". It shows the decoder inputs applied on port A of the processor.

  STEP   RA3  RA2  RA1  RA0
      0   0    0    0    0
  10000   0    1    0    0
  20000   0    0    0    0
  30000   0    0    1    0
  40000   0    0    0    0
  50000   0    0    0    1
  60000   0    0    0    0
 210000   0    0    0    1
 220000   0    0    1    1
 230000   0    0    1    0
 240000   0    1    1    0
 250000   0    1    1    1
 260000   0    1    0    1
 270000   0    1    0    0
 280000   0    0    0    0
 440000   0    0    0    1
 450000   0    0    0    0
 460000   0    0    1    0
 500000   0    0    0    0
 510000   0    0    1    1
 550000   0    0    0    0
 560000   0    1    0    0
 600000   0    0    0    0
 610000   0    1    0    1
 650000   0    0    0    0
 660000   0    1    1    0
 700000   0    0    0    0
 710000   0    1    1    1
 750000   0    0    0    0

A simulator initialization file

An initialization file for the simulator is shown below. It controls the variables displayed by the simulator.

LO MICRO
AD PORTA,B
AD PORTB,B
AD W
AD timeB1
AD timeB2
AD timeB3
AD countLo
AD valueLED
AD pattLED
AD STATUS,B
ST MICRO

Back to the Handout index
Return to Dean Brock's home page
UNCA CSCI logo Return to the UNCA Computer Science home page