⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 migalka.asm

📁 Lamp switcher. (4 channels with PWM)
💻 ASM
📖 第 1 页 / 共 2 页
字号:
                pop     R17
                pop     R16
                ret
;===== Adjust value channels ============================
AdjValuesCh:    push    R16

                lds     R16,ProgValue
                andi    R16,0x01
                breq    AdjVal_0
                lds     R16,CntCh0
                cpi     R16,0xff
                breq    AdjVal_1
                inc     R16
                sts     CntCh0,R16
                rjmp    AdjVal_1
AdjVal_0:       lds     R16,CntCh0
                cpi     R16,0x00
                breq    AdjVal_1
                dec     R16
                sts     CntCh0,R16
AdjVal_1:


                lds     R16,ProgValue
                andi    R16,0x02
                breq    AdjVal_2
                lds     R16,CntCh1
                cpi     R16,0xff
                breq    AdjVal_3
                inc     R16
                sts     CntCh1,R16
                rjmp    AdjVal_3
AdjVal_2:       lds     R16,CntCh1
                cpi     R16,0x00
                breq    AdjVal_3
                dec     R16
                sts     CntCh1,R16
AdjVal_3:

                lds     R16,ProgValue
                andi    R16,0x04
                breq    AdjVal_4
                lds     R16,CntCh2
                cpi     R16,0xff
                breq    AdjVal_5
                inc     R16
                sts     CntCh2,R16
                rjmp    AdjVal_5
AdjVal_4:       lds     R16,CntCh2
                cpi     R16,0x00
                breq    AdjVal_5
                dec     R16
                sts     CntCh2,R16
AdjVal_5:

                lds     R16,ProgValue
                andi    R16,0x08
                breq    AdjVal_6
                lds     R16,CntCh3
                cpi     R16,0xff
                breq    AdjVal_7
                inc     R16
                sts     CntCh3,R16
                rjmp    AdjVal_7
AdjVal_6:       lds     R16,CntCh3
                cpi     R16,0x00
                breq    AdjVal_7
                dec     R16
                sts     CntCh3,R16
AdjVal_7:
                pop     R16
                ret
;===== PWM mode check ===================================
PWMmode:        push    R16
                lds     R16,PWMflag
                cpi     R16,0x00
                breq    NoPWMmode

                lds     R16,CntCh0
                sts     ValCh0_,R16
                lds     R16,CntCh1
                sts     ValCh1_,R16
                lds     R16,CntCh2
                sts     ValCh2_,R16
                lds     R16,CntCh3
                sts     ValCh3_,R16

                pop     R16
                ret

NoPWMmode:      lds     R16,CntCh0
                andi    R16,0x80
                breq    NoPWMmode_1
                ldi     R16,0xff
NoPWMmode_1:    sts     ValCh0_,R16

                lds     R16,CntCh1
                andi    R16,0x80
                breq    NoPWMmode_2
                ldi     R16,0xff
NoPWMmode_2:    sts     ValCh1_,R16

                lds     R16,CntCh2
                andi    R16,0x80
                breq    NoPWMmode_3
                ldi     R16,0xff
NoPWMmode_3:    sts     ValCh2_,R16

                lds     R16,CntCh3
                andi    R16,0x80
                breq    NoPWMmode_4
                ldi     R16,0xff
NoPWMmode_4:    sts     ValCh3_,R16

                pop     R16
                ret
;----- Checking keys ------------------------------------
KeyCheck:       cpi     KeyCnt1,10
                breq    Key1pr
                cpi     KeyCnt2,10
                breq    Key2pr
                cpi     KeyCnt3,10
                breq    Key3pr
                cpi     KeyCnt4,10
                breq    Key4pr
                cpi     KeyCnt5,10
                breq    Key5pr
                cpi     KeyCnt6,10
                breq    Key6pr
                ret
Key1pr:         rjmp    Key2pressed
Key2pr:         rjmp    Key1pressed
Key3pr:         rjmp    Key3pressed
Key4pr:         rjmp    Key4pressed
Key5pr:         rjmp    Key5pressed
Key6pr:         rjmp    Key6pressed
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Key1pressed:    ldi     R16,100
                sts     EEPflag,R16
                sts     EEPwr,R16
                ldi     KeyCnt2,11
                lds     R16,ProgNum
                ldi     ZL,Low(ProgTab*2)
                ldi     ZH,High(ProgTab*2)
                lpm     R17,Z
                inc     R16
                cp      R16,R17
                brne    Key1pressed1
                clr     R16
Key1pressed1:   sts     ProgNum,R16
                clr     R16
                sts     CntCh0,R16
                sts     CntCh1,R16
                sts     CntCh2,R16
                sts     CntCh3,R16
                sts     ProgSt,R16
                sts     ProgBit,R16
                sts     ProgValue,R16
                ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Key2pressed:    ldi     R16,100
                sts     EEPflag,R16
                sts     EEPwr,R16
                ldi     KeyCnt1,11
                lds     R16,ProgNum
                ldi     ZL,Low(ProgTab*2)
                ldi     ZH,High(ProgTab*2)
                dec     R16
                cpi     R16,0xff
                brne    Key2pressed1
                lpm     R16,Z
                dec     R16
