BERBAGILAH DALAM HAL KEBAIKAN TERMASUK ILMU WALAU CUMA SETITIK....

11/02/2014

Program Motor Stepper Bipolar


Subroutin programnya dalam bahasa assembler :
;CodeVisionAVR C Compiler V2.04.4a Advanced
; Test Motor stepper Bepoalar
;Chip type                : ATmega16
;Program type             : Application
;Clock frequency          : 11.059200 MHz
;Memory model             : Small
;Optimize for             : Size
;(s)printf features       : int, width
;(s)scanf features        : int, width
;External RAM size        : 0
;Data Stack size          : 256 byte(s)
;Heap size                : 0 byte(s)
;Promote 'char' to 'int'  : Yes
;'char' is unsigned       : Yes
;8 bit enums              : Yes
;global 'const' stored in FLASH: No
;Enhanced core instructions    : On
;Smart register allocation     : On
;Automatic register allocation : On

            #pragma AVRPART ADMIN PART_NAME ATmega16
            #pragma AVRPART MEMORY PROG_FLASH 16384
            #pragma AVRPART MEMORY EEPROM 512
            #pragma AVRPART MEMORY INT_SRAM SIZE 1024
            #pragma AVRPART MEMORY INT_SRAM START_ADDR 0x60

            .LISTMAC
            .EQU UDRE=0x5
            .EQU RXC=0x7
            .EQU USR=0xB
            .EQU UDR=0xC
            .EQU SPSR=0xE
            .EQU SPDR=0xF
            .EQU EERE=0x0
            .EQU EEWE=0x1
            .EQU EEMWE=0x2
            .EQU EECR=0x1C
            .EQU EEDR=0x1D
            .EQU EEARL=0x1E
            .EQU EEARH=0x1F
            .EQU WDTCR=0x21
            .EQU MCUCR=0x35
            .EQU GICR=0x3B
            .EQU SPL=0x3D
            .EQU SPH=0x3E
            .EQU SREG=0x3F

            .DEF R0X0=R0
            .DEF R0X1=R1
            .DEF R0X2=R2
            .DEF R0X3=R3
            .DEF R0X4=R4
            .DEF R0X5=R5
            .DEF R0X6=R6
            .DEF R0X7=R7
            .DEF R0X8=R8
            .DEF R0X9=R9
            .DEF R0XA=R10
            .DEF R0XB=R11
            .DEF R0XC=R12
            .DEF R0XD=R13
            .DEF R0XE=R14
            .DEF R0XF=R15
            .DEF R0X10=R16
            .DEF R0X11=R17
            .DEF R0X12=R18
            .DEF R0X13=R19
            .DEF R0X14=R20
            .DEF R0X15=R21
            .DEF R0X16=R22
            .DEF R0X17=R23
            .DEF R0X18=R24
            .DEF R0X19=R25
            .DEF R0X1A=R26
            .DEF R0X1B=R27
            .DEF R0X1C=R28
            .DEF R0X1D=R29
            .DEF R0X1E=R30
            .DEF R0X1F=R31

            .MACRO __CPD1N
            CPI  R30,LOW(@0)
            LDI  R26,HIGH(@0)
            CPC  R31,R26
            LDI  R26,BYTE3(@0)
            CPC  R22,R26
            LDI  R26,BYTE4(@0)
            CPC  R23,R26
            .ENDM

            .MACRO __CPD2N
            CPI  R26,LOW(@0)
            LDI  R30,HIGH(@0)
            CPC  R27,R30
            LDI  R30,BYTE3(@0)
            CPC  R24,R30
            LDI  R30,BYTE4(@0)
            CPC  R25,R30
            .ENDM

            .MACRO __CPWRR
            CP   R@0,R@2
            CPC  R@1,R@3
            .ENDM

            .MACRO __CPWRN
            CPI  R@0,LOW(@2)
            LDI  R30,HIGH(@2)
            CPC  R@1,R30
            .ENDM

            .MACRO __ADDB1MN
            SUBI R30,LOW(-@0-(@1))
            .ENDM

            .MACRO __ADDB2MN
            SUBI R26,LOW(-@0-(@1))
            .ENDM

            .MACRO __ADDW1MN
            SUBI R30,LOW(-@0-(@1))
            SBCI R31,HIGH(-@0-(@1))
            .ENDM

            .MACRO __ADDW2MN
            SUBI R26,LOW(-@0-(@1))
            SBCI R27,HIGH(-@0-(@1))
            .ENDM

            .MACRO __ADDW1FN
            SUBI R30,LOW(-2*@0-(@1))
            SBCI R31,HIGH(-2*@0-(@1))
            .ENDM

            .MACRO __ADDD1FN
            SUBI R30,LOW(-2*@0-(@1))
            SBCI R31,HIGH(-2*@0-(@1))
            SBCI R22,BYTE3(-2*@0-(@1))
            .ENDM

            .MACRO __ADDD1N
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            SBCI R22,BYTE3(-@0)
            SBCI R23,BYTE4(-@0)
            .ENDM

            .MACRO __ADDD2N
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            SBCI R24,BYTE3(-@0)
            SBCI R25,BYTE4(-@0)
            .ENDM

            .MACRO __SUBD1N
            SUBI R30,LOW(@0)
            SBCI R31,HIGH(@0)
            SBCI R22,BYTE3(@0)
            SBCI R23,BYTE4(@0)
            .ENDM

            .MACRO __SUBD2N
            SUBI R26,LOW(@0)
            SBCI R27,HIGH(@0)
            SBCI R24,BYTE3(@0)
            SBCI R25,BYTE4(@0)
            .ENDM

            .MACRO __ANDBMNN
            LDS  R30,@0+(@1)
            ANDI R30,LOW(@2)
            STS  @0+(@1),R30
            .ENDM

            .MACRO __ANDWMNN
            LDS  R30,@0+(@1)
            ANDI R30,LOW(@2)
            STS  @0+(@1),R30
            LDS  R30,@0+(@1)+1
            ANDI R30,HIGH(@2)
            STS  @0+(@1)+1,R30
            .ENDM

            .MACRO __ANDD1N
            ANDI R30,LOW(@0)
            ANDI R31,HIGH(@0)
            ANDI R22,BYTE3(@0)
            ANDI R23,BYTE4(@0)
            .ENDM

            .MACRO __ANDD2N
            ANDI R26,LOW(@0)
            ANDI R27,HIGH(@0)
            ANDI R24,BYTE3(@0)
            ANDI R25,BYTE4(@0)
            .ENDM

            .MACRO __ORBMNN
            LDS  R30,@0+(@1)
            ORI  R30,LOW(@2)
            STS  @0+(@1),R30
            .ENDM

            .MACRO __ORWMNN
            LDS  R30,@0+(@1)
            ORI  R30,LOW(@2)
            STS  @0+(@1),R30
            LDS  R30,@0+(@1)+1
            ORI  R30,HIGH(@2)
            STS  @0+(@1)+1,R30
            .ENDM

            .MACRO __ORD1N
            ORI  R30,LOW(@0)
            ORI  R31,HIGH(@0)
            ORI  R22,BYTE3(@0)
            ORI  R23,BYTE4(@0)
            .ENDM

            .MACRO __ORD2N
            ORI  R26,LOW(@0)
            ORI  R27,HIGH(@0)
            ORI  R24,BYTE3(@0)
            ORI  R25,BYTE4(@0)
            .ENDM

            .MACRO __DELAY_USB
            LDI  R24,LOW(@0)
__DELAY_USB_LOOP:
            DEC  R24
            BRNE __DELAY_USB_LOOP
            .ENDM

            .MACRO __DELAY_USW
            LDI  R24,LOW(@0)
            LDI  R25,HIGH(@0)
__DELAY_USW_LOOP:
            SBIW R24,1
            BRNE __DELAY_USW_LOOP
            .ENDM

            .MACRO __GETD1S
            LDD  R30,Y+@0
            LDD  R31,Y+@0+1
            LDD  R22,Y+@0+2
            LDD  R23,Y+@0+3
            .ENDM

            .MACRO __GETD2S
            LDD  R26,Y+@0
            LDD  R27,Y+@0+1
            LDD  R24,Y+@0+2
            LDD  R25,Y+@0+3
            .ENDM

            .MACRO __PUTD1S
            STD  Y+@0,R30
            STD  Y+@0+1,R31
            STD  Y+@0+2,R22
            STD  Y+@0+3,R23
            .ENDM

            .MACRO __PUTD2S
            STD  Y+@0,R26
            STD  Y+@0+1,R27
            STD  Y+@0+2,R24
            STD  Y+@0+3,R25
            .ENDM

            .MACRO __PUTDZ2
            STD  Z+@0,R26
            STD  Z+@0+1,R27
            STD  Z+@0+2,R24
            STD  Z+@0+3,R25
            .ENDM

            .MACRO __CLRD1S
            STD  Y+@0,R30
            STD  Y+@0+1,R30
            STD  Y+@0+2,R30
            STD  Y+@0+3,R30
            .ENDM

            .MACRO __POINTB1MN
            LDI  R30,LOW(@0+(@1))
            .ENDM

            .MACRO __POINTW1MN
            LDI  R30,LOW(@0+(@1))
            LDI  R31,HIGH(@0+(@1))
            .ENDM

            .MACRO __POINTD1M
            LDI  R30,LOW(@0)
            LDI  R31,HIGH(@0)
            LDI  R22,BYTE3(@0)
            LDI  R23,BYTE4(@0)
            .ENDM

            .MACRO __POINTW1FN
            LDI  R30,LOW(2*@0+(@1))
            LDI  R31,HIGH(2*@0+(@1))
            .ENDM

            .MACRO __POINTD1FN
            LDI  R30,LOW(2*@0+(@1))
            LDI  R31,HIGH(2*@0+(@1))
            LDI  R22,BYTE3(2*@0+(@1))
            LDI  R23,BYTE4(2*@0+(@1))
            .ENDM

            .MACRO __POINTB2MN
            LDI  R26,LOW(@0+(@1))
            .ENDM

            .MACRO __POINTW2MN
            LDI  R26,LOW(@0+(@1))
            LDI  R27,HIGH(@0+(@1))
            .ENDM

            .MACRO __POINTBRM
            LDI  R@0,LOW(@1)
            .ENDM

            .MACRO __POINTWRM
            LDI  R@0,LOW(@2)
            LDI  R@1,HIGH(@2)
            .ENDM

            .MACRO __POINTBRMN
            LDI  R@0,LOW(@1+(@2))
            .ENDM

            .MACRO __POINTWRMN
            LDI  R@0,LOW(@2+(@3))
            LDI  R@1,HIGH(@2+(@3))
            .ENDM

            .MACRO __POINTWRFN
            LDI  R@0,LOW(@2*2+(@3))
            LDI  R@1,HIGH(@2*2+(@3))
            .ENDM

            .MACRO __GETD1N
            LDI  R30,LOW(@0)
            LDI  R31,HIGH(@0)
            LDI  R22,BYTE3(@0)
            LDI  R23,BYTE4(@0)
            .ENDM

            .MACRO __GETD2N
            LDI  R26,LOW(@0)
            LDI  R27,HIGH(@0)
            LDI  R24,BYTE3(@0)
            LDI  R25,BYTE4(@0)
            .ENDM

            .MACRO __GETB1MN
            LDS  R30,@0+(@1)
            .ENDM

            .MACRO __GETB1HMN
            LDS  R31,@0+(@1)
            .ENDM

            .MACRO __GETW1MN
            LDS  R30,@0+(@1)
            LDS  R31,@0+(@1)+1
            .ENDM

            .MACRO __GETD1MN
            LDS  R30,@0+(@1)
            LDS  R31,@0+(@1)+1
            LDS  R22,@0+(@1)+2
            LDS  R23,@0+(@1)+3
            .ENDM

            .MACRO __GETBRMN
            LDS  R@0,@1+(@2)
            .ENDM

            .MACRO __GETWRMN
            LDS  R@0,@2+(@3)
            LDS  R@1,@2+(@3)+1
            .ENDM

            .MACRO __GETWRZ
            LDD  R@0,Z+@2
            LDD  R@1,Z+@2+1
            .ENDM

            .MACRO __GETD2Z
            LDD  R26,Z+@0
            LDD  R27,Z+@0+1
            LDD  R24,Z+@0+2
            LDD  R25,Z+@0+3
            .ENDM

            .MACRO __GETB2MN
            LDS  R26,@0+(@1)
            .ENDM

            .MACRO __GETW2MN
            LDS  R26,@0+(@1)
            LDS  R27,@0+(@1)+1
            .ENDM

            .MACRO __GETD2MN
            LDS  R26,@0+(@1)
            LDS  R27,@0+(@1)+1
            LDS  R24,@0+(@1)+2
            LDS  R25,@0+(@1)+3
            .ENDM

            .MACRO __PUTB1MN
            STS  @0+(@1),R30
            .ENDM

            .MACRO __PUTW1MN
            STS  @0+(@1),R30
            STS  @0+(@1)+1,R31
            .ENDM

            .MACRO __PUTD1MN
            STS  @0+(@1),R30
            STS  @0+(@1)+1,R31
            STS  @0+(@1)+2,R22
            STS  @0+(@1)+3,R23
            .ENDM

            .MACRO __PUTB1EN
            LDI  R26,LOW(@0+(@1))
            LDI  R27,HIGH(@0+(@1))
            CALL __EEPROMWRB
            .ENDM

            .MACRO __PUTW1EN
            LDI  R26,LOW(@0+(@1))
            LDI  R27,HIGH(@0+(@1))
            CALL __EEPROMWRW
            .ENDM

            .MACRO __PUTD1EN
            LDI  R26,LOW(@0+(@1))
            LDI  R27,HIGH(@0+(@1))
            CALL __EEPROMWRD
            .ENDM

            .MACRO __PUTBR0MN
            STS  @0+(@1),R0
            .ENDM

            .MACRO __PUTBMRN
            STS  @0+(@1),R@2
            .ENDM

            .MACRO __PUTWMRN
            STS  @0+(@1),R@2
            STS  @0+(@1)+1,R@3
            .ENDM

            .MACRO __PUTBZR
            STD  Z+@1,R@0
            .ENDM

            .MACRO __PUTWZR
            STD  Z+@2,R@0
            STD  Z+@2+1,R@1
            .ENDM

            .MACRO __GETW1R
            MOV  R30,R@0
            MOV  R31,R@1
            .ENDM

            .MACRO __GETW2R
            MOV  R26,R@0
            MOV  R27,R@1
            .ENDM

            .MACRO __GETWRN
            LDI  R@0,LOW(@2)
            LDI  R@1,HIGH(@2)
            .ENDM

            .MACRO __PUTW1R
            MOV  R@0,R30
            MOV  R@1,R31
            .ENDM

            .MACRO __PUTW2R
            MOV  R@0,R26
            MOV  R@1,R27
            .ENDM

            .MACRO __ADDWRN
            SUBI R@0,LOW(-@2)
            SBCI R@1,HIGH(-@2)
            .ENDM

            .MACRO __ADDWRR
            ADD  R@0,R@2
            ADC  R@1,R@3
            .ENDM

            .MACRO __SUBWRN
            SUBI R@0,LOW(@2)
            SBCI R@1,HIGH(@2)
            .ENDM

            .MACRO __SUBWRR
            SUB  R@0,R@2
            SBC  R@1,R@3
            .ENDM

            .MACRO __ANDWRN
            ANDI R@0,LOW(@2)
            ANDI R@1,HIGH(@2)
            .ENDM

            .MACRO __ANDWRR
            AND  R@0,R@2
            AND  R@1,R@3
            .ENDM

            .MACRO __ORWRN
            ORI  R@0,LOW(@2)
            ORI  R@1,HIGH(@2)
            .ENDM

            .MACRO __ORWRR
            OR   R@0,R@2
            OR   R@1,R@3
            .ENDM

            .MACRO __EORWRR
            EOR  R@0,R@2
            EOR  R@1,R@3
            .ENDM

            .MACRO __GETWRS
            LDD  R@0,Y+@2
            LDD  R@1,Y+@2+1
            .ENDM

            .MACRO __PUTBSR
            STD  Y+@1,R@0
            .ENDM

            .MACRO __PUTWSR
            STD  Y+@2,R@0
            STD  Y+@2+1,R@1
            .ENDM

            .MACRO __MOVEWRR
            MOV  R@0,R@2
            MOV  R@1,R@3
            .ENDM

            .MACRO __INWR
            IN   R@0,@2
            IN   R@1,@2+1
            .ENDM

            .MACRO __OUTWR
            OUT  @2+1,R@1
            OUT  @2,R@0
            .ENDM

            .MACRO __CALL1MN
            LDS  R30,@0+(@1)
            LDS  R31,@0+(@1)+1
            ICALL
            .ENDM

            .MACRO __CALL1FN
            LDI  R30,LOW(2*@0+(@1))
            LDI  R31,HIGH(2*@0+(@1))
            CALL __GETW1PF
            ICALL
            .ENDM

            .MACRO __CALL2EN
            LDI  R26,LOW(@0+(@1))
            LDI  R27,HIGH(@0+(@1))
            CALL __EEPROMRDW
            ICALL
            .ENDM

            .MACRO __GETW1STACK
            IN   R26,SPL
            IN   R27,SPH
            ADIW R26,@0+1
            LD   R30,X+
            LD   R31,X
            .ENDM

            .MACRO __GETD1STACK
            IN   R26,SPL
            IN   R27,SPH
            ADIW R26,@0+1
            LD   R30,X+
            LD   R31,X+
            LD   R22,X
            .ENDM

            .MACRO __NBST
            BST  R@0,@1
            IN   R30,SREG
            LDI  R31,0x40
            EOR  R30,R31
            OUT  SREG,R30
            .ENDM


            .MACRO __PUTB1SN
            LDD  R26,Y+@0
            LDD  R27,Y+@0+1
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X,R30
            .ENDM

            .MACRO __PUTW1SN
            LDD  R26,Y+@0
            LDD  R27,Y+@0+1
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1SN
            LDD  R26,Y+@0
            LDD  R27,Y+@0+1
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            CALL __PUTDP1
            .ENDM

            .MACRO __PUTB1SNS
            LDD  R26,Y+@0
            LDD  R27,Y+@0+1
            ADIW R26,@1
            ST   X,R30
            .ENDM

            .MACRO __PUTW1SNS
            LDD  R26,Y+@0
            LDD  R27,Y+@0+1
            ADIW R26,@1
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1SNS
            LDD  R26,Y+@0
            LDD  R27,Y+@0+1
            ADIW R26,@1
            CALL __PUTDP1
            .ENDM

            .MACRO __PUTB1PMN
            LDS  R26,@0
            LDS  R27,@0+1
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X,R30
            .ENDM

            .MACRO __PUTW1PMN
            LDS  R26,@0
            LDS  R27,@0+1
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1PMN
            LDS  R26,@0
            LDS  R27,@0+1
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            CALL __PUTDP1
            .ENDM

            .MACRO __PUTB1PMNS
            LDS  R26,@0
            LDS  R27,@0+1
            ADIW R26,@1
            ST   X,R30
            .ENDM

            .MACRO __PUTW1PMNS
            LDS  R26,@0
            LDS  R27,@0+1
            ADIW R26,@1
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1PMNS
            LDS  R26,@0
            LDS  R27,@0+1
            ADIW R26,@1
            CALL __PUTDP1
            .ENDM

            .MACRO __PUTB1RN
            MOVW R26,R@0
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X,R30
            .ENDM

            .MACRO __PUTW1RN
            MOVW R26,R@0
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1RN
            MOVW R26,R@0
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            CALL __PUTDP1
            .ENDM

            .MACRO __PUTB1RNS
            MOVW R26,R@0
            ADIW R26,@1
            ST   X,R30
            .ENDM

            .MACRO __PUTW1RNS
            MOVW R26,R@0
            ADIW R26,@1
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1RNS
            MOVW R26,R@0
            ADIW R26,@1
            CALL __PUTDP1
            .ENDM

            .MACRO __PUTB1RON
            MOV  R26,R@0
            MOV  R27,R@1
            SUBI R26,LOW(-@2)
            SBCI R27,HIGH(-@2)
            ST   X,R30
            .ENDM

            .MACRO __PUTW1RON
            MOV  R26,R@0
            MOV  R27,R@1
            SUBI R26,LOW(-@2)
            SBCI R27,HIGH(-@2)
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1RON
            MOV  R26,R@0
            MOV  R27,R@1
            SUBI R26,LOW(-@2)
            SBCI R27,HIGH(-@2)
            CALL __PUTDP1
            .ENDM

            .MACRO __PUTB1RONS
            MOV  R26,R@0
            MOV  R27,R@1
            ADIW R26,@2
            ST   X,R30
            .ENDM

            .MACRO __PUTW1RONS
            MOV  R26,R@0
            MOV  R27,R@1
            ADIW R26,@2
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1RONS
            MOV  R26,R@0
            MOV  R27,R@1
            ADIW R26,@2
            CALL __PUTDP1
            .ENDM


            .MACRO __GETB1SX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            LD   R30,Z
            .ENDM

            .MACRO __GETB1HSX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            LD   R31,Z
            .ENDM

            .MACRO __GETW1SX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            LD   R0,Z+
            LD   R31,Z
            MOV  R30,R0
            .ENDM

            .MACRO __GETD1SX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            LD   R0,Z+
            LD   R1,Z+
            LD   R22,Z+
            LD   R23,Z
            MOVW R30,R0
            .ENDM

            .MACRO __GETB2SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            LD   R26,X
            .ENDM

            .MACRO __GETW2SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            LD   R0,X+
            LD   R27,X
            MOV  R26,R0
            .ENDM

            .MACRO __GETD2SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            LD   R0,X+
            LD   R1,X+
            LD   R24,X+
            LD   R25,X
            MOVW R26,R0
            .ENDM

            .MACRO __GETBRSX
            MOVW R30,R28
            SUBI R30,LOW(-@1)
            SBCI R31,HIGH(-@1)
            LD   R@0,Z
            .ENDM

            .MACRO __GETWRSX
            MOVW R30,R28
            SUBI R30,LOW(-@2)
            SBCI R31,HIGH(-@2)
            LD   R@0,Z+
            LD   R@1,Z
            .ENDM

            .MACRO __GETBRSX2
            MOVW R26,R28
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            LD   R@0,X
            .ENDM

            .MACRO __GETWRSX2
            MOVW R26,R28
            SUBI R26,LOW(-@2)
            SBCI R27,HIGH(-@2)
            LD   R@0,X+
            LD   R@1,X
            .ENDM

            .MACRO __LSLW8SX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            LD   R31,Z
            CLR  R30
            .ENDM

            .MACRO __PUTB1SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            ST   X,R30
            .ENDM

            .MACRO __PUTW1SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            ST   X+,R30
            ST   X+,R31
            ST   X+,R22
            ST   X,R23
            .ENDM

            .MACRO __CLRW1SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            ST   X+,R30
            ST   X,R30
            .ENDM

            .MACRO __CLRD1SX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            ST   X+,R30
            ST   X+,R30
            ST   X+,R30
            ST   X,R30
            .ENDM

            .MACRO __PUTB2SX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            ST   Z,R26
            .ENDM

            .MACRO __PUTW2SX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            ST   Z+,R26
            ST   Z,R27
            .ENDM

            .MACRO __PUTD2SX
            MOVW R30,R28
            SUBI R30,LOW(-@0)
            SBCI R31,HIGH(-@0)
            ST   Z+,R26
            ST   Z+,R27
            ST   Z+,R24
            ST   Z,R25
            .ENDM

            .MACRO __PUTBSRX
            MOVW R30,R28
            SUBI R30,LOW(-@1)
            SBCI R31,HIGH(-@1)
            ST   Z,R@0
            .ENDM

            .MACRO __PUTWSRX
            MOVW R30,R28
            SUBI R30,LOW(-@2)
            SBCI R31,HIGH(-@2)
            ST   Z+,R@0
            ST   Z,R@1
            .ENDM

            .MACRO __PUTB1SNX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            LD   R0,X+
            LD   R27,X
            MOV  R26,R0
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X,R30
            .ENDM

            .MACRO __PUTW1SNX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            LD   R0,X+
            LD   R27,X
            MOV  R26,R0
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X+,R30
            ST   X,R31
            .ENDM

            .MACRO __PUTD1SNX
            MOVW R26,R28
            SUBI R26,LOW(-@0)
            SBCI R27,HIGH(-@0)
            LD   R0,X+
            LD   R27,X
            MOV  R26,R0
            SUBI R26,LOW(-@1)
            SBCI R27,HIGH(-@1)
            ST   X+,R30
            ST   X+,R31
            ST   X+,R22
            ST   X,R23
            .ENDM

            .MACRO __MULBRR
            MULS R@0,R@1
            MOVW R30,R0
            .ENDM

            .MACRO __MULBRRU
            MUL  R@0,R@1
            MOVW R30,R0
            .ENDM

            .MACRO __MULBRR0
            MULS R@0,R@1
            .ENDM

            .MACRO __MULBRRU0
            MUL  R@0,R@1
            .ENDM

            .MACRO __MULBNWRU
            LDI  R26,@2
            MUL  R26,R@0
            MOVW R30,R0
            MUL  R26,R@1
            ADD  R31,R0
            .ENDM

