Tải bản đầy đủ (.pdf) (13 trang)

AN0704 interfacing microchip’s MCP3201 analogdigital (AD) converter to MC68HC11E9 based microcontroller

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (193.28 KB, 13 trang )

AN704
Interfacing Microchip’s MCP3201 Analog/Digital (A/D) Converter to
MC68HC11E9-Based Microcontroller
Author:

Richard L. Fischer
Microchip Technology Inc.

INTRODUCTION
Many of the embedded control systems designed today
require some flavor of Analog-to-Digital (A/D) Converter. Embedded system applications such as Data
Acquisition, Sensor Monitoring, and Instrumentation
and Control all have varying A/D Converter requirements.
For the most part, these A/D Converter requirements
are a combination of performance, cost, package size
basis and availability. In some applications a microcontroller with an on-chip A/D Converter may meet the
design requirements. Typically, these on-chip A/D Converter modules fit well into embedded applications
which require a 10-35ksps A/D Converter. In other
applications, a stand-alone A/D Converter is required
for various performance reasons.
For those applications which require higher performance or remote sense capability, the Microchip
MCP3201 12-bit A/D Converter fits very nicely.
The Microchip Technology Inc. MCP3201 employs a
classic SAR architecture. The device uses an internal
sample and hold capacitor to store the analog input
while the conversion is taking place. Conversion rates
of 100ksps are possible on the MCP3201. Minimum
clock speed (10 kHz or 625sps, assuming 16 clocks) is
a function of the capacitors used for the sample and
hold.
The MCP3201 has a single pseudo-differential input.


The (IN–) input is limited to ±100mV. This can be used
to cancel small noise signals present on both the (IN+)
and (IN–) inputs. This provides a means of rejecting
noise when the (IN–) input is used to sense a remote
signal ground. The (IN+) input can range from the (IN-)
input to VREF.
The reference voltage for the MCP3201 is applied to
VREF pin. VREF determines the analog input voltage
range and the LSB size, i.e.:

As the reference input is reduced, the LSB size is
reduced accordingly.
Communication with the MCP3201 is accomplished
using a standard SPI™ compatible serial interface.
This interface allows direct connection to the serial
ports of microcontrollers and digital signal processors.
The MCP3201 is suitable for use with a wide variety of
microcontrollers from Microchip and others. This application note describes how to interface the MCP3201
with a Motorola MC684C11 microcontroller. Application
Note, AN702 covers microcontrollers based on the Intel
8051 architecture.
Figure 1 shows the hardware schematic for this interface. Appendix A contains a listing of the source code.

CIRCUIT DESCRIPTION
The serial interface of the Microchip MCP3201 A/D
Converter has three wires, a serial clock input (DCLK),
the serial data output (DOUT) and the chip select input
signal (CS/SHDN). For this simple circuit interface, the
Motorola MC68HC11E9 SPI port is used. PORTD:<4>
is configured for the serial clock and PORTD:<2> is the

data input to the microcontroller. The SPI clock rate for
this application is set at 1 MHz.
The MC68HC11 is configured in the master mode with
its CPOL and CPHA bits set to logic one (default setting
on power-up).
A conversion is initiated with the high to low transition
of CS/SHDN (active low). The chip select is generated
by PORTD:<5> of the microcontroller. The device will
sample the analog input from the rising edge of the first
clock after CS goes low for 1.5 clock cycles. On the falling edge of the second clock, the device will output a
low null bit. With the next 12 clocks, the MCP3201 will
output the result of the conversion with the MSB first
(See Figure 2 and Figure 3). Data is always output from
the device on the falling edge of the clock. If the device
continues to receive clocks while CS/SHDN is low, the
device will output the conversion LSB first. If more
clocks are provided to the device while CS/SHDN is still
low (after the LSB first data has been transmitted), the
device will clock out zeros indefinitely.

LSB size = VREF
212

SPI is a trademark of Motorola Inc.

 1999 Microchip Technology Inc.

DS00704B-page 1



AN704

FIGURE 1:

Hardware Schematic

DS00704B-page 2

 1999 Microchip Technology Inc.


AN704

CS/SHDN
MCU latches data from A/D Converter
on rising edges of DCLK
1

DCLK

2

3

4

5

6


8

7

9

10

11

12

13

14

15

16
Data is clocked out of
A/D Converter on falling edges

DOUT

NULL
BIT B11 B10

HI-Z

B9


B8

B7

B6

B5

B4

B3

B2

