


     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



     NAME
          asm_c84 - assembler for the PIC 16C84 microcontroller

     SYNOPSIS
          asm_c84 filename

     DESCRIPTION
          asm_c84 is a simple assembler for Microchip Technology's PIC
          16C84 CMOS EEPROM microcontroller.  The PIC 16C84 is popular
          because it is a relatively inexpensive microcontroller that
          can be reprogrammed in-circuit using a simple interface
          circuit.

          The assembler reads the given file of PIC 16C84 assembly
          code and produces an output file formatted in INtel HeX 8-
          bit Merged (INHX8M).  It also produces a simple listing and
          symbol table file.

     EXAMPLE
          The following example assembles the file test.a84 and
          produces the output files test.hex and test.lst.

            asm_c84 test.a84


     SYNTAX
          My assembler is vaguely similar to Microchip's MPALC.
          However, I have made changes where I couldn't stand their
          syntax.

     Comments
          The semicolon (;) is the comment character.  Everything from
          a semicolon to the end of line is ignored by the assembler.

     White Space
          Spaces and tabs are used to delimit words but, are otherwise
          ignored.

     Constants
          Constants may have the following formats (regular
          expressions given):

          B'[01]+'
               A binary (base 2) constant.

          O'[0-7]+' or Q'[0-7]+'
               An octal (base 8) constant.

          [0-9]+
               A decimal (base 10) constant.

          0x[0-9A-F]+ or H'[0-9A-F]+'



     Page 1






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



               A hexadecimal (base 16) constant.

          '.' or A'.'
               A character constant.  C-style backslash conventions
               are supported.

          ".*"
               A string constant.  C-style backslash conventions are
               supported.

          [_A-Z:?][_A-Z0-9:?]*
               A symbol name.  (Yes, to be compatible with MPALC, I
               allow colons in names.)

          [_A-Z:?][_A-Z0-9:?]*:?
               A program label.  Labels must be the first word on a
               line.  Trailing colons are optional, and are deleted
               from the symbol's name.  Ex:

                       fruit_loop:
                               DECFSZ  counter, F
                               GOTO    fruit_loop


     Variables
          All variable and keyword names are compared caselessly.
          i.e. RTCC, rtcc, and rTcC all reference the same register.

          Rather than use Microchip's technique of changing the origin
          to the start of data and using the RES assembler directive
          as shown below:

                    ORIG    0xc     ; first byte of data
            bytevar RES     1       ; variable named bytevar
            more_v  RES     1       ; another named more_v
                    ....
                    ORIG    0       ; back to code
                    ....

          I have given my assembler an address pointer and ORG command
          for each memory space:

                    DORG    0xc     ; first byte of data
            bytevar BYTE    1       ; variable named bytevar
            more_v  BYTE    1       ; another named more_v
                    ....


     Built-in Definitions:
          There are a number of built-in values defined, to make up
          for the current lack of an INCLUDE ability.  The values
          given as number,number are BIT definitions.  Those that are



     Page 2






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



          single numbers are EQU definitions.

          Register EQUs

            Name    Value     Description
            ----    -----     -----------
          EEADR     0x09    EEROM address register
          EECON1    0x88    EEROM control register
          EECON2    0x89    not a physical register
          EEDATA    0x08    EEROM data port
          FSR       0x04    Data address for indirect via IND0
          IND0      0x00    Indirects via FSR into data memory
          INTCON    0x0B    Interrupt Control register
          OPTION    0x81    Option select register
          PCL       0x02    PC's Low 8 bits
          PCLATH    0x0A    Holding reg for PC's High byte (see manual)
          PORT_A    0x05    Port A data bits
          PORT_B    0x06    Port B data bits
          RTCC      0x01    Real Time Clock Counter
          STATUS    0x03    Status register
          TRIS_A    0x85    Port A data direction bits
          TRIS_B    0x86    Port B data direction bits

          STATUS BITs

          CARRY     0       Carry/Borrow* bit (see manual)
          C_bit     0x03,0  Carry/Borrow* bit (see manual)
          DC        1       Digit Carry/Borrow* bit (see manual)
          DC_bit    0x03,1  Digit Carry/Borrow* bit (see manual)
          Z         2
          Z_bit     0x03,2  Zero bit
          PD_bit    0x03,3  Power Down status bit
          PD        3
          TO_bit    0x03,4  Time Out status bit
          TO        4
          RP0       5       RP1,0: Register Page for direct addr
          RP0_bit   0x03,5  RP0,0: Pg 0 (00-7F); 0,1: Pg 1 (80-8F)
          RP1       6
          RP1_bit   0x03,6
          IRP0      7       Indirect Reg Page select (not used yet)
          IRP0_bit  0x03,7

          PORT_A BITs

          RA0       0x05,0  bit 0
          RA1       0x05,1  bit 1
          RA2       0x05,2  bit 2
          RA3       0x05,3  bit 3
          RA4       0x05,4  bit 4 (RTCC input)
          RT        0x05,4  bit 4 (RTCC input)

          PORT_B BITs



     Page 3






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



          RB0       0x06,0  bit 0 (INT input)
          RB1       0x06,1  bit 1
          RB2       0x06,2  bit 2
          RB3       0x06,3  bit 3
          RB4       0x06,4  bit 4 (RB4-7 intr-on-change)
          RB5       0x06,5  bit 5
          RB6       0x06,6  bit 6
          RB7       0x06,7  bit 7

          INTCON BITs

          RBIF      0x0B,0  bit 0 (Change on RB pend Flg)
          INTF      0x0B,1  bit 1 (INT pending Flag)
          RTIF      0x0B,2  bit 2 (RTCC Intr pending Flg)
          RBIE      0x0B,3  bit 3 (Change on RB4-7 IntEn)
          INTE      0x0B,4  bit 4 (INT Intr Enable)
          RTIE      0x0B,5  bit 5 (RTCC overflow Intr En)
          EEIE      0x0B,6  bit 6 (EEwrite Intr Enable)
          GIE       0x0B,7  bit 7 (General Intr Enable)

          OPTION BITs

          PS0       0x81,0  bit 0 (Prescaler val bit 0)
          PS1       0x81,1  bit 1 (Prescaler val bit 1)
          PS2       0x81,2  bit 2 (Prescaler val bit 2)
          PSA       0x81,3  bit 3 (Prescaler Assign bit)
          RTE       0x81,4  bit 4 (RTCC signal edge)
          RTS       0x81,5  bit 5 (RTCC signal source)
          INTEDG    0x81,6  bit 6 (INT edge select)
          RBPU      0x81,7  bit 7 (Port B pull-up Enable)

          EECON1 BITs

          RD        0x88,0  bit 0 (Read ctl: 1=read)
          WR        0x88,1  bit 1 (Write ctl: 1=write)
          WREN      0x88,2  bit 2 (Write enable: 1=write)
          WRERR     0x88,3  bit 3 (Write error: 1=fail)
          EEIF      0x88,4  bit 4 (EEwrite done Intr Flg)

          Helpful defines

          Same      1       destination codes
          F         1
          W         0
          LSB       0       Least Significant Bit
          MSB       7       Most Significant Bit
          TRUE      1
          FALSE     0
          YES       1
          NO        0

          Other variables:



     Page 4






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



          $    Equal to the current program pointer value.

     Operators
          Nearly all of the C operators are supported with the C
          precedence levels:

          (  )

          !  ~

          *  /  %

          +  -

          <<  >>

          <  <=  >  >=

          ==  !=

          &

          ^

          |

          &&

          ||

          =  +=  -=  *=  /=  %=  &=  ^=  |=  <<=  >>=

          ,

     Assembler Pseudo-Operations supported:
          In the following list, words surrounded by square braces
          ([...])  are optional.

          BIT
               <symbol> BIT <expr>, <expr>
               Define a "file_reg, bit" symbol and value.  This works
               like EQU, but defines a symbol with a bit value.  When
               used as a value in an ordinary expression, the symbol
               has the value (1 << bit).  When used in an instruction
               that takes a "f,b" argument, it supplies both the file
               register and the bit number.  Example:

                 C_bit   BIT     3, 0    ; Carry is bit 0 of register 3
                         ....
                         BSF     C_bit   ; set Carry
                         ANDWF   C_bit | TO_bit, W




     Page 5






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



          BYTE, DB, DBYTE, RES
               [<label>] BYTE <expr>
               If present, BYTE (or its synonyms) defines the optional
               label to point to the current data address, then
               increments the data address pointer by <expr> bytes.
               Use it to reserve byte variables or small arrays.  (You
               can't have large arrays with only 36 bytes of RAM.)

                 JoeBob  BYTE    1       ; JoeBob is a byte variable
                 name    BYTE    5       ; name is an array 5 bytes long


          DATA
               [<label>] DATA <expr_list>
               DATA is a synonym for the RETLW opcode.  The
               <expr_list> may be one or more expressions, constants,
               and character strings, separated by commas.  (Note that
               strings are _not_ NUL terminated.)

                 string  DATA    "I'm a string!", 0


          DORG
               [<label>] DORG <expr>
               Sets the data address pointer to <expr>. The data
               address pointer starts out at 0x0C, which is the first
               general-purpose byte of RAM.  There are 36 bytes of RAM
               in the 16C84.

                         DORG    0x10    ; jump data alloc to 0x10


          DW, DWORD, WORD
               [<label>] DWORD <expr>
               If present, DWORD (or its synonyms) defines the
               optional label to point to the current data address.
               The data pointer is advanced by (2 * <expr>) bytes.

                 wd_var  WORD    1       ; wd_var is a word variable


          EEB, EEBYTE
               [<label>] EEBYTE <expr_list>
               If present, EEBYTE (or EEB) defines the optional symbol
               to point to the current EEPROM address.  The bytes of
               EEPROM are initialized to the value(s) of <expr_list>.

                 eestr   EEBYTE  "Zot!", ' ', 45, Zuul + 9 / 2, 0


          EEW, EEWORD
               [<label>] EEWORD <expr_list>



     Page 6






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



               Like EEWORD but defines words instead of bytes.
               Character strings are not allowed in EEW's <expr_list>.

                 speedc  EEWORD  MAX_PULSES / PWM_FREQ


          END
               END
               End of program.  Stops the assembler from reading any
               more of the current file.

          EQU, =
               <symbol> EQU <expr>
               Define a symbol with value set to <expr>. Example:

                 FREQ    =       4000000         ; Frequency is 4 MHz
                 M_CYCLE EQU     FREQ / 4        ; 1 Machine cyc = 4 clock cyc


          EORG
               [<label>] EORG <expr>
               Sets the EEPROM address pointer to <expr>. The EEPROM
               address pointer starts out at 0, the first byte of
               EEPROM, and is automatically incremented.  There are 64
               bytes of data EEPROM in the 16C84.

                         EORG    0x20    ; skip half the EEPROM


          FILL
               [<label>] FILL <numw>, <value>
               Fills the next <numw> words of program memory with the
               constant value <value>. The program address pointer is
               advanced accordingly.

                         FILL    CODE_END - $, 0x3FFF


          FUSE
               FUSE <expr>
               Sets the configuration fuse word to <expr>. This
               selects the oscillator type, and controls the state of
               code protection, the power-up time delay, and the
               watchdog timer.

                         FUSE    0x3FF5        ; XT_osc|WDT_on|PWRTE_off|CP_off


          ID
               ID <expr_list>
               Sets one or more of the four ID words to the value(s)
               in <expr_list>. The ID address pointer is advanced by



     Page 7






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



               the number of words.  There are four ID EEPROM words in
               the 16C84.

                         ID      "v5.4"


          ORG, PORG
               [<label>] ORG <expr>
               Sets the program address pointer to <expr>. The program
               address pointer starts out at 0 (the 16C84's reset
               vector).  There are 1024 program EEPROM words in the
               16C84.

                         ORG     0       ; move org to 16C84's reset vector


          UNEQU
               UNEQU <symbol>
               Causes the given symbol or label to become undefined.

                         UNEQU   FREQ    ; FREQ goes away


     Built-in Functions:
          HIGH(expr)
               Returns byte # 1 of expr.  Equivalent to (((expr) >> 8)
               & 0xFF).

          LOW(expr)
               Returns the least significant byte of expr.  Equivalent
               to ((expr) & 0xFF).

          MAX(expr, expr)
               Returns the larger of the two values.

          MIN(expr, expr)
               Returns the smaller of the two values.

     Source Code
          The program was deliberately kept simple.  (Maybe too
          simple.  8-) It should run with almost any ANSI C compiler
          and POSIX-compatible standard C library package.  The
          lexical analyzer is made using flex's caseless lexer option,
          so flex is required.  The parser works with standard yacc,
          byacc, and bison.

     DIFFERENCES FROM OTHER COMMON PIC ASSEMBLERS
          *    It has no Parallax "enhancements".

          *    Currently has no INCLUDE (hooks are in the code, but
               time is short).




     Page 8






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



          *    No macros.

          *    No IF, ELIF, ELSE, or ENDIF.

          *    The output format is INHX8M only.

          *    Rather than do the "ORG 0xC\n var_name RES 1" stuff, I
               have separate address counters, allocation and ORG
               commands for the data and EEPROM memory spaces (DORG,
               EORG, DBYTE, EEBYTE, etc).

          *    The PIC 16C84 register and bit declarations are built
               into the assembler.  No INCLUDE "PICEQU.H" need be done
               (nor is possible at the moment).

          *    Not all of MPALC's odd constant formats are supported.

          *    It has standard C-like operator precedences, not simple
               left-to-right precedence.  I've removed the unary
               positive operator.

          *    No GUI, or any frills like that.  It should run with
               almost any ANSI C compiler and POSIX-compatible
               standard C library package.

          *    The lexical analyzer is made using flex features, so
               developers will need a copy of flex.  The parser works
               with bison, standard yacc, and byacc.

          *    The listing format is not the same as MPALC.

     FILES
          The following files are produced by the assembler, where
          file is the prefix before the final period (.) of the given
          filename.

          file.hex
               The INtel HeX 8-bit Merged (INHX8M) output file.

          file.lst
               The program listing and table of symbols.

     MEMORY SPACES
          The PIC 16C84 RISC microcontroller chip has four (count 'em
          -- 4) different memory spaces:

          Program memory
               1K of 14-bit words of EEROM.  Can only be altered in
               programming mode.  Can only be executed by programs,
               not referenced.  Hence the RETLW hack to put tables in
               program memory.  Program memory appears at 0x000 -
               0x3FF when burning in a program and also while



     Page 9






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



               executing programs.

          Data file memory
               36 bytes of real RAM, plus some special function
               registers that may have available bits.  Data memory is
               directly addressable in pages, bit addressable, and
               indirectly addressable through the FSR.  Data memory is
               not accessible when burning a program into the 16C84.

          EEROM data memory
               64 bytes of EEROM that may be reprogrammed while the
               16C84 is running (yes, even at 2.0 V for the LC
               version).  It is accessed through the EEADR and EEDATA
               file registers by programs and is made part of
               configuration memory for programming purposes.  Data
               EEPROM appears at 0x00 - 0x3F when using EEADR, and
               0x2100 - 0x213F when burning the 16C84.

          Configuration memory
               Accessible only in programming mode, this memory space
               contains the configuration fuse word and four 14-bit ID
               words of EEPROM.  The ID words are available for use to
               hold a checksum, or a version number, or some other
               identifing string of bytes.  If the code-protection
               fuse is set, then only the low 7 bits of the ID words
               are usable -- the high 7 bits must be all 1s.  Also,
               the data EEPROM appears in this space when programming.
               The ID words are at 0x2000 to 0x2003, and the fuse word
               is at 0x2007.

     Author
          James Cleverdon / jamesc@sequent.com

     PUBLIC DOMAIN INFORMATION
          Public domain 16C84 programmer circuits that use the
          parallel ports of common home computers are available, as is
          freely available software to program the 16C84.

          -    Here's a URL for the PIC 16C84's manufacturer,
               Microchip Technology:
               http://www.ultranet.com/biz/mchip/

          -    And, here's a URL for a manufacturer of many PIC
               products, Parallax, Inc.:
               http://www.parallaxinc.com/

          -    Rick Miller maintains the GNUPIC list:
               http://www.execpc.com/~rdmiller/gnupic

          -    Andy's PIC Project Page:
               http://www.lancs.ac.uk/people/cpaame/pic/pic.htm




     Page 10






     asm_c16(1)          Version 1.2 January 1996           asm_c16(1)



          -    Don McKenzie's PIC info:
               http://rasi.lr.ttu.ee/~sis/mirror/don/





















































     Page 11