;NAME DEFINITIONS FOR GLOBAL VARIABLES ALLOCATED TO REGISTERS
            .DEF __lcd_x=R5
            .DEF __lcd_y=R4
            .DEF __lcd_maxx=R7

            .CSEG
            .ORG 0x00

;INTERRUPT VECTORS
            JMP  __RESET
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00
            JMP  0x00

_0x0:
            .DB  0x20,0x4D,0x4F,0x54,0x4F,0x52,0x20,0x2D
            .DB  0x53,0x54,0x45,0x50,0x50,0x45,0x52,0x20
            .DB  0X20,0x20,0x43,0x2D,0x43,0x4C,0x4F,0x43
            .DB  0x4B,0x57,0x49,0x53,0x45,0x20,0x20,0x20
            .DB  0x20,0x20,0x43,0x4C,0x4F,0x43,0x4B,0x57
            .DB  0x49,0x53,0x45,0x00,0x0

        ;.DB  0x20,0x4D,0x4F,0x54,0x4F,0x52,0x2D,0x53
            ;.DB  0x54,0x45,0x50,0x50,0x45,0x52,0x00,0x20
            ;.DB  0X20,0x20,0X20,0X20,0x43,0x4C,0x4F,0x43
            ;.DB  0x4B,0x57,0x49,0x53,0x45,0x20,0X20,0X20
            ;.DB  0X20,0x43,0x2D,0x43,0x4C,0x4F,0x43,0x4B
            ;.DB  0x57,0x49,0x53,0x45,0x00,0x00,0x00,0x00

_0x2000003:
            .DB  0x80,0xC0

__GLOBAL_INI_TBL:
            .DW  0x02
            .DW  __base_y_G100
            .DW  _0x2000003*2

_0xFFFFFFFF:
            .DW  0

__RESET:
            CLI
            CLR  R30
            OUT  EECR,R30

;INTERRUPT VECTORS ARE PLACED
;AT THE START OF FLASH
            LDI  R31,1
            OUT  GICR,R31
            OUT  GICR,R30
            OUT  MCUCR,R30

;DISABLE WATCHDOG
            LDI  R31,0x18
            OUT  WDTCR,R31
            OUT  WDTCR,R30

;CLEAR R2-R14
            LDI  R24,(14-2)+1
            LDI  R26,2
            CLR  R27
__CLEAR_REG:
            ST   X+,R30
            DEC  R24
            BRNE __CLEAR_REG

;CLEAR SRAM
            LDI  R24,LOW(0x400)
            LDI  R25,HIGH(0x400)
            LDI  R26,0x60
__CLEAR_SRAM:
            ST   X+,R30
            SBIW R24,1
            BRNE __CLEAR_SRAM

;GLOBAL VARIABLES INITIALIZATION
            LDI  R30,LOW(__GLOBAL_INI_TBL*2)
            LDI  R31,HIGH(__GLOBAL_INI_TBL*2)