B1 B0

HI-Z

B1

LSB first data begins
to come out

MCU Received Data
(After 16 clocks)

FIGURE 2:

?


?

B11 B10 B9

0

B8

B7

B6

B5

B4

B3

B2

B1

B0

B1

SPI Communication using 8-bit segments (Mode 1,1: SCLK idles high).

CS/SHDN

MCU latches data from A/D Converter
on rising edges of DCLK
1

DCLK

2

3

4

5

6

7

8

9

10

11

12

13


14

15

16
Data is clocked out of
A/D Converter on falling edges

DOUT

HI-Z

NULL B11 B10 B9
BIT

B8

B6

B7

B5

B4

B3

B2

B1


B0 B1 B2

HI-Z
LSB first data begins
to come out

MCU Received Data
(After 16 clocks)

FIGURE 3:

?

?

0

B11 B10 B9

B8

B7

B6

B5

B4


B3

B2

B1

B0

B1

SPI Communication using 8-bit segments (Mode 0,0: SCLK idles low).

 1999 Microchip Technology Inc.

DS00704B-page 3


AN704
As the analog input signal is applied to the IN+ and INinputs, it is ratioed to the VREF input for conversion scaling.

Digital output code = VIN x F.S.
VREF
Where:

VIN = analog input voltage V(IN+) - V(IN–)
VREF = reference voltage
F.S. = full scale = 4096
VREF can be sourced directly from VDD or can be supplied by an external reference. In either configuration,
the VREF source must be evaluated for noise contributions during the conversion. The voltage reference
input of the MCP3201 ranges from 250mV to 5VDC,

which approximately translates to a corresponding LSB
size from 61µV to 1.22mV per bit.

1.22mV = 5VDC
212 bits
For this simple application, the MCP3201 voltage
reference input is tied to 5VDC. This translates to a
1.22mV/bit resolution for the A/D Converter module.
The voltage input to the MCP3201 is implemented with
a multi-turn potentiometer. The output voltage range of
this passive driver is approximately 0VDC to 5VDC.
Finally, a simple RS-232 interface is implemented using
the USART peripheral of the microcontroller and a
MAX233 transceiver IC. The USART transmits the captured A/D Converter binary value, both in ASCII and
Decimal, to the PC terminal at 9600 baud.
As with all applications which require moderate to high
performance A/D Converter operation, proper grounding and layout techniques are essential in achieving
optimal performance. Proper power supply decoupling
and input signal and VREF parameters must be considered for noise contributions.

SOURCE CODE DESCRIPTION
The code written for this simple application performs
five main functions:
1.
2.
3.
4.
5.

Controller Initialization.

A/D Converter Conversion.
Conversion to ASCII.
Conversion to Decimal.
Transmit ASCII and Decimal to PC for display.

Upon power-up the microcontroller Port pins, USART
peripheral and SSP module are initialized. The default
microcontroller SPI bus mode is 1,1. The bus mode can
be changed on power-up via SW1. If SW1 is depressed
on power-up then PORTC:<7> is pulled low. The initialization code checks this pin state and if a logic low SPI
bus mode 0,0 is selected. Likewise if PORTC:<7> is a
logic high, (SW1 is not depressed), then mode 1,1 is
the operational bus state. Once the initialization code is
executed, the main code loop is entered and executed
continuously.
After asserting PORTD:<5> the SPDR register is written to for initiating a SPI bus cycle. When the SPI cycle
is complete, (SPIF flag is set to logic 1), the received
data is read from the SPDR register and written to the
RAM variable RESULT_MSB. The SPDR register is
again written to, which initiates a SPI bus cycle, and the
second 8-bits are received and written to the RAM variable RESULT_LSB. Here the composite result, located
in variables RESULT_MSB and RESULT_LSB is right
adjusted one bit location. The CS/SHDN is then
negated and the MCP3201 enters into the shutdown
mode.
Next the hex_to_ascii and hex_to_decimal routines are called and executed. Then the
display_conversion routine is executed which
sends the data to the USART for transmission to the
PC for display.


REFERENCES
Williams, Jim, “Analog Circuit Design,” ButterworthHeinemann
Baker, Bonnie, “Layout Tips for 12-bit A/D Converter
Applications,” AN688, Microchip Technology Inc.
MCP3201 12-bit A/D Converter with SPI Serial Interface, Microchip Technology, Document DS21290B,
1999.

DS00704B-page 4

 1999 Microchip Technology Inc.


AN704
APPENDIX A:

SOURCE CODE

MCP3201.SRC Assembled with IASM 07/01/1999 11:30 PAGE 1
Interfacing Microchip MCP3201 ADC to Motorola MC68HC11E9-Based Microcontroller

0000
0000
0000
0000
0000
0000
0000
0000
0000
0000

0000
0000

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60

 1999 Microchip Technology Inc.

*****************************************************************
*
*
Filename:
MCP3201.src
*
Date:
07/01/99
*
*
File Version: 1.00
*
*
Author:
Richard L. Fischer
*
Microchip Technology Inc.
*
*****************************************************************
*
*
* This code demonstrates how the Microchip MCP3201 Analog-to-Digital
* Converter (ADC) is interfaced to the Synchronous Serial Peripheral
* (SSP) of the MC68HC11E9 microcontroller. The interface uses two

* Serial Peripheral Interface (SPI) lines (SCK, MISO) on the
* 68HC11E9 Microcontroller for the clock (SCK) and data in (MISO).
* A chip select (CS) to the MCP3201 is generated with a general
* purpose port line (PD5). The MC68HC11E9 is placed into the master
* mode which allows use of the port line PD5 for the CS control
* signal. The simple application uses Mode 00 or Mode 11 to the
* define bus clock polarity and phase.
*
* SPI bus mode 1,1 is the default mode of operation upon power-up.
* If SPI bus Mode 0,0 is desired, cycle off power, depress and
* hold SW1, cycle on power then release SW1. SPI bus Mode 0,0 is
* now the operational mode.
*
* For this application, the SPI data rate is set to one eighth of
* the microcontroller clock frequency. The MC68HC11E9 device clock
* frequency used for this application is 8MHz. This translates to
* an ADC throughput of 62.5kHz. In order to obtain the maximum
* throughput (100kHz) from the MCP3201 ADC the M68HC11E9 must be
* clocked at 12.8Mhz.
*
*
******************************************************************

***********************************************
*
MICROCONTROLLER RELATED EQUATES
*
***********************************************
REGBASE
PACTL

PORTA
PORTB
DDRC
PORTC
DDRD
PORTD

EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU

$1000
$26
$00
$04
$07
$03
$09
$08

;
;
;
;
;

;
;
;

Register Base Address
PortA bit7 control
PortA Address
PortB Address
PortD Data Direction Register
PortC Address
PortD Data Direction Register
PortD Address

SPCR
SPSR
SPDR

EQU
EQU
EQU

$28
$29
$2A

; SPI Control Register
; SPI Status Register
; SPI Data Register

BAUD


EQU

$2B

; Baud Rate Register

DS00704B-page 5


AN704
0000
0000
0000

0000

0000
0000
0001
0002
0003
0004
0005
0006

0025
0025
0025
0025

0025
0025

D000
D000 [03] 8E01FF
D003 [06] 7F0000
D006 [06] 7F0001
D009
D00C
D010
D013
D015
D016
D018
D01B

[03]
[04]
[05]
[04]
[03]
[04]
[04]
[03]

CE0006
18CED12D
18A600
A700
08

1808
8C0026
26F3

D01D [03] CE1000
D020
D023
D026
D029

[07]
[07]
[07]
[07]

1D00FF
1C2680
1D04FF
1C077F

DS00704B-page 6

61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

SCCR2

SCSR
SCDR

EQU
EQU
EQU

$2D
$2E
$2F

; SCI Control Register 2
; SCI Status Register
; SCI Data Register

MASKCS

EQU

$20

; Mask for Chip Select Bit

***********************************************
*
INTERNAL RAM USAGE
*
***********************************************
ORG


$0000

; Internal RAM

RESULT_MSB
RESULT_LSB

RMB
RMB

1
1

; Converted MSB
; Converted LSB

THOUS
HUNDS
TENS
ONES

RMB
RMB
RMB
RMB

1
1
1
1


;
;
;
;

DISPLAY_BUFF

RMB

1F

; Buffer string for display

Variable
Variable
Variable
Variable

for
for
for
for

ASCII
ASCII
ASCII
ASCII

thousands

hundreds
tens
ones

***********************************************
*
INTERNAL MEMORY EQUATES
*
***********************************************
EEPMBEG
EEPMEND

EQU
EQU

$B600
$B7FF

; EEPROM begin
; EEPROM end

EPRMBEG
EPRMEND

EQU
EQU

$D000
$FFFF


; EPROM begin
; EPROM end

