; =========================================================================
; Project: sjjdq
; Author: hjc
; Version: V0
; Date: 20210623
; =========================================================================
;--------------- File Include ---------------------------------------------
;--------------------------------------------------------------------------
; --------
; VDD-| |-VSS
;R PB5 -| |- PB0 B
;G PB4 -| |- PB1
;K3 PB3 -|RST |- PB2 PWM
; --------
#include NY8A051F.H ; The Header File for NY8A054E
OUTB EQU PORTB
LED_R EQU 5
LED_G EQU 4
K EQU 3
LED_B EQU 0
PWM EQU 2
LLED EQU 1
FL EQU 7;七彩速度
;--------------- Variable Definition --------------------------------------
;--------------------------------------------------------------------------
R_AccBuf EQU 0x20 ; Store ACC value
R_StatusBuf EQU 0x21 ; Store Status value
R_shift_regl EQU 0x22 ; Map to present state of PortB Data buffer
NS EQU 0X23
MS EQU 0X24
S EQU 0X25
MIN EQU 0X26
H EQU 0X27
KV EQU 0X28
KS EQU 0X2A
EN EQU 0X2B
RUN EQU 0
ken EQU 1
EN1 EQU 2
DCLL EQU 3
MODE_V EQU 0X2C
S1 EQU 0X2D
M_V EQU 0X2E
R_V EQU 0X2F
G_V EQU 0X30
B_V EQU 0X31
S2 EQU 0X32
PW EQU 0X33
PWMV EQU 0X34
LS EQU 0X35
X EQU 0X36
Y EQU 0X37
VV EQU 0X38
LV EQU 0X39
XX EQU 0X3A
ORG 0x000
lgoto V_Main
ORG 0x008
lgoto INT_RET
MV_x:
MOVIA FL
SUBAR LS,0
BTRSS Status,0
RET
CLRR LS
movR VV,0
ADDAR PCL,1
LGOTO M10
LGOTO M11
LGOTO M12
LGOTO M13
LGOTO M14
LGOTO M15
LGOTO M16
LGOTO M17
LGOTO M18
LGOTO M19
CLRR MODE_V
RET
INT_RET:
movar R_AccBuf ; Store ACC value
swapr R_AccBuf,C_SaveToReg
movr STATUS,C_SaveToAcc
movar R_StatusBuf
MOVIA 63
MOVAR TMR0
MOVIA 0
MOVAR INTF
INCR NS,1
MOVIA 100
SUBAR NS,0
BTRSS STATUS,0
LGOTO EXIT
CLRR NS
MOVIA 0X02
XORAR PORTB,1
INCR LS,1
INCR MS,1
MOVIA 100
SUBAR MS,0
btrss Status,0
LGOTO EXIT
CLRR MS
INCR S1,1
INCR S2,1
INCR S,1
MOVIA 60
SUBAR S,0
btrss Status,0
LGOTO EXIT
CLRR S
INCR MIN,1
MOVIA 60
SUBAR MIN,0
btrss Status,0
LGOTO EXIT
CLRR MIN
INCR H,1
CLRR MODE_V
CLRR M_V
EXIT:
movr R_StatusBuf,C_SaveToAcc
movar STATUS ; Restore STATUS value
swapr R_AccBuf,C_SaveToAcc ; Restore ACC value
RETIE
V_Main:
movia 00001000b
iost IOSTB
movia 11110111b
MOVAR BPHCON
CLRR EN
CLRR MS
CLRR S
CLRR MODE_V
CLRR M_V
CLRR VV
movia 0X00
MOVAR portb
WAKUP:
movia 00100000B
MOVAR PCON
movia 00010101B
iost PCON1
movia 0x00
SFUN TMR0
movia 0xFF
sfun TMR1
movia 00000001B
movar INTE
movia 00000000B
T0MD
DISI
;--------------------------------------------------------------
L_MainLoop:
ENI
Lcall key1
LCALL SLE
LCALL LVD_ON
BTRSC EN,DCLL
LGOTO OFF
MOVIA 1
XORAR M_V,0
btrsC Status,2
LCALL MV_X
MOVIA 0
XORAR M_V,0
btrsC Status,2
LCALL OFF_LED
LCALL PWM_RUN
MOVIA 0
XORAR MODE_V,0
BTRSC STATUS,2
LGOTO MODE0
MOVIA 1
XORAR MODE_V,0
BTRSC STATUS,2
LGOTO MODE1
MOVIA 2
XORAR MODE_V,0
BTRSC STATUS,2
LGOTO MODE2
MOVIA 3
XORAR MODE_V,0
BTRSC STATUS,2
LGOTO MODE3
MOVIA 4
SUBAR MODE_V,0
BTRSC STATUS,0
CLRR MODE_V
lgoto L_MainLoop
OFF:
CLRR M_V
CLRR R_V
CLRR G_V
CLRR B_V
CLRR PW
CLRR MODE_V
CLRR M_V
BSR OUTB,LED_R
BSR OUTB,LED_G
BSR OUTB,LED_B
movia 17
sfun TMR1
movia 0
sfun PWM1Duty
movia 00000011B ;
sfun T1CR1
movia 0x00
sfun T1CR2
lgoto L_MainLoop
OFF_LED:
CLRR M_V
CLRR R_V
CLRR G_V
CLRR B_V
BSR OUTB,LED_R
BSR OUTB,LED_G
BSR OUTB,LED_B
CLRR PW
RET
PWM_RUN:
INCR PW,1
MOVIA 100
SUBAR PW,0
BTRSC STATUS,0
CLRR PW
MOVR R_V,0
SUBAR PW,0
BTRSS STATUS,0
BCR OUTB,LED_R
BTRSC STATUS,0
BSR OUTB,LED_R
MOVR G_V,0
SUBAR PW,0
BTRSS STATUS,0
BCR OUTB,LED_G
BTRSC STATUS,0
BSR OUTB,LED_G
MOVR B_V,0
SUBAR PW,0
BTRSS STATUS,0
BCR OUTB,LED_B
BTRSC STATUS,0
BSR OUTB,LED_B
RET
LVD_ON:
BTRSC EN,DCLL
LGOTO BC_DCLL
CLRR LV
movia 01010101B
iost PCON1
movia 00100000B
MOVAR PCON
NOP
NOP
NOP
NOP
NOP
IOSTR PCON1
MOVAR LV
BTRSS LV,6
BSR EN,DCLL
RET
BC_DCLL:
CLRR LV
movia 01011101B
iost PCON1
movia 00100000B
MOVAR PCON
NOP
NOP
NOP
NOP
NOP
IOSTR PCON1
MOVAR LV
BTRSC LV,6
BCR EN,DCLL
RET
key1:
incr ks,1
btrss Status,2
ret
rlr kv,1
bcr kv,0
btrss outb,K
BSR KV,0
movia 0
xorar kv,0
btrsc Status,2
BCR EN,KEN
movia 0xfE
xorar kv,0
btrsc Status,2
Lgoto KEY_EN
movia 0xff
xorar kv,0
btrsc Status,2
Lgoto long_k
movia 0x7f
xorar kv,0
btrss Status,2
ret
CLRR MS
CLRR S
RET
KEY_EN:
btrsc en,ken
RET
INCR MODE_V,1
CLRR S2
CLRR MIN
CLRR H
BCR EN,EN1
MOVIA 1
XORAR MODE_V,0
btrsC Status,2
LGOTO LED_1
MOVIA 4
SUBAR MODE_V,0
btrsC Status,0
CLRR M_V
btrsC Status,0
CLRR MODE_V
ret
LED_1:
MOVIA 1
MOVAR M_V
RET
LONG_K:
btrsC EN,KEN
RET
MOVIA 2
SUBAR S,0
btrss Status,0
ret
BSR EN,KEN
INCR M_V,1
MOVIA 3
SUBAR M_V,0
btrsC Status,0
CLRR M_V
ret
M10:
CLRR R_V
CLRR G_V
CLRR B_V
INCR VV,1
RET
M11:
INCR R_V,1
MOVIA 100
SUBAR R_V,0
btrsC Status,0
INCR VV,1
RET
M12:
INCR G_V,1
MOVIA 100
SUBAR G_V,0
btrsC Status,0
INCR VV,1
RET
M13:
DECR R_V,1
MOVIA 1
SUBAR R_V,0
btrss Status,0
INCR VV,1
RET
M14:
INCR B_V,1
MOVIA 100
SUBAR B_V,0
btrsC Status,0
INCR VV,1
RET
M15:
DECR G_V,1
MOVIA 1
SUBAR G_V,0
btrsS Status,0
INCR VV,1
RET
M16:
INCR R_V,1
MOVIA 100
SUBAR R_V,0
btrsC Status,0
INCR VV,1
RET
M17:
DECR B_V,1
MOVIA 1
SUBAR B_V,0
btrss Status,0
INCR VV,1
RET
M18:
INCR G_V,1
INCR B_V,1
MOVIA 100
SUBAR B_V,0
btrsC Status,0
INCR VV,1
RET
M19:
DECR B_V,1
DECR G_V,1
MOVIA 1
SUBAR B_V,0
btrsC Status,0
RET
MOVIA 1
MOVAR VV
RET
MODE0:
LCALL OFF_PWM
LGOTO L_MainLoop
MODE1:
BTRSS EN,EN1
LCALL ON_PWM30
LGOTO L_MainLoop
MODE2:
BTRSS EN,EN1
LCALL PWM_ON
LGOTO L_MainLoop
MODE3:
MOVIA 0
XORAR S2,0
btrsC Status,2
LCALL PWM_ON
MOVIA 5
XORAR S2,0
btrsC Status,2
LCALL OFF_PWM
MOVIA 11
SUBAR S2,0
btrsC Status,0
CLRR S2
LGOTO L_MainLoop
OFF_PWM:
movia 36
sfun TMR1
movia 0
sfun PWM1Duty
movia 00000011B ;
sfun T1CR1
movia 0x00
sfun T1CR2
BCR OUTB,PWM
INCR S2,1
RET
ON_PWM30:;P62
movia 36
sfun TMR1
movia 7
sfun PWM1Duty
BSR EN,EN1
movia 10000011B
sfun T1CR1
movia 00001000B
sfun T1CR2
INCR S2,1
RET
PWM_ON:
BSR EN,EN1
INCR S2,1
movia 36
sfun TMR1
movia 18
sfun PWM1Duty
movia 10000011B ;
sfun T1CR1
movia 00001000B
sfun T1CR2
RET
SLE:
MOVIA 0
XORAR KV,0
btrsS Status,2
RET
MOVIA 0
XORAR MODE_V,0
btrsS Status,2
RET
MOVIA 0
XORAR M_V,0
btrsS Status,2
RET
LCALL OFF_LED
LCALL OFF_PWM
movia 0X02
movar INTE ; Enable PortB input change interrupt
movia 0x00
movar INTF
clrwdt ; Clear WatchDog
movia 00001000B
MOVAR BWUCON
movia 00000000B
iost PCON1
BSR KV,0
movr Pr_PB_Data,C_SaveToReg
SLEEP
LGOTO WAKUP
end
|