__GLOBAL_INI_NEXT:
            LPM  R24,Z+
            LPM  R25,Z+
            SBIW R24,0
            BREQ __GLOBAL_INI_END
            LPM  R26,Z+
            LPM  R27,Z+
            LPM  R0,Z+
            LPM  R1,Z+
            MOVW R22,R30
            MOVW R30,R0
__GLOBAL_INI_LOOP:
            LPM  R0,Z+
            ST   X+,R0
            SBIW R24,1
            BRNE __GLOBAL_INI_LOOP
            MOVW R30,R22
            RJMP __GLOBAL_INI_NEXT
__GLOBAL_INI_END:

;STACK POINTER INITIALIZATION
            LDI  R30,LOW(0x45F)
            OUT  SPL,R30
            LDI  R30,HIGH(0x45F)
            OUT  SPH,R30

;DATA STACK POINTER INITIALIZATION
            LDI R28,LOW(0x160)
            LDI R29,HIGH(0x160)
            JMP _main
            .ESEG
            .ORG 0
            .DSEG
            .ORG 0x160
            .CSEG
;
;
;#include <mega16.h>
            #ifndef __SLEEP_DEFINED__
            #define __SLEEP_DEFINED__
            .EQU __se_bit=0x40
            .EQU __sm_mask=0xB0
            .EQU __sm_powerdown=0x20
            .EQU __sm_powersave=0x30
            .EQU __sm_standby=0xA0
            .EQU __sm_ext_standby=0xB0
            .EQU __sm_adc_noise_red=0x10
            .SET power_ctrl_reg=mcucr
            #endif