RAMBEG
RAMEND

EQU
EQU

$0000
$01FF

; RAM begin
; RAM end

*****************************************************************

start

copy

ORG

EPRMBEG

; Beginning of code

LDS
CLR
CLR


#RAMEND
RESULT_MSB
RESULT_LSB

; Initialize Stack Pointer
; Clear ram variables
; Clear ram variables

LDX
LDY
LDAA
STAA
INX
INY
CPX
BNE

#DISPLAY_BUFF
#DISPLAY_IMAGE
0,Y
0,X

#DISPLAY_BUFF+20
copy

;
;
;
;

;
;
;
;

LDX

#REGBASE

; Initialize X Index pointer

BCLR
BSET
BCLR
BSET

PORTA,X,$FF
PACTL,X,$80
PORTB,X,$FF
DDRC,X,$7F

;
;
;
;
;

Initialize X pointer to RAM
Initialize Y pointer to ROM
Read from ROM

Save into RAM
Point to next RAM location
Point to next ROM location
Copy display string complete?
No, so copy some more

Set PortA outputs low
Set PortA bit7 to output
Set PortB outputs low
Set PortC for outputs
except for pin7

 1999 Microchip Technology Inc.


AN704
D02C [07] 1D03FF
D02F [07] 1C0937
D032 [02] 8620
D034 [04] A708
D036 [07] 1C2D08
D039 [02] 8630
D03B [04] A72B
D03D
D041
D043
D045

[07]
[02]

[04]
[03]

1E038006
8650
A728
2004

D047 [02] 865C
D049 [04] A728

D04B [07] 1D0820
D04E
D050
D054
D056

[06]
[07]
[04]
[03]

6F2A
1F2980FC
A62A
9700

D058 [06] 6F2A
D05A [07] 1F2980FC
D05E [07] 1C0820

D061 [04] A62A
D063 [03] 9701
D065 [06] 760000
D068 [06] 760001
D06B [06] 1500F0
D06E [06] BDD093
D071 [06] BDD0D3

D074 [04] 18CE0006
D078 [05] 18A600
D07B
D07D
D081
D083

[04]
[07]
[04]
[05]

A72F
1F2E40FC
1808
188C0026

127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192

 1999 Microchip Technology Inc.

m11

BCLR
BSET

PORTC,X,$FF
DDRD,X,$37

LDAA
STAA

#$20
PORTD,X

;
;
;
;
;

Set PortC outputs low
Make all PortD pins outputs
except PD3

BSET
LDAA

STAA

SCCR2,X,$08
#$30
BAUD,X

; Enable SCI TX
; Initialize SCI for 9600
; baud at 8Mhz

BRSET
LDAA
STAA
BRA

PORTC,X,$80,m11
#$50
SPCR,X
start_conversion

;
;
;
;

LDAA
STAA

#$5C
SPCR,X


; Mode 11
; Initialize SPI control reg

Set CS high and all other

Branch to Mode 11 if pin high
Else, Mode 00
Initialize SPI control reg
Go start conversion

*******************************************************
*
* The routines to follow perform 3 repetitive functions:
*
*
1. Initiate an ADC conversion sequence
*
2. Convert acquired data for display
*
2. Transmit converted data to PC
*
*******************************************************
start_conversion

rd1

rd2

*****


BCLR

PORTD,X,MASKCS

; Assert CS to ADC

CLR
BRCLR
LDAA
STAA

SPDR,X
SPSR,X,$80,rd1
SPDR,X
RESULT_MSB

;
;
;
;

Initiate SPI bus cycle
Wait until cycle completes
Read data and clear flag (SPIF)
Save off upper bits

CLR
SPDR,X
BRCLR SPSR,X,$80,rd2


; Initiate SPI bus cycle
; Wait until cycle completes

BSET
LDAA
STAA

PORTD,X,MASKCS
SPDR,X
RESULT_LSB

; Negate CS, place ADC in shutdown
; Read data and clear flag (SPIF)
; Save off lower bits

ROR
ROR
BCLR

RESULT_MSB
RESULT_LSB
RESULT_MSB,$F0

; Move bit 0 into carry
; Rotate MSB bit0 into LSB bit7
; Mask out upper bits of MSB

JSR
JSR


hex_to_ascii
hex_to_decimal

; Convert to ASCII for display
; Convert to decimal for display

ROUTINE FOR DISPLAYING CONVERTED DATA

***********

display_conversion

tx_loop

wtx

LDY
LDAA

#DISPLAY_BUFF
0,Y

STAA SCDR,X
BRCLR SCSR,X,$40,wtx
INY
CPY
#DISPLAY_BUFF+20

; Initialize Y pointer

; Retrieve MSB upper nibble
;
;
;
;

Initiate SCI Transmit
Wait until cycle completes
Increment Y pointer
All characters sent?

DS00704B-page 7


AN704
D087 [03] 26EF

D089 [04] 18CE0000
D08D [04] 1809
D08F [03] 26FC
D091 [03] 20B8

D093
D094
D097
D09B
D09D
D09E
D0A0
D0A1

D0A2
D0A3
D0A4
D0A6
D0A8
D0AA
D0AD
D0AF
D0B1

[04]
[03]
[04]
[04]
[03]
[02]
[02]
[02]
[02]
[02]
[02]
[03]
[02]
[05]
[03]
[02]
[05]

3C
CE0000

18CE000E
A600
36
84F0
44
44
44
44
8109
2F07
8B37
18A700
2005
8B30
18A700

D0B4
D0B6
D0B7
D0B9
D0BB
D0BD
D0BF
D0C2

[04]
[04]
[02]
[02]
[03]

[02]
[05]
[03]

1808
32
840F
8109
2F07
8B37
18A700
2005

D0C4 [02] 8B30
D0C6 [05] 18A700
D0C9
D0CA
D0CC
D0CF
D0D1
D0D2

D0D3
D0D5
D0D8
D0DB
D0DE

[03]
[04]

[04]
[03]
[05]
[05]

[04]
[06]
[06]
[06]
[06]

08
1808
8C0002
26CA
38
39

DC00
7F0002
7F0003
7F0004
7F0005

D0E1 [05] 1A8303E7
D0E5 [03] 2508

DS00704B-page 8

193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258

BNE

decy

*****

tx_loop

; No, so send more characters

LDY #$0000
DEY
BNE decy

; Approximately 485mS delay
; Decrement counter
; Stay in loop until Y=0

BRA start_conversion

; Stay in main loop

ROUTINE FOR CONVERTING TO ASCII


*****************

hex_to_ascii
Save off X Index register
Initialize X
Initialize Y
Get Result_MSB data
Save ACCA
Mask out lower nibble
Shift upper nibble
into lower nibble

#$09
numb_1
#$37
0,Y
do_lsb
#$30
0,Y

;
;
;
;
;
;
;
;
;
;

;
;
;
;
;
;
;

INY
PULA
ANDA
CMPA
BLE
ADDA
STAA
BRA

#$0F
#$09
numb_2
#$37
0,Y
next1

;
;
;
;
;
;

;
;

Increment Y
Restore ACCA
Mask out upper nibble
Is value a number ?
Yes, make it 0-9 ($30 - $39)
No, make it a letter (A - F)
Save ASCII letter

numb_2

ADDA
STAA

#$30
0,Y

;
; Save ASCII number

next1

INX
INY
CPX
BNE
PULX
RTS


#RESULT_MSB+2
next

;
;
;
;
;
;

next

numb_1

do_lsb

*****

PSHX
LDX
LDY
LDAA
PSHA
ANDA
LSRA
LSRA
LSRA
LSRA
CMPA

BLE
ADDA
STAA
BRA
ADDA
STAA

#RESULT_MSB
#DISPLAY_BUFF+8
0,X
#$F0

Is value a number ?
Yes, make it 0-9 ($30 - $39)
No, make it a letter (A - F)
Save ASCII letter
Convert lower nibble
Save ASCII number

Increment X
Increment Y
Converted all bytes?
No, so do some more
Else yes so restore X
Return from subroutine

ROUTINE FOR CONVERTING TO DECIMAL

***************


hex_to_decimal

ck_thous

LDD
CLR
CLR
CLR
CLR

RESULT_MSB
THOUS
HUNDS
TENS
ONES

;
;
;
;
;

Initialize ACCA and ACCB
Zero out THOUSANDS temp location
Zero out HUNDREDS temp location
Zero out TENS temp location
Zero out ONES temp location

CPD
BLO


#$03E7
ck_hunds

; ACCD >= 1000 or more?
; No, so go check hundreds

 1999 Microchip Technology Inc.


AN704
D0E7 [04] 8303E8
D0EA [06] 7C0002
D0ED [03] 20F2
D0EF
D0F3
D0F5
D0F8
D0FB

[05]
[03]
[04]
[06]
[03]

