di3203.txt ;****************************************************************************************** ; ; LISTING 1 ; ; "Indicator has 'electronic lens,'" EDN, September 4, 2003, pg 92. ; ;****************************************************************************************** ADC-PWM3.asm Assembled with CASM08Z 01/29/2003 8:47:32 AM PAGE 1 1 ******************************************* 2 * The program converts ADC voltage to PWM * 3 * signal according to the given Table * 4 * PWM period = 10ms, fosc=5.75MHz * 5 ******************************************* 0000 6 $list 7 * CONSTANTS 0000 8 N equ 19T ;number of conversion points 0000 9 adrV equ FLASHend+1-N ;Vin table address 0000 10 adrPWL equ FLASHend+1-N-N ;PWL table address 11 * I/O PORTS 12 * pB7 -input ADC 13 * pD4 -output PWM 14 * VARIABLES 0080 15 org RAM 0080 16 PWL rmb 1 17 * INITIALIZATION F600 18 org FLASHstart F600 [01] 4F 19 init clrA F601 [03] 3F80 20 clr PWL F603 [03] 3F27 21 clr Tch0L F605 [04] 6EFF07 22 mov #$ff,ddrD ;set prtD as output F608 [03] 3F03 23 clr prtD F60A [04] 6E2620 24 mov #%00100110,TSC ;stop&clear Timer 25 ;set prescaler:64 F60D [04] 6E0023 26 mov #$00,tmodH ;set period = 10ms F610 [04] 6EE124 27 mov #$E1,tmodL ; by $00E1-->TMOD F613 [04] 1A3C 28 bset ADCO,ADSCR ;set continious ADC F615 [04] 6E011F 29 mov #01,Config1 ;disable COP F618 [04] 1B20 30 bclr TSTOP,TSC ;start TIMER F61A [04] 6E2025 31 mov #$20,Tsc0 ;disable PWM ADC-PWM3.asm Assembled with CASM08Z 01/29/2003 8:47:32 AM PAGE 2 F61D [01] 5F 32 MAIN clrx F61E [04] 6E073C 33 mov #%00000111,ADscr ;start ADC pB7 F621 [05] 0F3CFD 34 brclr coco,ADscr,* ;wait for ADC end F624 [03] B63D 35 lda ADR ;ADC data --> Acc F626 [04] 6E1F3C 36 mov #%00011111,ADscr ;stop ADC 37 *********************************************** F629 [04] D1FBED 38 Start cmp adrV,x ;Vmeasured <=adrV,x? F62C [03] 2307 39 bls PWset F62E [02] A313 40 cpx #N ;x>=N? F630 [03] 24EB 41 bhs Main F632 [01] 5C 42 incx ;x+1 F633 [03] 20F4 43 bra Start 44 ****************************************** F635 [01] 5D 45 PWset tstX F636 [03] 2712 46 beq NoOut F638 [05] 0F20FD 47 brclr TOF,TSC,* ;wait for TOF=1 F63B [04] 1F20 48 bclr TOF,TSC ;reset TOF F63D [03] 3F26 49 clr Tch0H ; 0 --> PWH F63F [04] D6FBDA 50 lda adrPWL,x ;PWL,x --> PWL F642 [03] B727 51 sta Tch0L F644 [04] 6E2A25 52 mov #%00101010,tsc0 ;start PWM F647 [03] CCF61D 53 jmp Main 54 ******************************************* F64A [04] 6E2025 55 NoOut mov #$20,Tsc0 ;stop PWM F64D [03] 20CE 56 bra Main 57 *************************************** 58 * Input Voltage and Output Pulse Width Tables FBED 59 org adrV FBED 0119324C 60 fcb $01,$19,$32,$4c,$65,$6b,$70,$75,$7a,$7f 656B7075 7A7F FBF7 84898E93 61 fcb $84,$89,$8e,$93,$99,$b2,$cc,$e5,$fa 99B2CCE5 FA FBDA 62 org adrPWL FBDA 00060B11 63 fcb $00,$06,$0B,$11,$16,$26,$36,$46,$55,$65 16263646 5565 FBE4 758595A4 64 fcb $75,$85,$95,$A4,$B4,$BF,$CB,$D6,$DF B4BFCBD6 DF 65 ************************************************ FFFE 66 org $fffe ;Initialization Vector FFFE F600 67 fdb init