;#include <delay.h>
;
;
;// Alphanumeric LCD Module functions
;#asm
        .equ __lcd_port=0x15      ;PORTC
; 0000 000A #endasm
;#include <lcd.h>
;
;// Declare your global variables here
;
;void main(void)
; 0000 0010 {

             .CSEG
_main:
; 0000 0011 PORTD = 0X00;
             LDI  R30,LOW(0)
             OUT  0x12,R30
; 0000 0012 DDRD = 0XFF;
             LDI  R30,LOW(255)
             OUT  0x11,R30
; 0000 0013
; 0000 0014 PORTB = 0XFF;
             OUT  0x18,R30
; 0000 0015 DDRB = 0X00;
             LDI  R30,LOW(0)
             OUT  0x17,R30
; 0000 0016
; 0000 0017 // LCD module initialization
; 0000 0018 lcd_init(16);
             LDI  R30,LOW(16)
             ST   -Y,R30
             CALL _lcd_init
; 0000 0019 lcd_gotoxy(1,0);
             LDI  R30,LOW(1)
             ST   -Y,R30
             LDI  R30,LOW(0)
             ST   -Y,R30
             CALL _lcd_gotoxy
; 0000 001A lcd_putsf(" MOTOR -STEPPER ");
             __POINTW1FN _0x0,1
             CALL SUBOPT_0x0
; 0000 001B
; 0000 001C
; 0000 001D while (1)
_0x3:
; 0000 001E       {
; 0000 001F       // Place your code here
; 0000 0020       if (PINB.7 == 0)
             SBIC 0x16,7
             RJMP _0x6
; 0000 0021       {
; 0000 0022       lcd_gotoxy(1,1);
             CALL SUBOPT_0x1
; 0000 0023       lcd_putsf("   C-CLOCKWISE   ");
             __POINTW1FN _0x0,17
             CALL SUBOPT_0x0
; 0000 0024
; 0000 0025       PORTD = 0X01;
             CALL SUBOPT_0x2
; 0000 0026       delay_ms(10);
; 0000 0027       PORTD = 0X02;
             CALL SUBOPT_0x3
; 0000 0028       delay_ms(10);
; 0000 0029       PORTD = 0X04;
             CALL SUBOPT_0x4
; 0000 002A       delay_ms(10);
; 0000 002B       PORTD = 0X08;
             CALL SUBOPT_0x5
; 0000 002C       delay_ms(10);
; 0000 002D       }
; 0000 002E
; 0000 002F
; 0000 0030       if (PINB.6 == 0)
_0x6:
             SBIC 0x16,6
             RJMP _0x7
; 0000 0031       {
; 0000 0032        lcd_gotoxy(1,1);
             CALL SUBOPT_0x1
; 0000 0033       lcd_putsf("    CLOCKWISE   ");
             __POINTW1FN _0x0,30
             CALL SUBOPT_0x0
; 0000 0034        PORTD = 0X08;
             CALL SUBOPT_0x5      
; 0000 0035        delay_ms(10);
; 0000 0036        PORTD = 0X04;
             CALL SUBOPT_0x4      
; 0000 0037        delay_ms(10);
; 0000 0038        PORTD = 0X02;
             CALL SUBOPT_0x3       
; 0000 0039        delay_ms(10);
; 0000 003A        PORTD = 0X01;
             CALL SUBOPT_0x2       
; 0000 003B        delay_ms(10);
; 0000 003C
; 0000 003D
; 0000 003E
; 0000 003F       }
; 0000 0040
; 0000 0041       };
_0x7:
             RJMP _0x3
; 0000 0042 }
_0x8:
             RJMP _0x8
        .equ __lcd_direction=__lcd_port-1
        .equ __lcd_pin=__lcd_port-2
        .equ __lcd_rs=0
        .equ __lcd_rd=1
        .equ __lcd_enable=2
        .equ __lcd_busy_flag=7

            .DSEG

            .CSEG