1A830063
2508
830064
7C0003

20F2

D0FD
D0FF
D101
D103
D106

[02]
[03]
[02]
[06]
[03]

C10A
2507
C00A
7C0004
20F5

D108
D10A
D10E
D110
D112
D115
D117
D119
D11B
D11E

D120
D122
D124
D127
D129
D12C

[02]
[04]
[03]
[02]
[05]
[04]
[03]
[02]
[05]
[04]
[03]
[02]
[05]
[04]
[05]
[05]

CB30
18CE001E
9602
8B30
18A700
1808

9603
8B30
18A700
1808
9604
8B30
18A700
1808
18E700
39

D12D

4865782D
3E203078
20202020
203A2044
6563696D
616C2D3E
20202020
200D0A

FFD6
FFD6
FFD8
FFDA
FFDC
FFDE
FFE0
FFE2

FFE4
FFE6
FFE8
FFEA
FFEC
FFEE
FFF0
FFF2

D000
D000
D000
D000
D000
D000
D000
D000
D000
D000
D000
D000
D000
D000
D000

259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

 1999 Microchip Technology Inc.

SUBD
INC

BRA

#$03E8
THOUS
ck_thous

; Subtract 1000 from ACCD
; Increment THOUS
; Go check for more

ck_hunds

CPD
BLO
SUBD
INC
BRA

#$0063
ck_tens
#$0064
HUNDS
ck_hunds

;
;
;
;
;


ACCD >= 100 OR more?
No, so go check tens
Subtract 100 from ACCD
Increment HUND
Go check for more

ck_tens

CMPB
BLO
SUBB
INC
BRA

#$0A
do_ones
#$0A
TENS
ck_tens

;
;
;
;
;

No, ACCB >= 10 or more?
No, finish up with ONES
Subtract another 10 from B
Bump “TENS”

Loop again

do_ones

ADDB
LDY
LDAA
ADDA
STAA
INY
LDAA
ADDA
STAA
INY
LDAA
ADDA
STAA
INY
STAB
RTS

#$30
#DISPLAY_BUFF+18
THOUS
#$30
0,Y

;
;
;

;
;
;
;
;
;
;
;
;
;
;
;
;

Convert ONES to ASCII
Initialize Y pointer into buffer

DISPLAY_IMAGE

HUNDS
#$30
0,Y
TENS
#$30
0,Y
0,Y

DB

‘Hex-> 0x


Convert THOUS to ASCII
Save it
Increment Y
Convert HUNDS to ASCII
Save it
Increment Y
Convert TENS to ASCII
Save it
Increment Y
Save conversion into string
Return from subroutine

: Decimal->

‘,0D,0A

***********************************************
*
INTERRUPT VECTORS
*
***********************************************
ORG

$FFD6

DW
DW
DW
DW

DW
DW
DW
DW
DW
DW
DW
DW
DW
DW
DW

start
start
start
start
start
start
start
start
start
start
start
start
start
start
start

; VECTORS
;

;
;
;
;
;
;
;
;
;
;
;
;
;
;

SCI Serial System - RIE, TIE, TCIE, ILIE
SPI Serial Transfer Complete - SPIE
Pulse Accumalator Input Edge - PAII
Pulse Accumalator Overflow - PAOVI
Timer Overflow - TOI
Timer Input Capture 4/Output Compare 5 - I4/O5I
Timer Output Compare 4 - OC4I
Timer Output Compare 3 - OC3I
Timer Output Compare 2 - OC2I
Timer Output Compare 1 - OC1I
Timer Input Capture 3 - IC3I
Timer Input Capture 2 - IC2I
Timer Input Capture 1 -IC1I
Real Time Interrupt - RTII
IRQ (External Pin)


DS00704B-page 9


AN704
FFF4
FFF6
FFF8
FFFA
FFFC
FFFE

D000
D000
D000
D000
D000
D000

318
319
320
321
322
323
324
325
326
327
328


0000

DW
DW
DW
DW
DW
DW

start
start
start
start
start
start

;
;
;
;
;
;

XIRQ Pin
Software Interrupt
Illegal Opcode Trap
COP Failure
Clock Monitor Fail
Reset


END

Symbol Table
BAUD
CK_HUNDS
CK_TENS
CK_THOUS
COPY
DDRC
DDRD
DECY
DISPLAY_BUFF
DISPLAY_CONVERSI
DISPLAY_IMAGE
DO_LSB
DO_ONES
EEPMBEG
EEPMEND
EPRMBEG
EPRMEND
HEX_TO_ASCII
HEX_TO_DECIMAL
HUNDS
M11
MASKCS
NEXT
NEXT1
NUMB_1
NUMB_2

