1 Week 5 Course notes Introduction to material covered this week Having reviewed the instruction set for the MC68HC11 with practice on some of the more frequently used opcodes, we are now ready to learn and work with the interface and programming of Input/Output ( I/O ) devices. It is in those applications where you will see the power of the microcontroller and its relative ease of use. As you recall, the scheme used by Motorola for I/O handling is the Memory Mapped I/O method. In this method, I/O lines are configured as a combination of Input/ Output through a control register called the Data Direction Register ( DDR ). The method is very simple; a 0 in a given bit of the DDR configure the corresponding line as an INPUT line, whereas a 1 configure it as an output line. The MC68HC11 ports will be discussed in detail later in this discussion. Due to the use of numerous ports performing various functions, we need at this time to focus our attention to assembly techniques and directives available to us in the Motorola cross assembler, and which help us better document our source code. Our goal from this point forward is to write structured programs with conventional documents. To that end, there are some simple assembly directives which help us accomplish this goal. These are listed in the section on more assembly directives below. Our Input/Output programming and interfacing will begin with Display technologies. We will
2 study the following: Light Emitting Diode ( LED ) discrete displays Liquid Crystal ( LCD ) displays Multiplexed LED displays In these discussions, we will also learn how to use the computer monitor and keyboard for I/O using some of the Buffalo ROM routines We will also integrate the interface and programming of an external unencoded keyboard for input and programming control. In all experiments, you will be given an interface board which we specifically designed and build to make the learning, programming and hardware interfacing much easier. I also will have for you a quick orientation module in the training link button for each of these boards once they are issued to you. Outline of what s ahead for this week This week we will address two separate topics: Part I: Summary & additional useful assembly directives Part II: I/O programming and interfacing of Light Emitting Diode ( LED ) discrete displays Part I: Summary & additional useful assembly directives CREATING A SOURCE CODE FILE A source code file consists of source code lines, which make up a program. An AS11 user
3 employs a word or text processor to create a source code file. After creating this file, the user converts it to ASCII. That is, the user assures that the source code file contains only ASCII characters. Most word processors can convert a file to ASCII with a few simple commands. Source Code Fields The user enters source code lines one at a time. A source code line includes four fields: 1. Label 2. Operation 3. Operand 4. Comments The label field identifies constants, operands, addresses, program routines, subroutines, or interrupt routines. Use labels in lieu of direct references to memory addresses or constant values. A label field can contain up to fifteen characters. The label must begin with a letter, a period (.), or an underline (_). Remaining characters in a label may be letters, numbers, periods, dollar signs, or underlines. Avoid spaces (made with the space bar) within a label. Use an underline instead of a space. The operation field identifies an action to be taken by either the M68HC11 or the AS11 assembler. The operation field can therefore contain either a mnemonic from the M68HC11 instruction set or an assembler directive. An assembler directive does not form a part of the program code. Rather, a directive instructs the AS11 on how to assemble the program code. The operand field serves four functions. First, the operand field defines an instruction s addressing mode. The operand field employs syntax elements to identify M68HC11 addressing modes. For example, a # prefix identifies an immediate-mode operand. Second, the operand field can specify a constant. A numerical entry into the operand field can specify this constant, or the user can identify the constant by entering a previously established label. Third, the operand field can specify an operand s address. A programmer can enter the address itself, or can enter a previously established label identifying the address. Finally, the operand field can identify a program jump or branch destination. Again, the user can enter the address itself or a previously established label.
4 The comments field allows a programmer to explain a source code line. An assembled S-recor will not include comments, but the list file will. Thus, comments are optional. A comment ca include any printable characters. Normally, comments follow the operand field in the source cod line. However, a comment can follow the operation field, when the instruction or directive require no operand. For example, an inherent-mode instruction, such as INX, uses no operand Additionally, the programmer can use a comment to identify program routines or sections. In thi case, the programmer enters an asterisk (*) as the first character in the label field. This asteris informs the AS11 that a comment follows, and that the source code line will include no othe fields. Creating a Source Code Line To create a source code line, enter the fields in the order discussed above. Start the label field at the left margin and separate fields with a single space (space bar). Do not use spaces within label, operation, or operand fields. The comments field can include spaces. Indicate the end of a source code line with a carriage return ( enter key). Numbers and Mathematical Operators Use care in entering numbers into the operand field. Use the following prefixes to identify decimal, hex, octal, and binary numbers: No prefix decimal (default, e.g., 53927) $ hexadecimal (e.g., octal % binary (e.g., % ) The binary designation % is particularly useful in I/O control registers and in masking type instructions as it quickly gives the reader the Port line assignment pattern. For example, a bit pattern of % will show the reader that the MS nibble is configured as output lines while the LS nibble interfaces to 4 input lines Use the following symbols to identify mathematical operators in the operand field: + add subtract * multiply I divide Assembler Directives Assembler directives are instructions to the AS11 on how it should assemble an S-record and create a list file. These directives fall into four categories. First, assembler directives may tell the AS11 where to locate program elements in M68HC11 memory. These elements can include program routines, operands, constants, and results. Second, directives may assign labels to numerical values or M68HC11 addresses. Third, directives may establish initial values in M68HC11 memory locations. Fourth, assembler directives control aspects of list file generation.
5 Following paragraphs describe these assembler directives in more detail. The NAM directive allows a programmer to assign a title to his or her program on the first line of the source code file and list file. Enter the NAM directive into the operation field, then follow with a space and title; for example, NAM LED-Lab8 where LED-Lab8 is the program s name. The ORG (Origin) directive establishes starting addresses for program memory blocks. An ORG directive can establish the starting address of a main program, a subroutine, or an interrupt routine. ORG can establish starting addresses for scratch pad memory blocks, operand storage areas, or results. Enter the ORG mnemonic into the operation field, and the starting address into the operand field. For example, ORG $0100 establishes a memory block starting at M68HC11 address $0100. The ORG source code line precedes a section of source code lines relevant to the memory block established. If a programmer enters no ORG directive, the AS11 assumes that the memory block begins at address $0000. You may redirect the assembler to any other RAM location anywhere in the program as many times as you wish. For example, following the first ORG $0100, somewhere later in the program you may enter ORG $0120 to direct the following part to start at $0120. etc.. EQU (Equate) directives establish address or operand values, and assign labels to them. An EQU directive does not cause the AS11 to store these values in M68HC11 memory. Enter the label to be assigned into the label field, the EQU mnemonic into the operation field, and the value to be assigned into the operand field. For example, PORTC EQU $1003 equates value $1003 to label PORTC. An FCB (Form Constant Byte) directive labels a specified value and assigns it to an M68HC11 memory location. The AS11 selects the memory location. Therefore, the programmer has no direct control over which memory byte will hold the specified value. Of course, a previous ORG directive has established a memory block in which the value will reside. Enter the label to be assigned into the label field, the FCB mnemonic into the operation field, and the value to be assigned into the operand field. For example, AUGEND FCB $9C assigns value $9C to a memory location labeled AUGEND. The AS11 selects the memory location. If the programmer makes no entry into the operand field, the AS11 stores $00 to the memory location. For example, AUGEND FCB assigns value $00 to a memory location labeled AUGEND.
6 A programmer can also use an FCB directive to initialize a series of memory locations with 8- bit values. The programmer enters these values into the operand field. Separate operand field values with commas. For example, the following source code line stores $9C, $10, and $8C to successive M68HC11 memory locations. Value $9C resides at a location labeled AUGENDS. Access value $10 at AUGENDS+l. Access value $8C at AUGENDS+2 : AUGENDS FCB $9C,$10,$8C If the programmer makes no entry between commas, the AS11 assigns a value of $00. The following would store $9C, $00, and $8C to successive memory locations. AUGENDS FCB $9C,,$8C The following source code line would store $00 to all three memory locations: AUGENDS FCB,, FDB (Form Double Byte) directives function in the same way as FCBs, except that FDBs store 2 bytes at a time. For example, AUGEND FDB $9C10 stores value $9C to a memory location labeled AUGEND. The AS11 stores $10 to location AUGEND+1. Another example: AUGEND FDB stores $00 to a location labeled AUGEND, and $00 to location AUGEND+ 1. Finally, this source code line stores values $9C, $10, $00, and $00 to successive memory locations. Access $9C at AUGEND, $10 at AUGEND+1, $00 at AUGEND+2, and $00 at AUGEND+3 AUGEND FDB $9C10, The RMB (Reserve Memory Bytes) directive labels and sets aside a series of M68HC11 memory locations. An RMB does not initialize these memory locations. The AS11 selects memory locations to be reserved. Of course, a previous ORG directive has established a memory block within which reserved bytes will reside. Enter the label to be assigned into the label field, and the RMB mnemonic into the operation field. Enter the number of bytes to be reserved into the operand field. For example, RESULTS RMB 15 reserves fifteen successive memory locations. The AS11 labels the first location RESULTS. Access following locations as RESULTS+1, RESULTS+2, etc. BSZ (Block Storage of Zeros) and ZMB (Zero Memory Bytes) directives cause identical responses from the AS11. BSZ/ZMB operates in a manner similar to the RMB, except that the AS 11 stores $00 to all reserved memory bytes. The AS11 selects the series of M68HC11 locations
7 to be reserved and initialized to zero. For example, RESULTS ZMB 20 reserves twenty successive memory locations and initializes them to $00. The first location is labeled RESULTS. Access remaining locations as RESULTS+1, RESULTS+2, etc. The FILL (Fill Memory) directive causes the AS11 to label and reserve a specified number of memory bytes. In addition, the AS11 initializes all of these bytes to a specified value. The AS11 selects the series of memory locations to be reserved. Enter the label to be assigned into the source code line s label field. Enter the FILL mnemonic into the operation field. Enter two values into the operand field. First, enter the 8-bit initialization value, then enter the number of bytes to be reserved and initialized. Separate these two values with a comma. For example, RESULTS FILL $FF,$19 reserves a series of twenty-five M68HC11 memory locations and initializes them all to $FF. The first memory location is labeled RESULTS. Access remaining locations as RESULTS+1, RESULTS+2 etc. The FCC (Form Constant Character String) directive causes the AS11 to label and store an ASCII string into a series of M68HC11 memory locations. Again, the AS11 chooses the memory locations. Enter the label to be assigned into the source code line s label field. Enter the FCC mnemonic into the operation field. Enter the ASCII string into the operand field. Prefix the string with a delimiter. Also add a suffix delimiter at the end of the string. Use identical and printable ASCII characters for the delimiters. The author suggests commas, colons, or semicolons as delimiters. Additionally, assure that the string includes only printable ASCII characters. An example: PROMPT FCC :ENTER_NEXT_OPERAND.: In response to this source code line, the AS11 stores ASCII string ENTER_ NEXT_OPERAND. into a series of M68HC1 1 memory locations. The first byte in the string is labelled PROMPT. Access remaining bytes of the string as PROMPT+l, PROMPT+2, etc. A more common use of the FCC directive is simply as follows: FCC Kent State Tuscarawas The following example shows a simple use of the ORG, EQU NAM Example ;use of the nam directive for program name PORTC EQU $1003 DDRC EAU $1007 ORG $100 FCB $20,$10,$5 ;use of Form Constant FDB $1122,$3344 ;use of Form Double - $106 ORG $150 FCC '0123ABCD' ;Form Constant ASCII ORG $170 FILL $22,$10 ;Fill 16 bytes with $22
8 ORG $190 FCC 'KENT STATE' ; use of Form Constant Character ORG $19A LDAA #$10 SWI Note that the EQU directive is a label. As such, it must start at column 1 whereas all other directives in the example start at position 2. The following example further illustrates the use of these directives. ORG $100 AUGENDS FCB $9C,$1C ORG $120 AUGEND FDB $1910 RESULTS RMB 2 LDAA AUGENDS LDAB AUGEND STAA RESULTS STX RESULTS+1 SWI Note that the some assembly directives like FCB, FCC etc..are non executable. As such, you can t direct the assembler to that location ( program counter ) and start execution. The line assembler will treat these hex codes as opcodes which will result in errors. Part II: I/O programming and interfacing of Light Emitting Diode ( LED ) discrete displays Parallel I/0 System Summary We need to distinguish clearly between the two operation modes: Single Chip Mode ( MODA Jumper ON, MODB Jumper OFF ) Expanded Mode ( MODA Jumper OFF, MODB Jumper OFF ) For our first set of experiments, using the LED interface board we will operate the processor in the Single chip mode ( RAM in Range $100 - $1FF ). This is because we have more I/O capabilities in the single chip mode. For now, we will just say that in the expanded mode, some of the I/O port lines are used for address lines. More detail on this is given in the MC68HC11 Reference manual and will be discussed later in the course. The following summarizes the use of 68HCl1 ports for parallel I/Q apd parallel I/O operations.
9 Port A: Data register is PORTA ($1000). Three input pins (PA0,1,2), four output pins (PA3,4,5,6), one bidirectional pin (PA7). Bit DDRA7 in register PACTL (B7 in $1026) sets the direction for PA7. Port B: Data register is PORTB ($1004). Parallel outputs only when in single-chip mode. ( Its pins are the high address byte in expanded mode). Port C: Data register is PORTC ($1003). Parallel Inputs OR Outputs when in single-chip mode. Direction is configured by register DDRC ($1007). ( Its pins are the multiplexed low address byte and data byte when in expanded mode). Port D: Data register is PORTD ($1008). Data direction register is DDRD ($1009, B0 to B5). Only pins PD0 to PD5 are available for input or output. PD6 is reserved for STRNAS. PD7 is reserved for STRB/R/W. Port E: Data register is PORTE ($l00a). Input only lines. Used for A/D converter inputs as well. Summary conclusion: For our first set of experiments, we will only use PORTC In the single chip mode, PORTC, PORTD are programmable general purpose I/O ports. PORTC gives us all 8 lines, PORTD gives us 6 lines PD0- PD5. With these two ports alone, we have 14 user programmable I/O lines PORTB is output only line
10 PORTA is has a mixed I/O assignment PORTE is Input only also used for A/D conversion input For our purpose, in using PORTC, there are simple steps to remember: Load the I/O bit pattern into either ACCA or ACCB STAA or STAB $1007 ( DDRC ) Send the output data to the port using STAA or STAB $1003 ( PORTC ) whenever an output is needed For those PORT lines configured as input lines, use LDAA or LDAB $1003 to read the data Note that a READ ( LDA ) instruction on an output line returns the previous write data from that pin line ). The following simple example 1. configures the Low byte ( LS- 4 lines ) PC0 PC3 of PORTC as input lines and the High byte ( MS 4-lines ) PC3 PC7 as output lines. 2. Read PORTC 3. Deletes info. From the output lines ( masks ) since output data is irrelevant to the READ operation. 4. Store READ data in $00 5. Load PORTC write data FROM MEMORY $000A 6. Write to PORTC NAM I-OEXAMPLE ORG $0100 LDAA #$% ;initialize DDRC STAA $1007 ; LDAA $1003 ;READ PORTC ANDA #$0F ;delete 1 s in high byte STAA $00 ;STORE read data in $00 LDAA $0A ;LOAD PORTC write data from $0A STAA $1003 ;WRITE to PORTC SWI For the first 4 lab experiments you will be using the LED Display Board. You may view the orientation module for it any time from the web page training link button. In the second part for this week notes, we will discuss the specifics of seven segment display technology