__lcd_delay_G100:
        ldi   r31,15
__lcd_delay0:
        dec   r31
        brne  __lcd_delay0
            RET
__lcd_ready:
        in    r26,__lcd_direction
        andi  r26,0xf                     ;set as input
        out   __lcd_direction,r26
        sbi   __lcd_port,__lcd_rd         ;RD=1
        cbi   __lcd_port,__lcd_rs         ;RS=0
__lcd_busy:
        RCALL __lcd_delay_G100
        sbi   __lcd_port,__lcd_enable      ;EN=1
        RCALL __lcd_delay_G100
        in    r26,__lcd_pin
        cbi   __lcd_port,__lcd_enable      ;EN=0
        RCALL __lcd_delay_G100
        sbi   __lcd_port,__lcd_enable      ;EN=1
        RCALL __lcd_delay_G100
        cbi   __lcd_port,__lcd_enable      ;EN=0
        sbrc  r26,__lcd_busy_flag
        rjmp  __lcd_busy
        RET
__lcd_write_nibble_G100:
        andi  r26,0xf0
        or    r26,r27
        out   __lcd_port,r26                ;write
        sbi   __lcd_port,__lcd_enable       ;EN=1
        CALL __lcd_delay_G100
        cbi   __lcd_port,__lcd_enable       ;EN=0
        CALL __lcd_delay_G100
        RET
__lcd_write_data:
        cbi  __lcd_port,__lcd_rd                  ;RD=0
        in   r26,__lcd_direction
        ori  r26,0xf0 | (1<<__lcd_rs) | (1<<__lcd_rd) | (1<<__lcd_enable)   ;set as output
        out  __lcd_direction,r26
        in   r27,__lcd_port
        andi r27,0xf
        ld   r26,y
        RCALL __lcd_write_nibble_G100
        ld   r26,y
        swap r26
        RCALL __lcd_write_nibble_G100
        sbi  __lcd_port,__lcd_rd            ;RD=1
        JMP  _0x2020001
__lcd_read_nibble_G100:
        sbi  __lcd_port,__lcd_enable        ;EN=1
        CALL __lcd_delay_G100
        in   r30,__lcd_pin                  ;read
        cbi  __lcd_port,__lcd_enable        ;EN=0
        CALL __lcd_delay_G100
        andi r30,0xf0
        RET
_lcd_read_byte0_G100:
        CALL __lcd_delay_G100
        RCALL __lcd_read_nibble_G100
        mov  r26,r30
        RCALL __lcd_read_nibble_G100
        cbi  __lcd_port,__lcd_rd             ;RD=0
        swap r30
        or   r30,r26
            RET
_lcd_gotoxy:
            CALL __lcd_ready
            LD   R30,Y
            LDI  R31,0
            SUBI R30,LOW(-__base_y_G100)
            SBCI R31,HIGH(-__base_y_G100)
            LD   R30,Z
            LDD  R26,Y+1
            ADD  R30,R26
            ST   -Y,R30
            CALL __lcd_write_data
            LDD  R5,Y+1
            LDD  R4,Y+0
            ADIW R28,2
            RET
_lcd_clear:
            CALL __lcd_ready
            LDI  R30,LOW(2)
            ST   -Y,R30
            CALL __lcd_write_data
            CALL __lcd_ready
            LDI  R30,LOW(12)
            ST   -Y,R30
            CALL __lcd_write_data
            CALL __lcd_ready
            LDI  R30,LOW(1)
            ST   -Y,R30
            CALL __lcd_write_data
            LDI  R30,LOW(0)
            MOV  R4,R30
            MOV  R5,R30
            RET
_lcd_putchar:
        push r30
        push r31
        ld   r26,y
        set
        cpi  r26,10
        breq __lcd_putchar1
        clt
            CP   R5,R7
            BRLO _0x2000004
__lcd_putchar1:
            INC  R4
            LDI  R30,LOW(0)
            ST   -Y,R30
            ST   -Y,R4
            RCALL _lcd_gotoxy
            brts __lcd_putchar0
_0x2000004:
            INC  R5
        rcall __lcd_ready
        sbi  __lcd_port,__lcd_rs     ;RS=1
        ld   r26,y
        st   -y,r26
        rcall __lcd_write_data
__lcd_putchar0:
        pop  r31
        pop  r30
            JMP  _0x2020001
_lcd_putsf:
            ST   -Y,R17
_0x2000008:
            LDD  R30,Y+1
            LDD  R31,Y+1+1
            ADIW R30,1
            STD  Y+1,R30
            STD  Y+1+1,R31
            SBIW R30,1
            LPM  R30,Z
            MOV  R17,R30
            CPI  R30,0
            BREQ _0x200000A
            ST   -Y,R17
            RCALL _lcd_putchar
            RJMP _0x2000008
_0x200000A:
            LDD  R17,Y+0
            ADIW R28,3
            RET
