gpasm-0.11.8 alpha lightpen.asm4-1-2004 00:50:13 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ; CPU configuration 00002 processor 16f84 00003 include 00001 LIST 00002 ; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc. 00136 LIST 002007 3FF2 00004 __config _HS_OSC & _WDT_OFF & _PWRTE_ON 00005 00006 ; variables 00007 00008 ; delay code is 4 cycles long, at 4Mz one instruction is 1us, so we can 00009 ; execute 250 4 cycle delay loops per ms 00010 00011 ; the first time we wait for just under 1ms (load the counter with 248) after 00012 ; activating the servo. then we use the position value to set the delay length 00013 ; (in 4us increments) when the delay finishes, we activate the servo. the 00014 ; result is a 1-2 ms pulse corresponding to the position variable 00015 00016 ; the servo needs updating every 20ms or so 00017 0000000C 00018 counter EQU H'0c' ; servo delay counter register 0000000D 00019 position EQU H'0d' ; servo position register 00000001 00020 outpin EQU H'01' ; servo i/o pin 00000002 00021 outpin2 EQU H'02' 00000010 00022 innerdelay EQU H'10' ; delay for random positioning 00000011 00023 temp EQU H'11' 00000012 00024 ping EQU H'12' 00025 0000 00026 main: 0000 3000 00027 movlw B'00000000' Warning [224] : Use of this instruction is not recommended. 0001 0065 00028 tris PORTA ; init port A as output 0002 30FF 00029 movlw B'11111111' Warning [224] : Use of this instruction is not recommended. 0003 0066 00030 tris PORTB ; init port B as input 00031 0004 3000 00032 movlw D'00' ; init variables 0005 008C 00033 movwf counter 0006 008D 00034 movwf position 00035 0007 00036 start: 0007 1485 00037 bsf PORTA,outpin ; activate servo output 0008 1105 00038 bcf PORTA,outpin2 0009 080D 00039 movf position,0 ; load w with servo position 000A 008C 00040 movwf counter ; and store in Counter for next delay 000B 201E 00041 call delay ; keep servo active for position delay 00042 00043 ; calculate how long the second delay needs to be 000C 30FF 00044 movlw D'255' 000D 0091 00045 movwf temp 000E 080D 00046 movf position,0 000F 0211 00047 subwf temp,0 0010 008C 00048 movwf counter 00049 gpasm-0.11.8 alpha lightpen.asm4-1-2004 00:50:13 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0011 1085 00050 bcf PORTA,outpin ; deactivate servo output 0012 1505 00051 bsf PORTA,outpin2 0013 201E 00052 call delay 00053 0014 1C12 00054 btfss ping,0 ; if ping is set, incr 0015 2818 00055 goto decpos ; otherwise decr 0016 0A8D 00056 incf position,1 ; inc! 0017 2819 00057 goto endpos ; skip the decr 0018 00058 decpos: 0018 038D 00059 decf position,1 ; decr! 0019 00060 endpos: 0019 300D 00061 movlw position ; load position 001A 1D03 00062 btfss STATUS,Z ; .. and test for zero 001B 2807 00063 goto start 001C 0992 00064 comf ping,1 001D 2807 00065 goto start 00066 001E 00067 delay: 001E 3037 00068 movlw D'55' 001F 0090 00069 movwf innerdelay 0020 00070 inner: 0020 0000 00071 nop ; pad loop 0021 0B90 00072 decfsz innerdelay,f ; inner loop 0022 2820 00073 goto inner 00074 0023 0B8C 00075 decfsz counter,f ; counter=counter-1 0024 281E 00076 goto delay 0025 0008 00077 return gpasm-0.11.8 alpha lightpen.asm4-1-2004 00:50:13 PAGE 3 SYMBOL TABLE LABEL VALUE C 00000000 DC 00000001 EEADR 00000009 EECON1 00000088 EECON2 00000089 EEDATA 00000008 EEIE 00000006 EEIF 00000004 F 00000001 FSR 00000004 GIE 00000007 INDF 00000000 INTCON 0000000B INTE 00000004 INTEDG 00000006 INTF 00000001 IRP 00000007 NOT_PD 00000003 NOT_RBPU 00000007 NOT_TO 00000004 OPTION_REG 00000081 PCL 00000002 PCLATH 0000000A PORTA 00000005 PORTB 00000006 PS0 00000000 PS1 00000001 PS2 00000002 PSA 00000003 RBIE 00000003 RBIF 00000000 RD 00000000 RP0 00000005 RP1 00000006 STATUS 00000003 T0CS 00000005 T0IE 00000005 T0IF 00000002 T0SE 00000004 TMR0 00000001 TRISA 00000085 TRISB 00000086 W 00000000 WR 00000001 WREN 00000002 WRERR 00000003 Z 00000002 _CP_OFF 00003FFF _CP_ON 0000000F _HS_OSC 00003FFE _LP_OSC 00003FFC _PWRTE_OFF 00003FFF _PWRTE_ON 00003FF7 gpasm-0.11.8 alpha lightpen.asm4-1-2004 00:50:13 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _XT_OSC 00003FFD __16F84 00000001 counter 0000000C decpos 00000018 delay 0000001E endpos 00000019 inner 00000020 innerdelay 00000010 main 00000000 outpin 00000001 outpin2 00000002 ping 00000012 position 0000000D start 00000007 temp 00000011 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXX---------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 39 Errors : 0 Warnings : 2 reported, 0 suppressed Messages : 0 reported, 0 suppressed