In the first edition of this book, I created a very complex "emulator" which used an external serial EEPROM for storing instructions. This application worked okay, but was very (read "unnecessarily") complex and slow - the best speed I was able to observe was about ten thousand instructions per second. This application takes advantage of the PIC16F876 to read and write its own program memory to download a hex file and allow you to single step through it at a full application speed of 4 MHz.
This application is not perfect, but it is an excellent tool to see how the PICmicro® MCU works and help you to debug your own applications. The tool itself is wired to a PC/Workstation in exactly the same manner as the YAP-II and requires the same power input.
Click Here to access the source code on the CD-ROM. When you read the text, you'll see that I came up with the DT Compress utility that converts ASCII table data in the PIC16F87x parts (which can read their own program memory). This code takes an assembler source file (ending in ".asm") and converts "dt" statements into "dw" statements when they have been identified with:
;#CompStartstatements. To end the DT Compress operation, the:
;#CompEndstatement is put in. This is shown in the compress.asm" assembler code. Compare this file to compress.inc.
When I laid out the PCB for the EMU-II, I used the same form factor as the YAP-II. This simplified the layout work somewhat, but more importantly, gave me the same peripherals as the YAP-II, which allows the EMU-II to work through many of the same experiments as the YAP-II. The biggest difference between the EMU-II and the YAP-II is the lack of a clock at the PICmicro$reg; MCU connector. For experiments and applications that are put on the PCB's breadboard, they will also have to have their own oscillator.
The EMU-II's primary circuit is shown in the emu-ii.pdf file. The peripheral functions can be found in the yap-iiac.pdf file and are identical to the YAP-II's.
The bill of materials for the YAP-II is listed in the table below.
Part | Description |
---|---|
U1 | PIC16F877-04/P PIC16F876-04/SP |
U2 | 18 Pin Socket/ZIF Socket |
U4 | 78L12 +12 Volt Regulator in a TO-92 Package |
U5 | Maxim MAX232 RS-232 Interface |
U6 | 7805 +5 Volt Regulator in a TO-92 Package |
Y1 | 4 MHz Ceramic Resonator with Internal Capacitors |
CR2 - CR5, CR7 | 1N914 Silicon Diode |
CR4 | 1N4001 Silicon Diode |
CR1, CR6 | 5mm LED, Any Type |
LED3 | 10 LED "Bargraph" Display |
T1 | 2N3904 NPN Bipolar Transistor |
Q5 | 2106A P-Channel MOSFET (Digi-Key Part Number: ZVP2106A-ND) |
R1 | 10K, 1/4 Watt Resistors |
R2, R7 | 220 Ohm, 1/4 Watt Resistors |
R35, R10, R13 | 330 Ohm, 1/4 Watt Resistors |
POT1 - POT2 | 10K, Single Turn PCB Mount Potentiometer (Digi-Key Part Number: 3310Y-1-103-ND |
SIP1 - SIP2 | 220 Ohm, x9 Common Pin SIP |
C3 | 0.1 uF Capacitors (Any Type) |
C4 - C8 | 1.0 uF Capacitors (Any Type) |
C1 - C2 | 10 uF, 35 Volt, Electrolytic Capacitors |
CSPKR | 0.47 uF, 16 Volt, Tantalum Capacitor |
SPKR | Piezo Speaker (Digi-Key Part Number: P9922-ND) |
SW1 | SPDT PCB Mount Switch |
SW2, BUT1, BUT2 | Momentary On, PCB Mount Push Buttons |
J1 | 2.5 mm PCB Mount Power Socket |
J2 | 9-Pin Female PCB Mount D-Shell |
J3, J5 | 19x1 Female IDC Connector |
J4, J6 | 5x1 Female IDC Connector |
Miscellaneous | PCB Board, Serial Cable, Power Supply |
The nineteen pin connector wired to the PICmicro MCU is defined as:
Pin | Function |
---|---|
1 | Gnd |
2 | Vcc |
3 | _MCLR - No High Programming Voltage |
4 - 6 | RC3 - RC5 |
7 - 11 | RA0 to RA4 |
12 - 19 | RB0 to RB7. Note: RB6 and RB7 cannot be loaded during programming operation |
Operation
Once the display is active, then the commands listed in the following table can be entered. Note that "Parameters" in square brackets ("["/"]") are optional. All numeric data is in hexadecimal and register addresses can either be a hex address or a register name. When register data is displayed, the information will either be in hex or binary format depending on which format is appropriate for the register.
Command | Parameters | Comments |
---|---|---|
H | Display List of Commands | |
D | Download Application Hex File | |
! | [D | A] | Reset Emulated Part with "A"nalog or "D" PORTA I/O Pins |
1 | [Address] | Single Step starting at current Program Counter or Specified Address
|
J | [Address] | Single Step starting at current Program Counter or Specified Address
|
G | [Address] | Start Executing at current Program Counter or Specified Address
|
I | Address | Set Program Counter to specified Address |
R | Display the Primary Special Function Registers in the PICmicro MCU | |
S | Register | Display the contents of 16 Registers starting at "Register" Address |
E | Register | Display and optionally change the contents of the specified Register |
B | [Address] | Toggle a breakpoint at either the specified address or the current Program Counter |
C | Clear all the Breakpoints in the Emulator | |
U | [Address] | Disassemble the 22 instructions starting at either the current Program Counter or the specified address |
+ | [Address] | Load hex values that are to be entered into Program Memory either Starting at the current Program Counter or the specified address |
The operation of the application is quite straightforward with the only non-intuitive operation being the application download operation. To load a new application into the EMU-II's Program Memory, carry out the following steps:
- Enter "D"/CR ("Enter" if a PC is being used). The EMU-II will return with a message saying that Program Memory is being cleared
- When the EMU-II requests the application to be downloaded, use the Terminal Emulator to send a "Text File" "Hex File". This operation will be picked up by the EMU-II and the application code will be stored into the Program Memory devoted to the operation
The Download operation will not typically have any feedback as to the status of the operation. This can make the operation worrisome but note that after the application hex file has been sent, the EMU-II will poll incoming serial data for five seconds to ensure the host system (PC) download was not pre-empted by another task. No characters should be entered in the PC keyboard until the EMU-II prompt (which will be at address 0) has been displayed.
The following register names have been built into the EMU-II to allow for some symbolic application debugging:
Bank 0 | Bank 1 | ||
---|---|---|---|
Address | Register Name | Address | Register Name |
0x000 | INDF | 0x080 | INDF |
0x001 | TMR0 | 0x081 | OPTION (2) |
0x002 | PCL | 0x082 | PCL |
0x003 | STATUS | 0x083 | STATUS |
0x004 | FSR | 0x084 | FSR |
0x005 | PORTA | 0x085 | TRISA |
0x006 | PORTB | 0x086 | TRISB |
0x007 | PORTC | 0x087 | TRISC |
0x008 | PORTD (1) | 0x088 | TRISD (1) |
0x009 | PORTE (1) | 0x089 | TRISE (1) |
0x00A | PCLATH | 0x08A | PCLATH |
0x00B | INTCON | 0x08B | INTCON |
0x00C | PIR1 | 0x08C | PIE1 |
0x00D | PIR2 | 0x08D | PIE2 |
0x00E | TMR1L | 0x08E | PCON |
0x00F | TMR1H | 0x08F | Zero (3) |
0x010 | TCON1 | 0x090 | Zero (3) |
0x011 | TMR2 | 0x091 | SSPCON2 |
0x012 | TCON2 | 0x092 | PR2 |
0x013 | SSPBUF | 0x093 | SSPADD |
0x014 | SSPCON | 0x094 | SSPSTAT |
0x015 | CCPR1L | 0x095 | Zero (3) |
0x016 | CCPR1H | 0x096 | Zero (3) |
0x017 | CCP1CON | 0x097 | Zero (3) |
0x018 | RCSTA (4) | 0x098 | TXSTA (4) |
0x019 | TXREG (4) | 0x099 | SPBRG (4) |
0x01A | RCREG (4) | 0x09A | Zero (3) |
0x01B | CCPR2L | 0x09B | Zero (3) |
0x01C | CCPR2H | 0x09C | Zero (3) |
0x01D | CCP2CON | 0x09D | Zero (3) |
0x01E | ADRESH | 0x09E | ADCRESL |
0x01F | ADCON0 | 0x09F | ADCON1 |
The following notes apply to the registers:
- Registers and I/O Ports are Not Available in the PIC16F876
- Register is known as "OPTION_REG" in Microchip Documentation/Tools
- No special functions devoted to these registers, 0x000 always returned upon register read
- Registers used by the EMU-II. These registers along with the registers EEPROM registers (EEDATA, EEDATH, EEADR, EEADRH, EECON1 and EECON2) should never be accessed except using the functions listed below
As indicated in the notes above, the USART and EEPROM registers should never be accessed by an application. Instead, the following functions should be used for serial communications with the PC Host and for accessing the Data EEPROM. The Program Memory EEPROM must never be accessed. The serial port registers are enabled for non-interrupt communications at 1200-8-N-1 and should not be modified in any way.
Address | Function Name | Description |
---|---|---|
0x07B0 | SerialPoll | If Character Received and not yet read, return with the carry flag set |
0x07C0 | SerialRead | Wait until a character has been received and return it in "w" |
0x07D0 | SerialWrite | Send the Character in "w" out serially to the host |
0x07E0 | EERead | Read the Data EEPROM at the Address specified in FSR |
0x07F0 | EEWrite | Write the Data EEPROM with the value in "w" at the Address specified in FSR |
EMU-II Application Specification
Applications written for generic PICmicro MCU applications can be debugged using the EMU-II with very little modification. The EMU-II was designed to minimize the need for developing applications that had to be modified for both EMU-II operation and actual application operation.
To create applications that can be debugged on the EMU-II, the following rules must be followed:
- "nop" as the first instruction at address 0x0000
- Variables should start at 0x020 rather than 0x00C as is possible in some devices
- Use the USART and EEPROM functions listed above and do not access the Special Function Registers that control these functions directly
- For variables that are accessed from either Bank 0 or Bank 1, use address range 0x070 to 0x07E
Ideally, applications should not access any registers in Bank 2 or Bank 3 as the EMU-II state variables are stored in these banks along with the EEPROM access control registers.
As noted above, applications cannot be larger than 1,792 (0x0700) instructions. It is recommended that applications use the:
__CONFIGstatement to specify the operating characteristics of the application even though it will be ignored by the EMU-II. The config and __IDLOCS data will be stored within the EMU-II for programming into a PICmicro MCU.
No comments:
Post a Comment