User`s guide

MPLAB
®
IDE User’s Guide
DS51519B-page 226 © 2006 Microchip Technology Inc.
17.7.3 PIC18F MCU USART Example – SCL Stimulus
To use SCL Stimulus input to simulate USART/UART operation, follow the steps below.
1. Once the project is completed, you will need an input file to simulate USART
signal input.
-Select File>Open
to open an editor window.
- Enter message-based data for RCREG input (see
Section 18.2.5.2 “Message-Based Data File Description” for information
on this format). Example input might be:
//single-packet example
wait 20 ms
10 20 34
-Select File>Save
and name the file input.txt.
2. Select Debugger>SCL Generator>New Workbook
. Click on the
Register Injection tab.
- Under “Register”, select “RCREG”.
- Under “Trigger”, “Message” will be selected. (There are no other choices.)
- Under “Data Filename”, locate and select input.txt.
- Under “Rewind”, select “Yes”.
- Under “Format”, “Pkt”, or packet, will be selected. (There are no other
choices.)
-Click Generate SCL from Workbook and name the file usart.scl.
-Click Exit and save the workbook (usart.sbs).
3. Select Debugger>Stimulus Controller>New Scenario
.
- Under “Stimulus (SCL) File”, click Attach.
- In the Open dialog, select usart.scl and click OK.
-Click Save Scenario to save the scenario (usart.stc), then minimize this
window as it must stay open for stimulus operation.
4. Open a Watch window to see the USART registers update.
-Select View>Watch
.
- In the Watch window, add the SFRs RCREG and TXREG.
5. Build the project again and run it to see the output in the Watch window.
-Select Project>Build All
.
- Place a breakpoint at the beginning of the interrupt vector (IntVector) code,
i.e., at line
btfss PIR1,RCIF ; Did USART cause interrupt?”.
- Run the code till the breakpoint halt to see the value of RCREG change.
- Step to see the value of TXREG change to match the injected value of
RCREG.
- Run and step again to see the values change as per the input file.
17.7.4 Updated PICDEM™ 2 Example Code
;
; Software License Agreement
;
; The software supplied herewith by Microchip Technology Incorporated
; (the “Company”) for its PICmicro® Microcontroller is intended and
; supplied to you, the Company’s customer, for use solely and
; exclusively on Microchip PICmicro Microcontroller products. The
Note: “Enable UART1 I/O” must be unchecked on the UART IO tab, Settings
dialog (Debugger>Settings
) or this method will not work.