Key2pressed1:   sts     ProgNum,R16
                clr     R16
                sts     CntCh0,R16
                sts     CntCh1,R16
                sts     CntCh2,R16
                sts     CntCh3,R16
                sts     ProgSt,R16
                sts     ProgBit,R16
                sts     ProgValue,R16
                ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Key3pressed:    ldi     R16,100
                sts     EEPflag,R16
                sts     EEPwr,R16
                ldi     KeyCnt3,11
                ldi     YH,High(Speeds)
                ldi     YL,Low(Speeds)
                ldi     ZH,High(SpeedTab*2)
                ldi     ZL,Low(SpeedTab*2)

                lds     R16,ProgNum
                ldi     R17,0x00

                add     YL,R16
                adc     YH,R17

                add     ZL,R16
                adc     ZH,R17
                add     ZL,R16
                adc     ZH,R17
                add     ZL,R16
                adc     ZH,R17
                add     ZL,R16
                adc     ZH,R17

                lpm     R8,Z+
                lpm     R9,Z+
                lpm     R10,Z+

                ld      R16,Y

                cp      R16,R9
                brne    Key3pressed1
                mov     R16,R8
                rjmp    Key3pressed2
Key3pressed1:   add     R16,R10
Key3pressed2:   st      Y,R16
                ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Key4pressed:    ldi     R16,100
                sts     EEPflag,R16
                sts     EEPwr,R16
                ldi     KeyCnt4,11
                lds     R16,PWMflag
                com     R16
                sts     PWMflag,R16
                ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Key5pressed:    ldi     R16,100
                sts     EEPflag,R16
                sts     EEPwr,R16
                ldi     KeyCnt5,11
                lds     R16,AutoMode
                com     R16
                sts     AutoMode,R16
                ldi     R16,LoopProg
                sts     LoopPrg,R16
                ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Key6pressed:    ldi     R16,100
                sts     EEPflag,R16
                sts     EEPwr,R16
                ldi     KeyCnt6,11
                lds     R16,Microphone
                com     R16
                sts     Microphone,R16
                ret
;--------------------------------------------------------
RestoreEEP:     ldi     R19,0x00
                ldi     R18,0x00
                ldi     R17,0x10
                ldi     ZL,20

RestoreEEP1:    rcall   EEPROM_read
                add     R19,R16
                inc     R17
                dec     ZL
                brne    RestoreEEP1
                rcall   EEPROM_read

                cp      R16,R19
                breq    Read_Ok
                rjmp    Fault_read

Read_Ok:        ldi     R18,0x00
                ldi     R17,0x10

                rcall   EEPROM_Read
                sts     PWMflag,R16
                inc     R17
                rcall   EEPROM_Read
                sts     AutoMode,R16
                inc     R17
                rcall   EEPROM_Read
                sts     ProgNum,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Microphone,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+0,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+1,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+2,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+3,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+4,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+5,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+6,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+7,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+8,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+9,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+10,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+11,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+12,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+13,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+14,R16
                inc     R17
                rcall   EEPROM_Read
                sts     Speeds+15,R16
                ret
Fault_read:     ldi     R16,0x00
                sts     PWMflag,R16
                sts     AutoMode,R16
                sts     ProgNum,R16
                sts     Microphone,R16

                ldi     ZL,Low(SpeedTab*2)
                ldi     ZH,High(SpeedTab*2)

                adiw    ZH:ZL,3
                ldi     YL,Low(Speeds)
                ldi     YH,High(Speeds)

                ldi     R17,16

Fault_read1:    lpm     R16,Z
                st      Y,R16
                adiw    ZH:ZL,0x04
                adiw    YH:YL,0x01
                dec     R17
                brne    Fault_read1

                rcall   StoreEEP

                rjmp    RestoreEEP
;--------------------------------------------------------
EEPROM_read:    sbic    EECR,EEWE
                rjmp    EEPROM_read
                out     EEARH, R18
                out     EEARL, R17
                sbi     EECR,EERE
                in      R16,EEDR
                ret
;--------------------------------------------------------
StoreEEP:       ldi     R19,0x00
                ldi     R18,0x00
                ldi     R17,0x10

                lds     R16,PWMflag
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,AutoMode
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,ProgNum
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Microphone
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+0
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+1
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+2
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+3
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+4
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+5
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+6
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+7
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+8
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+9
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+10
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+11
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+12
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+13
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+14
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17
                lds     R16,Speeds+15
                add     R19,R16
                rcall   EEPROM_Write
                inc     R17

                mov     R16,R19
                rcall   EEPROM_Write
                ret
;--------------------------------------------------------
EEPROM_write:   sbic    EECR,EEWE
                rjmp    EEPROM_write
                out     EEARH, R18
                out     EEARL, R17
                out     EEDR,R16
                sbi     EECR,EEMWE
                sbi     EECR,EEWE
                ret
;--------------------------------------------------------
                                                ; 亦犭桷

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -