Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

Chapter 3 - A Simple PIC Application > 3.3. Program BIN1 - Pg. 52

52 Chapter 3 3.2.5. Port A Data Register, PORTA: File Register 05 The least significant five bits of File Register 05 are connected to pins RA0eRA4, the other three being unused. Inputs RA0 and RA1 will be used later to read the push buttons. If not initialized as outputs, the PIC I/O pins automatically become inputs, i.e. TRISA ¼ xxx11111. We will use this default setting for port A, so this port does not have to be explicitly initialized. The state of these inputs will have no effect unless the program actually uses them; the first program BIN1 will not use them. 3.2.6. General Purpose Register 1, GPR1: File Register 0C The first GPR will be used later in a timing loop. It is the first of a block of 68 such registers, numbered 0C to 4F in the '84A chip. They may be allocated by the programmer as required for temporary data storage, counting and so on. 3.2.7. Bank 1 Registers The main registers such as the program counter and port data registers are in a random access memory (RAM) block called register bank 0, while TRISA, TRISB and PCLATH are in a separate block, bank 1. Bank 0 can be directly addressed, meaning that data can be moved into it using a simple `move' instruction. Unfortunately, this is not the case with bank 1. There are two ways to write to these registers. The first way is a simple method, which we will use initially; it requires the required 8-bit code to be loaded into W first, and then moved into the bank 1 register using the TRIS instruction. Later, we will use the recommended method, using bank selection, but this is a little more complicated. TRIS does not now appear in the main instruction set, but continues to be recognized by the PIC assembler. 3.3. Program BIN1 The simple program called BIN1 is shown as Program 3.1. It consists of a list of 14-bit binary machine code instructions, represented as four-digit hex numbers (see Chapter 2). Bits 14 and 15 are assumed to be zero, so the codes are represented by hex numbers in the range 0000 to 3FFF. The program is stored at hex addresses 0000 to 0004 (five instructions) in program memory. 3.3.1. Program Analysis The program instructions must be related to the PIC internal architecture, as outlined in Chapter 2, and specified in the data sheet. The instruction set in the data sheet explains the significance of each bit in each instruction.