ONES
PACTL
PORTA
PORTB
PORTC
PORTD
RAMBEG
RAMEND
RD1
RD2
REGBASE
RESULT_LSB
RESULT_MSB
SCCR2
SCDR
SCSR
SPCR
SPDR
SPSR
START
START_CONVERSION
TENS
THOUS
TX_LOOP
WTX

DS00704B-page 10

002B
D0EF

D0FD
D0E1
D010
0007
0009
D08D
0006
D074
D12D
D0B4
D108
B600
B7FF
D000
FFFF
D093
D0D3
0003
D047
0020
D09B
D0C9
D0AF
D0C4
0005
0026
0000
0004
0003
0008

0000
01FF
D050
D05A
1000
0001
0000
002D
002F
002E
0028
002A
0029
D000
D04B
0004
0002
D078
D07D

 1999 Microchip Technology Inc.


AN704
NOTES:

 1999 Microchip Technology Inc.

DS00704B-page 11



Note the following details of the code protection feature on PICmicro® MCUs.








The PICmicro family meets the specifications contained in the Microchip Data Sheet.
Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today,
when used in the intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet.
The person doing so may be engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable”.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of
our product.

If you have any further questions about this matter, please contact the local sales office nearest to you.

Information contained in this publication regarding device
applications and the like is intended through suggestion only
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
No representation or warranty is given and no liability is
assumed by Microchip Technology Incorporated with respect
to the accuracy or use of such information, or infringement of

patents or other intellectual property rights arising from such
use or otherwise. Use of Microchip’s products as critical components in life support systems is not authorized except with
express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property
rights.

Trademarks
The Microchip name and logo, the Microchip logo, FilterLab,
KEELOQ, microID, MPLAB, PIC, PICmicro, PICMASTER,
PICSTART, PRO MATE, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
dsPIC, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, microPort,
Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM,
MXDEV, PICC, PICDEM, PICDEM.net, rfPIC, Select Mode
and Total Endurance are trademarks of Microchip Technology
Incorporated in the U.S.A.
Serialized Quick Turn Programming (SQTP) is a service mark
of Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2002, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.

Microchip received QS-9000 quality system
certification for its worldwide headquarters,
design and wafer fabrication facilities in
Chandler and Tempe, Arizona in July 1999. The
Company’s quality system processes and
procedures are QS-9000 compliant for its

PICmicro® 8-bit MCUs, KEELOQ® code hopping
devices, Serial EEPROMs and microperipheral
products. In addition, Microchip’s quality
system for the design and manufacture of
development systems is ISO 9001 certified.

 2002 Microchip Technology Inc.


M
WORLDWIDE SALES AND SERVICE
AMERICAS

ASIA/PACIFIC

Japan

Corporate Office

Australia

2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200 Fax: 480-792-7277
Technical Support: 480-792-7627
Web Address:

Microchip Technology Australia Pty Ltd
Suite 22, 41 Rawson Street
Epping 2121, NSW

Australia
Tel: 61-2-9868-6733 Fax: 61-2-9868-6755

Microchip Technology Japan K.K.
Benex S-1 6F
3-18-20, Shinyokohama
Kohoku-Ku, Yokohama-shi
Kanagawa, 222-0033, Japan
Tel: 81-45-471- 6166 Fax: 81-45-471-6122

Rocky Mountain

China - Beijing

2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7966 Fax: 480-792-7456

Microchip Technology Consulting (Shanghai)
Co., Ltd., Beijing Liaison Office
Unit 915
Bei Hai Wan Tai Bldg.
No. 6 Chaoyangmen Beidajie
Beijing, 100027, No. China
Tel: 86-10-85282100 Fax: 86-10-85282104

Atlanta
500 Sugar Mill Road, Suite 200B
Atlanta, GA 30350
Tel: 770-640-0034 Fax: 770-640-0307


Boston
2 Lan Drive, Suite 120
Westford, MA 01886
Tel: 978-692-3848 Fax: 978-692-3821

Chicago
333 Pierce Road, Suite 180
Itasca, IL 60143
Tel: 630-285-0071 Fax: 630-285-0075

Dallas
4570 Westgrove Drive, Suite 160
Addison, TX 75001
Tel: 972-818-7423 Fax: 972-818-2924