__long_delay_G100:
        clr  r26
        clr  r27
__long_delay0:
        sbiw  r26,1                  ;2 cycles
        brne __long_delay0           ;2 cycles
            RET
__lcd_init_write_G100:
        cbi  __lcd_port,__lcd_rd               ;RD=0
        in   r26,__lcd_direction
        ori  r26,0xf7                ;set as output
        out  __lcd_direction,r26
        in   r27,__lcd_port
        andi r27,0xf
        ld   r26,y
            CALL __lcd_write_nibble_G100
        sbi  __lcd_port,__lcd_rd     ;RD=1
            RJMP _0x2020001
_lcd_init:
        cbi  __lcd_port,__lcd_enable ;EN=0
        cbi  __lcd_port,__lcd_rs     ;RS=0
            LDD  R7,Y+0
            LD   R30,Y
            SUBI R30,-LOW(128)
            __PUTB1MN __base_y_G100,2
            LD   R30,Y
            SUBI R30,-LOW(192)
            __PUTB1MN __base_y_G100,3
            RCALL SUBOPT_0x6
            RCALL SUBOPT_0x6
            RCALL SUBOPT_0x6
            RCALL __long_delay_G100
            LDI  R30,LOW(32)
            ST   -Y,R30
            RCALL __lcd_init_write_G100
            RCALL __long_delay_G100
            LDI  R30,LOW(40)
            RCALL SUBOPT_0x7
            LDI  R30,LOW(4)
            RCALL SUBOPT_0x7
            LDI  R30,LOW(133)
            RCALL SUBOPT_0x7
        in    r26,__lcd_direction
        andi  r26,0xf                 ;set as input
        out   __lcd_direction,r26
        sbi   __lcd_port,__lcd_rd     ;RD=1
            CALL _lcd_read_byte0_G100
            CPI  R30,LOW(0x5)
            BREQ _0x200000B
            LDI  R30,LOW(0)
            RJMP _0x2020001
_0x200000B:
            CALL __lcd_ready
            LDI  R30,LOW(6)
            ST   -Y,R30
            CALL __lcd_write_data
            CALL _lcd_clear
            LDI  R30,LOW(1)
_0x2020001:
            ADIW R28,1
            RET

            .DSEG
__base_y_G100:
            .BYTE 0x4

            .CSEG
;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES, CODE SIZE REDUCTION:1 WORDS
SUBOPT_0x0:
            ST   -Y,R31
            ST   -Y,R30
            JMP  _lcd_putsf

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:1 WORDS
SUBOPT_0x1:
            LDI  R30,LOW(1)
            ST   -Y,R30
            ST   -Y,R30
            JMP  _lcd_gotoxy

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS  ( Half step mode )
;SUBOPT_0x2:
            LDI  R30,LOW(1)
            OUT  0x12,R30
            LDI  R30,LOW(5)
            LDI  R31,HIGH(10)
            ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS  ( Half step mode )
;SUBOPT_0x3:
            LDI  R30,LOW(8)
            OUT  0x12,R30
            LDI  R30,LOW(5)
            LDI  R31,HIGH(10)
            ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS  ( Half step mode )
;SUBOPT_0x4:
            LDI  R30,LOW(2)
            OUT  0x12,R30
            LDI  R30,LOW(5)
            LDI  R31,HIGH(10)
            ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS  ( Half step mode )
;SUBOPT_0x5:
            LDI  R30,LOW(4)
            OUT  0x12,R30
            LDI  R30,LOW(5)
            LDI  R31,HIGH(10)
            ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS (Two-phase-on (normal mode) drive /Fullstep )
SUBOPT_0x2:
            LDI  R30,LOW(5)
            OUT  0x12,R30
            LDI  R30,LOW(32)
            LDI  R31,HIGH(10)
            ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS (Two-phase-on (normal mode) drive /Fullstep )
SUBOPT_0x3:
            LDI  R30,LOW(9)
            OUT  0x12,R30
            LDI  R30,LOW(32)
            LDI  R31,HIGH(10)
            ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS (Two-phase-on (normal mode) drive /Fullstep )
SUBOPT_0x4:
            LDI  R30,LOW(10)
            OUT  0x12,R30
            LDI  R30,LOW(32)
            LDI  R31,HIGH(10)
            ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 2 TIMES, CODE SIZE REDUCTION:3 WORDS (Two-phase-on (normal mode) drive /Fullstep )
SUBOPT_0x5:
            LDI  R30,LOW(6)
            OUT  0x12,R30
            LDI  R30,LOW(32)
            LDI  R31,HIGH(10)
        ST   -Y,R31
            ST   -Y,R30
            JMP  _delay_ms

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES, CODE SIZE REDUCTION:5 WORDS
SUBOPT_0x6:
            CALL __long_delay_G100
            LDI  R30,LOW(48)
            ST   -Y,R30
            RJMP __lcd_init_write_G100

;OPTIMIZER ADDED SUBROUTINE, CALLED 3 TIMES, CODE SIZE REDUCTION:3 WORDS
SUBOPT_0x7:
            ST   -Y,R30
            CALL __lcd_write_data
            JMP  __long_delay_G100

            .CSEG
_delay_ms:
            ld   r30,y+
            ld   r31,y+
            adiw r30,0
            breq __delay_ms1
__delay_ms0:
            __DELAY_USW 0xBB8
            wdr
            sbiw r30,1
            brne __delay_ms0
__delay_ms1:
            ret

;END OF CODE MARKER
__END_OF_CODE:


Catatan: untuk simulasi menggunakan Proteus Clock pada Atmega16 di rubah ke 11.0592 MHz

Share

No comments:

Post a Comment