Part Number Hot Search : 
RN1104 ARJ2003 ISL85412 C3121 CXA13 ADG411TQ LC86343 4HC404
Product Description
Full Text Search
 

To Download AN20 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  application note 1 of 10 www.xicor.com june, 2000 AN20 interfacing the x9241 xdcps to 8051 microcontrollers by applications staff, june 2000 the x9241 has a variety of different instructions that provide ?xibility to the designer. additionally, the nonvolatile nature of the device allows for stored wiper positions that can be retrieved after power cycles. the following code implements all of the available x9241 instructions using a standard bi-directional bus protocol. although the routines occupy less than 300 bytes of program memory, designers who won't need to imple- ment all of the x9241 instructions can shorten the code by removing any unnecessary routines. however, this will necessitate the reassembly of the code. for those instructions which program the nonvolatile data registers (xfr_wcr, gxfr_wcr, and write_dr), acknowledge polling has been imple- mented to determine an early completion of the internal write cycle. although this is automatically handled by the routines, a word or two regarding the procedure is in order. after issuing a start condition, the master sends a slave address and receives an acknowledge. it then issues an instruction byte to the x9241 and again receives an acknowledge. if necessary, it now transmits the data byte and receives a ?al acknowledge. the master must then initiate a stop condition which will cause the x9241 to begin an internal write cycle. the x9241 pins go high impedance until this internal cycle is complete. the master can now begin acknowledge polling by successively sending start conditions followed by ?ummy?instructions. when the x9241 ?ally answers with an acknowledge, the internal write cycle has been completed and the master must initiate a stop condition. after the next start condition, the x9241 is ready to receive further instructions. in the code listing, an assumption was made that the code would execute upon a reset of the microcontroller. the code was also loaded into low memory, however this can be changed with an org assembler directive. a simple main program to exercise these routines is included on the next page. in this listing, the commands cause an x9241 (at a3a2a1a0 = 0000) to be accessed and the wcr of xdcp #2 to be rewritten with the value 43 (for wiper tap position #43). then a 15 pulse decre- ment of the wiper tap is initiated, causing the selected wcr to be reduced to the value 28 (for wiper tap posi- tion #28). the issuing of other commands follows the same general procedure. in figure 1, a representative hardware connection between the x9241 and an 8051 family microcontroller is shown. the pull-up resistors on the sda and scl lines are determined by the total capacitance of all of the devices connected to the bus, which is about 18pf in this case, however these may not be necessary since i/o port pins on 8051 family devices have internal pull-ups.
2 of 10 AN20 application note www.xicor.com june, 2000 code listing 1: sample main code listing for using the following interface routines main: mov addr_byte,#01010000b ;* load slave address byte mov id,#00001000b ;* load id byte (eepot #2) mov command,#4 ;* write to wcr mov data_byte,#00101011b ;* set d5d4d3d2d1d0 = 101011 call interpret mov id,#00001000b ;* reload id byte (eepot #2) mov pulses,#00001111b ;* dec for 15 pulses mov command,#32 ;* increment/decrement wiper call interpret code listing 2: 80c31 microcontroller routines for manipulating an x9241 1 ;*********************************************************** 2 ;* 3 ;* 80c31 microcontroller routines for manipulating an x9241 4 ;* quad xdcp 5 ;* 6 ;* (c) xicor inc. 1993 7 ;* ghc iv 8 ;*********************************************************** 0090 9 scl bit p1.0 ;* 80c31 pin used as scl 0091 10 sda bit p1.1 ;* 80c31 pin used as sda reg 11 temp equ r1 ;* scratch register reg 12 count equ r2 ;* loop counting register ea/ vp 31 x1 19 x2 18 reset 9 int0 12 int1 13 t0 14 t1 15 p1 . 0 1 p1 . 1 2 p1 . 2 3 p1 . 3 4 p1 . 4 5 p1 . 5 6 p1 . 6 7 p1 . 7 8 p0 . 0 39 p0 . 1 38 p0 . 2 37 p0 . 3 36 p0 . 4 35 p0 . 5 34 p0 . 6 33 p0 . 7 32 p2 . 0 21 p2 . 1 22 p2 . 2 23 p2 . 3 24 p2 . 4 25 p2 . 5 26 p2 . 6 27 p2 . 7 28 rd 17 wr 16 psen 29 al e/ p 30 txd 11 rxd 10 u2 80c31 +5v scl 14 sda 9 a0 4 a1 16 a2 5 a3 15 vh1 8 vw1 6 vh0 3 vw0 1 vl 0 2 vl 1 7 vh2 11 vw2 13 vl 2 12 vh3 17 vw3 19 vl 3 18 u1 x9241 figure 1. typical connection between an 80c31 and an x9241 (with a3a2a1a0 = 0000)
3 of 10 AN20 application note www.xicor.com june, 2000 reg 13 pulses equ r3 ;* bits -> dir x###### (# = 1 or 0) reg 14 command equ r4 ;* instruction (i.e. 0,4,8,12,16,...) reg 15 id equ r5 ;* bits -> 0 0 0 0 p1 p0 r1 r0 reg 16 addr_byte equ r6 ;* bits -> 0 1 0 1 a3 a2 a1 a0 reg 17 data_byte equ r7 ;* bits -> cm dw d5 d4 d3 d2 d1 d0 18 ;********************************************************* 19 ;* 20 ;* insert a "jump to main" instruction into 80c31 reset 21 ;* vector position 22 ;* 23 ;********************************************************* 0000 24 org 0000h ;* reset vector handler 25 ;* at this address 0000 02 01 2c 26 jmp main 27 ;********************************************************* 28 ;* 29 ;* name: interpret 30 ;* function: determines which x9241 instruction is issued, 31 ;* then executes 32 ;* inputs: command 33 ;* outputs: none 34 ;* calls: read wcr, read_dr, write_wcr, write_dr, xfr_dr, 35 ;* xfr_wcr, gxfr_dr, gxfr_wcr,inc_wiper 36 ;* affected: dptr,a 37 ;* 38 ;********************************************************* 0003 90 00 08 39 interpret: mov dptr,#first ;* jmp base address 0006 ec 40 mov a,command ;* jmp offset 0007 73 41 jmp @a+dptr ;* jump to instruction 42 ;* handler 0008 12 00 2c 43 first: call read_wcr ;* command #0 000b 22 44 ret 000c 12 00 37 45 call write_wcr ;* command #4 000f 22 46 ret 0010 12 00 42 47 call read_dr ;* command #8 0013 22 48 ret 0014 12 00 4d 49 call write_dr ;* command #12 0017 22 50 ret 0018 12 00 58 51 call xfr_dr ;* command #16 001b 22 52 ret 001c 12 00 63 53 call xfr_wcr ;* command #20 001f 22 54 ret 0020 12 00 6e 55 call gxfr_dr ;* command #24 0023 22 56 ret 0024 12 00 79 57 call gxfr_wcr ;* command #28 0027 22 58 ret 0028 12 00 84 59 call inc_wiper ;* command #32 002b 22 60 ret 61 ;********************************************************* 62 ;*
4 of 10 AN20 application note www.xicor.com june, 2000 63 ;* the following routines handle each x9241 instructions. 64 ;* these are called by the interpret routine and are 65 ;* straight forward 66 ;* 67 ;* read_wcr - reads a wcr and returns its' value in 68 ;* data_byte 69 ;* write_wcr - writes the value in data_byte to a wcr 70 ;* read_dr - reads a data register and returns its' value 71 ;* in data_byte 72 ;* write_dr - writes the value in data_byte to a data 73 ;* register 74 ;* xfr_dr - transfers the value in a data register to its' 75 ;* wcr 76 ;* xfr_wcr - transfers the value in a wcr to one of its' 77 ;* data registers 78 ;* gxfr_dr - global transfer of like data registers to 79 ;* their wcrs 80 ;* gxfr_wcr - global transfer of wcrs to their like data 81 ;* registers 82 ;* inc_wiper - single step increment/decrement of wiper 83 ;* position for wcr 84 ;* 85 ;* function: appends bits p1,p0,r1,r0 to the appropriate 86 ;* instruction code & passes the instruction byte to the 87 ;* instruction generator 88 ;* inputs: id 89 ;* outputs: none 90 ;* calls: instr_gen 91 ;* affected: id,a,dptr 92 ;* 93 ;********************************************************* 002c ed 94 read_wcr: mov a,id ;* get bits p1 p0 x x 002d 44 90 95 orl a,#090h ;* append to read_wcr 96 ;* instruction code 002f fd 97 mov id,a ;* save the result 0030 90 00 b2 98 mov dptr,#case1 ;* jmp base address for this 100 ;* instruction 0033 12 00 8f 101 call instr_gen 0036 22 102 ret 0037 ed 103 write_wcr: mov a,id ;* get bits p1 p0 x x 0038 44 a0 104 orl a,#0a0h ;* append to write_wcr 105 ;* instruction code 003a fd 106 mov id,a ;* save the result 003b 90 00 ab 107 mov dptr,#case2 ;* jmp base address for this 108 ;* instruction 003e 12 00 8f 109 call instr_gen 0041 22 110 ret 0042 ed 111 read_dr: mov a,id ;* get bits p1 p0 r1 r0 0043 44 b0 112 orl a,#0b0h ;* append to read_dr 113 ;* instruction code 0045 fd 114 mov id,a ;* save the result 0046 90 00 b2 115 mov dptr,#case1 ;* jmp base address for this
5 of 10 AN20 application note www.xicor.com june, 2000 116 ;* instruction 0049 12 00 8f 117 call instr_gen 004c 22 118 ret 004d ed 119 write_dr: mov a,id ;* get bits p1 p0 r1 r0 004e 44 c0 120 orl a,#0c0h ;* append to write_dr 121 ;* instruction code 0050 fd 122 mov id, a ;* save the result 0051 90 00 b8 123 mov dptr,#case3 ;* jmp base address for this 124 ;* instruction 0054 12 00 8f 125 call instr_gen 0057 22 126 ret 127 0058 ed 128 xfr_dr: mov a,id ;* get bits p1 p0 r1 r0 0059 44 d0 127 orl a,#0d0h ;* append to xfr_dr 128 ;* instruction code 005b fd 129 mov id, a ;* save the result 005c 90 00 a8 129 mov dptr,#case4 ;* jmp base address for this 130 ;* instruction 005f 12 00 8f 131 call instr_gen 0062 22 132 ret 0063 ed 133 xfr_wcr: mov a,id ;* get bits p1 p0 r1 r0 0064 44 e0 134 orl a,#0e0h ;* append to xfr_wcr 135 ;* instruction code 0066 fd 136 mov id, a ;* save the result 0067 90 00 c5 137 mov dptr,#case5 ;* jmp base address for this 138 ;* instruction 006a 12 00 8f 139 call instr_gen 006d 22 140 ret 006e ed 141 gxfr_dr: mov a,id ;* get bits x x r1 r0 006f 44 10 142 orl a,#010h ;* append to gxfr_dr 143 ;* instruction code 0071 fd 144 mov id, a ;* save the result 0072 90 00 a8 145 mov dptr,#case4 ;* jmp base address for this 146 ;* instruction 0075 12 00 8f 147 call instr_gen 0078 22 148 ret 0079 ed 149 gxfr_wcr: mov a,id ;* get bits x x r1 r0 007a 44 80 150 orl a,#080h ;* append to gxfr_wcr 151 ;* instruction code 007c fd 152 mov id, a ;* save the result 007d 90 00 c5 153 mov dptr,#case5 ;* jmp base address for 154 ;* this instruction 0080 12 00 8f 155 call instr_gen 0083 22 156 ret 0084 ed 157 inc_wiper: mov a,id ;* get bits p1 p0 x x 0085 44 20 158 orl a,#020h ;* append to inc_wiper 159 ;* instruction code 0087 fd 160 mov id,a ;* save the result 0088 90 00 9c 161 mov dptr,#case6 ;* jmp base address for 162 ;* this instruction 008b 12 00 8f 163 call instr_gen 008e 22 164 ret 165 ;********************************************************* 166 ;*
6 of 10 AN20 application note www.xicor.com june, 2000 167 ;* name: instr_gen (instruction generator) 168 ;* function: issues appropriate i2c protocol for each x9241 169 ;* instruction 170 ;* inputs: addr_byte,id,pulses,dptr,data_byte 171 ;* outputs: data_byte 172 ;* calls: start_cond, stop_cond, send_byte, send_bit, 173 ;* get_byte, polling 174 ;* affected: data_byte,a,count 175 ;* 176 ;********************************************************* 008f 12 01 04 177 instr_gen: call start_cond ;* issue an i2c start 178 ;* condition 0092 ee 179 mov a,addr_byte ;* send x9241 address byte 0093 12 00 cf 180 call send_byte 0096 ed 181 mov a,id ;* send x9241 instruction 182 ;* byte 0097 12 00 cf 183 call send_byte 009a e4 184 clr a ;* jmp offset (don't need 185 ;* an offset) 009b 73 186 jmp @ a +dptr ;* jump to various 187 ;* instruction cases 009c eb 188 case6: mov a,pulses ;* a <- bits dir x d5 d4 d3 189 ;* d2 d1 d0 009d 54 3f 190 anl a,#00111111b ;* a <- bits 0 0 d5 d4 d3 191 ;* d2 d1 d0 009f f9 192 mov count, a ;* save as the number of 193 ;* pulses 00a0 eb 194 mov a,pulses 00a1 54 80 195 anl a,#10000000b ;* a <- bits dir 0 0 0 0 0 196 ;* 0 0 00a3 12 00 e1 197 wiper_loop: call send_bit ;* send the bit (a single 198 ;* pulse) 00a6 d9 fb [00a3] 199 djnz count,wiper_loop ;* continue until all 200 ;* pulses are sent 00a8 02 00 cb 201 case4: jmp stop_gen ;* if program gets here, 202 ;* then it's done 00ab ef 203 case2: mov a,data_byte ;* send x9241 data byte 00ac 12 00 cf 204 call send_byte 00af 02 00 cb 205 jmp stop_gen 00b2 12 00 f6 206 case1: call get_byte ;* receive x9241 data byte 00b5 02 00 cb 207 jmp stop_gen 00b8 ef 208 case3: mov a,data_byte ;* send x9241 data byte 00b9 12 00 cf 209 call send_byte 00bc 12 01 15 210 call stop_cond ;* issue a stop condition 00bf 12 01 24 211 call polling ;* begin acknowledge polling 00c2 02 00 cb 212 jmp stop_gen 00c5 12 01 15 213 case5: call stop_cond ;* issue a stop condition 00c8 12 01 24 214 call polling ;* begin acknowledge polling 00cb 12 01 15 215 stop_gen: call stop_cond ;* i2c transmission over! 00ce 22 216 ret 217 ;********************************************************* 218 ;* 219 ;* name: send_byte
7 of 10 AN20 application note www.xicor.com june, 2000 220 ;* function: sends 8 bits (from msb to lsb) to sda and 221 ;* reads 1 bit from sda 222 ;* inputs: a 223 ;* outputs: none 224 ;* calls: send_bit,get_bit 225 ;* affected: count,temp,a 226 ;* 227 ;********************************************************* 00cf 79 08 228 send_byte: mov count,#8 ;* set loop for 8 229 ;* repetitions 00d1 f8 230 mov temp,a ;* store as shifted byte (no 231 ;* shift) 00d2 e8 232 bit_loop: mov a,temp ;* retrieve last saved 233 ;* shifted byte 00d3 54 80 234 anl a,#10000000b ;* mask for msb (most 235 ;* significant bit) 00d5 12 00 e1 236 call send_bit ;* place this bit on sda 00d8 e8 237 next_bit: mov a,temp ;* retrieve last saved 238 ;* shifted byte 00d9 23 239 rl a ;* rotate all bits 1 240 ;* position left 00da f8 241 mov temp,a ;* store this updated 242 ;* shifted byte 00db d9 f5 [00d2] 243 djnz count,bit_loop 00dd 12 00 eb 244 call clock ;* when done all 8 bits, 245 ;* read sda line 00e0 22 246 ret 247 ;********************************************************* 248 ;* 249 ;* name: send_bit 250 ;* function: places a bit on sda and initiates a clock 251 ;* pulse on scl 252 ;* inputs: a 253 ;* outputs: none 254 ;* calls: clock 255 ;* affected: sda 256 ;* 257 ;********************************************************* 00e1 c2 91 258 send_bit: clr sda ;* pull sda low 00e3 60 02 [00e7] 259 jz sent_zero ;* should sda really be low? 00e5 d2 91 260 setb sda ;* if not, pull sda high 00e7 12 00 eb 261 sent_zero: call clock ;* initiate a clock pulse 00ea 22 262 ret 263 ;********************************************************* 264 ;* 265 ;* name: clock 266 ;* function: issues a low-high-low clock pulse of 267 ;* sufficient duration & reads sda during the high phase, 268 ;* just in case it's needed 269 ;* inputs: none 270 ;* outputs: c
8 of 10 AN20 application note www.xicor.com june, 2000 271 ;* calls: none 272 ;* affected: scl,c 273 ;* 274 ;********************************************************* 00eb 00 275 clock: nop ;* let sda set-up 00ec d2 90 276 setb scl ;* pull scl high and hold 00ee 00 277 nop 00ef 00 278 nop 00f0 00 279 nop 00f1 a2 91 280 mov c,sda ;* move sda bit into carry flag 00f3 c2 90 281 clr scl ;* pull scl low 00f5 22 282 ret 283 ;********************************************************* 284 ;* 285 ;* name: get_byte 286 ;* function: receives 8 bits from sda (msb to lsb) and 287 ;* sends 1 bit to sda 288 ;* inputs: none 289 ;* outputs: data_byte 290 ;* calls: clock,send_bit 291 ;* affected: count,sda,a,data_byte 292 ;* 293 ;********************************************************* 00f6 d2 91 294 get_byte: setb sda ;* receiver shouldn't drive sda 295 ;* low 00f8 79 08 296 mov count,#8 ;* set loop counter to 8 297 ;* repetitions 00fa 11 eb [00eb] 298 get_loop: call clock ;* clock in the current bit 00fc 33 299 rlc a ;* reconstruct byte using left 300 ;* shifts 00fd d9 fb [00fa] 301 djnz count,get_loop 00ff ff 302 mov data_byte,a ;* store retrieved byte 303 ;* for user 0100 e4 304 clr a ;* a <- low (sending a 0) 0101 11 e1 [00e1] 305 call end_bit ;* send an acknowledge 0103 22 306 ret 307 ;******************************************************** 308 ;* 309 ;* name: start_cond (start condition) 310 ;* function: issues an i2c bus start condition 311 ;* inputs: none 312 ;* outputs: none 313 ;* calls: none 314 ;* affected: sda,scl 315 ;* 316 ;******************************************************** 0104 d2 91 317 start_cond: setb sda ;* pull sda high and allow set-up 0106 d2 90 318 setb scl ;* pull scl high and hold 0108 00 319 nop 0109 00 320 nop
9 of 10 AN20 application note www.xicor.com june, 2000 010a 00 321 nop 010b 00 322 nop 010c c2 91 323 clr sda ;* pull sda low (scl=high) and hold 010e 00 324 nop 010f 00 325 nop 0110 00 326 nop 0111 00 327 nop 0112 c2 90 328 clr scl ;* complete clock pulse 0114 22 329 ret 330 ;******************************************************** 331 ;* 332 ;* name: stop_cond (stop condition) 333 ;* function: issues an i2c bus stop condition 334 ;* inputs: none 335 ;* outputs: none 336 ;* calls: none 337 ;* affected: sda,scl 338 ;* 339 ;******************************************************** 0115 c2 91 340 stop_cond: clr sda ;* pull sda low and hold 0117 d2 90 341 setb scl ;* pull scl high and hold 0119 00 342 nop 011a 00 343 nop 011b 00 344 nop 011c 00 345 nop 011d d2 91 346 setb sda ;* pull sda high (scl=high) 011f 22 347 ret 348 ;******************************************************** 349 ;* 350 ;* name: ack_send (send acknowledge) 351 ;* function: sends an acknowledge bit to complete sda line 352 ;* data reads 353 ;* inputs: none 354 ;* outputs: none 355 ;* calls: send_bit 356 ;* affected: a 357 ;* 358 ;******************************************************** 0120 e4 359 ack_send: clr a ;* a <- low (sending a 0) 0121 11 e1 [00e1] 360 call send_bit ;* send the bit! 0123 22 361 ret 362 ;********************************************************* 363 ;* 364 ;* name: polling (acknowledge polling for xfr_wcr, 365 ;* write_dr, gxfr_wcr) 366 ;* function: sends dummy commands to x9241 during an 367 ;* internal write cycle so that the end of the cycle is 368 ;* marked by an acknowledge 369 ;* inputs: addr_byte
10 of 10 AN20 application note www.xicor.com june, 2000 370 ;* outputs: none 371 ;* calls: start_cond,send_byte 372 ;* affected: c 373 ;* 374 ;********************************************************* 0124 31 04 [0104] 375 polling: call start_cond ;* reestablish i2c protocol 0126 ee 376 mov a,addr_byte ;* attempt to send a dummy 377 ;* command 0127 11 cf [00cf] 378 again: call send_byte 0129 40 f9 [0124] 379 jc polling ;* if c=1, then there was no 380 ;* acknowledge 012b 22 381 ret 382 ;********************************************************* 383 ;* 384 ;* put main program here... 385 ;* 386 ;********************************************************* 012c 387 main: assembly end, errors:0, last code address:012bh, total bytes:299


▲Up To Search▲   

 
Price & Availability of AN20

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X