Detroit
Tri-Atria Office Building
32255 Northwestern Highway, Suite 190
Farmington Hills, MI 48334
Tel: 248-538-2250 Fax: 248-538-2260

Kokomo
2767 S. Albright Road
Kokomo, Indiana 46902
Tel: 765-864-8360 Fax: 765-864-8387

Los Angeles
18201 Von Karman, Suite 1090
Irvine, CA 92612

Tel: 949-263-1888 Fax: 949-263-1338

China - Chengdu
Microchip Technology Consulting (Shanghai)
Co., Ltd., Chengdu Liaison Office
Rm. 2401, 24th Floor,
Ming Xing Financial Tower
No. 88 TIDU Street
Chengdu 610016, China
Tel: 86-28-6766200 Fax: 86-28-6766599

China - Fuzhou
Microchip Technology Consulting (Shanghai)
Co., Ltd., Fuzhou Liaison Office
Unit 28F, World Trade Plaza
No. 71 Wusi Road
Fuzhou 350001, China
Tel: 86-591-7503506 Fax: 86-591-7503521

China - Shanghai
Microchip Technology Consulting (Shanghai)
Co., Ltd.
Room 701, Bldg. B
Far East International Plaza
No. 317 Xian Xia Road
Shanghai, 200051
Tel: 86-21-6275-5700 Fax: 86-21-6275-5060

China - Shenzhen


150 Motor Parkway, Suite 202
Hauppauge, NY 11788
Tel: 631-273-5305 Fax: 631-273-5335

Microchip Technology Consulting (Shanghai)
Co., Ltd., Shenzhen Liaison Office
Rm. 1315, 13/F, Shenzhen Kerry Centre,
Renminnan Lu
Shenzhen 518001, China
Tel: 86-755-2350361 Fax: 86-755-2366086

San Jose

Hong Kong

Microchip Technology Inc.
2107 North First Street, Suite 590
San Jose, CA 95131
Tel: 408-436-7950 Fax: 408-436-7955

Microchip Technology Hongkong Ltd.
Unit 901-6, Tower 2, Metroplaza
223 Hing Fong Road
Kwai Fong, N.T., Hong Kong
Tel: 852-2401-1200 Fax: 852-2401-3431

New York

Toronto
6285 Northam Drive, Suite 108

Mississauga, Ontario L4V 1X5, Canada
Tel: 905-673-0699 Fax: 905-673-6509

India
Microchip Technology Inc.
India Liaison Office
Divyasree Chambers
1 Floor, Wing A (A3/A4)
No. 11, O’Shaugnessey Road
Bangalore, 560 025, India
Tel: 91-80-2290061 Fax: 91-80-2290062

Korea
Microchip Technology Korea
168-1, Youngbo Bldg. 3 Floor
Samsung-Dong, Kangnam-Ku
Seoul, Korea 135-882
Tel: 82-2-554-7200 Fax: 82-2-558-5934

Singapore
Microchip Technology Singapore Pte Ltd.
200 Middle Road
#07-02 Prime Centre
Singapore, 188980
Tel: 65-334-8870 Fax: 65-334-8850

Taiwan
Microchip Technology Taiwan
11F-3, No. 207
Tung Hua North Road

Taipei, 105, Taiwan
Tel: 886-2-2717-7175 Fax: 886-2-2545-0139

EUROPE
Denmark
Microchip Technology Nordic ApS
Regus Business Centre
Lautrup hoj 1-3
Ballerup DK-2750 Denmark
Tel: 45 4420 9895 Fax: 45 4420 9910

France
Microchip Technology SARL
Parc d’Activite du Moulin de Massy
43 Rue du Saule Trapu
Batiment A - ler Etage
91300 Massy, France
Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79

Germany
Microchip Technology GmbH
Gustav-Heinemann Ring 125
D-81739 Munich, Germany
Tel: 49-89-627-144 0 Fax: 49-89-627-144-44

Italy
Microchip Technology SRL
Centro Direzionale Colleoni
Palazzo Taurus 1 V. Le Colleoni 1
20041 Agrate Brianza

Milan, Italy
Tel: 39-039-65791-1 Fax: 39-039-6899883

United Kingdom
Arizona Microchip Technology Ltd.
505 Eskdale Road
Winnersh Triangle
Wokingham
Berkshire, England RG41 5TU
Tel: 44 118 921 5869 Fax: 44-118 921-5820
01/18/02

 2002 Microchip Technology Inc.



×