📄 3.asm
字号:
mov channel3_fade_counter, channel3_fade_delay ;preset value
mov A, channel3_fade_PWM ;prepare for check
cjne A, channel3_fade_max, channel3_fade_to_on_2 ;countinue
clr fade3_to_on_in_progress ;Fading finished
setb fade3_direction ;last time I fade to on
sjmp channel3_fade_to_on_3 ;go for exit
channel3_fade_to_on_2:
inc channel3_fade_PWM ;one step forward
channel3_fade_to_on_3:
mov Channel3_PWM_percent, channel3_fade_PWM
channel3_fade_to_on_x:
ret
;============================================================================
channel4_fade_to_off_init:
mov A, channel4_fade_min ;prepare for check
cjne A, channel4_fade_PWM, channel4_fade_to_off_init_1
ret
channel4_fade_to_off_init_1:
jc channel4_fade_to_off_init_2
ret
channel4_fade_to_off_init_2:
clr fade4_to_on_in_progress
setb fade4_to_off_in_progress ;I am fading !
mov channel4_fade_counter, channel4_fade_delay ;preset value
; mov channel4_fade_PWM, channel4_fade_max
;============================================================================
channel4_fade_to_off:
jb fade4_to_off_in_progress, channel4_fade_to_off_1
ret
channel4_fade_to_off_1:
inc channel4_fade_counter ;counter++
mov A, channel4_fade_counter ;prepare for check
jnz channel4_fade_to_off_3 ;counter overflow check
mov channel4_fade_counter, channel4_fade_delay ;preset value
mov A, channel4_fade_PWM ;prepare for check
cjne A, channel4_fade_min, channel4_fade_to_off_2 ;countinue
clr fade4_to_off_in_progress ;Fading finished
clr fade4_direction ;last time I fade to off
sjmp channel4_fade_to_off_3 ;go for exit
channel4_fade_to_off_2:
dec channel4_fade_PWM ;one step back
channel4_fade_to_off_3:
mov Channel4_PWM_percent, channel4_fade_PWM
channel4_fade_to_off_x:
ret
;============================================================================
channel4_fade_to_on_init:
mov A, channel4_fade_max ;prepare for check
cjne A, channel4_fade_PWM, channel4_fade_to_on_init_1
ret
channel4_fade_to_on_init_1:
jnc channel4_fade_to_on_init_2
ret
channel4_fade_to_on_init_2:
clr fade4_to_off_in_progress
setb fade4_to_on_in_progress ;I am fading !
mov channel4_fade_counter, channel4_fade_delay ;preset value
; mov channel4_fade_PWM, channel4_fade_min
;============================================================================
channel4_fade_to_on:
jb fade4_to_on_in_progress, channel4_fade_to_on_1
ret
channel4_fade_to_on_1:
inc channel4_fade_counter ;counter++
mov A, channel4_fade_counter ;prepare for check
jnz channel4_fade_to_on_3 ;counter overflow check
mov channel4_fade_counter, channel4_fade_delay ;preset value
mov A, channel4_fade_PWM ;prepare for check
cjne A, channel4_fade_max, channel4_fade_to_on_2 ;countinue
clr fade4_to_on_in_progress ;Fading finished
setb fade4_direction ;last time I fade to on
sjmp channel4_fade_to_on_3 ;go for exit
channel4_fade_to_on_2:
inc channel4_fade_PWM ;one step forward
channel4_fade_to_on_3:
mov Channel4_PWM_percent, channel4_fade_PWM
channel4_fade_to_on_x:
ret
;============================================================================
Timer0_process:
jb TF0, Timer0_OverFlow ;if another milisecond...
jmp Timer0_process_x ;exit
Timer0_OverFlow:
clr TF0 ;clear overflow flag
mov TL0, #030h ;F830h=-2000, 1ms with 24MHz crystal
mov TH0, #0F8h ;F830h=-2000, 1ms with 24MHz crystal
mov R0, #Timer_counter_int16 ;prepare for int16 increamnet
call int16_inc ;timer_counter++
mov A, (Timer_counter_int16 + 0) ;prepare for second checking
jz Timer0_process_1 ;if timer_counter != 0
jmp Timer0_process_a ;exit
Timer0_process_1:
mov A, (Timer_counter_int16 + 1) ;prepare for second checking
jz Timer0_process_2 ;if timer_counter != 0
jmp Timer0_process_a ;exit
Timer0_process_2:
mov (Timer_counter_int16 + 0), #018h ;preset value
mov (Timer_counter_int16 + 1), #0FCh ;preset value
inc second ;second++
setb second_flag ;clear !
inc sequence1_timer ;timer++
Timer0_process_a:
Timer0_process_x:
ret
;============================================================================
Timer1_process:
jb TF1, Timer1_OverFlow ;if another milisecond...
jmp Timer1_process_x ;exit
Timer1_OverFlow:
clr TF1 ;clear overflow flag
mov TL1, #CYCLE_TIMER_LOWBYTE ;preset timer value
mov TH1, #CYCLE_TIMER_HIGHBYTE ;preset timer value
mov A, PWM_mscounter ;prepare for check
jnz Timer1_process_a1 ;if counter == PWM_PULSE_PER_CYCLE
mov PWM_mscounter, #PWM_PULSE_PER_CYCLE ;preset value
call Channel1_PWM_update ;update to new values
call Channel2_PWM_update ;update to new values
call Channel3_PWM_update ;update to new values
call Channel4_PWM_update ;update to new values
Timer1_process_a1:
inc PWM_mscounter ;increament timer
call channel1_PWM ;go for channel 1 PWM
call channel2_PWM ;go for channel 2 PWM
call channel3_PWM ;go for channel 3 PWM
call channel4_PWM ;go for channel 4 PWM
Timer1_process_x:
ret
;============================================================================
Channel1_PWM_update:
jnb fade1_to_on_in_progress, Channel1_PWM_update_1
call channel1_fade_to_on
ret
Channel1_PWM_update_1:
jnb fade1_to_off_in_progress, Channel1_PWM_update_2
call channel1_fade_to_off
ret
Channel1_PWM_update_2:
mov Channel1_PWM_percent, channel1_fade_PWM
ret
;============================================================================
Channel2_PWM_update:
jnb fade2_to_on_in_progress, Channel2_PWM_update_1
call channel2_fade_to_on
ret
Channel2_PWM_update_1:
jnb fade2_to_off_in_progress, Channel2_PWM_update_2
call channel2_fade_to_off
ret
Channel2_PWM_update_2:
mov Channel2_PWM_percent, channel2_fade_PWM
ret
;============================================================================
Channel3_PWM_update:
jnb fade3_to_on_in_progress, Channel3_PWM_update_1
call channel3_fade_to_on
ret
Channel3_PWM_update_1:
jnb fade3_to_off_in_progress, Channel3_PWM_update_2
call channel3_fade_to_off
ret
Channel3_PWM_update_2:
mov Channel3_PWM_percent, channel3_fade_PWM
ret
;============================================================================
Channel4_PWM_update:
jnb fade4_to_on_in_progress, Channel4_PWM_update_1
call channel4_fade_to_on
ret
Channel4_PWM_update_1:
jnb fade4_to_off_in_progress, Channel4_PWM_update_2
call channel4_fade_to_off
ret
Channel4_PWM_update_2:
mov Channel4_PWM_percent, channel4_fade_PWM
ret
;============================================================================
channel1_PWM:
mov A, Channel1_PWM_percent ;prepare for checking
jnz channel1_PWM_1 ;if it is not zero go for decreamentation
setb channel1_port ;turn it off
ret
channel1_PWM_1:
clr channel1_port ;turn it on
dec Channel1_PWM_percent ;percent--
ret
;============================================================================
channel2_PWM:
mov A, Channel2_PWM_percent ;prepare for checking
jnz channel2_PWM_1 ;if it is not zero go for decreamentation
setb channel2_port ;turn it off
ret
channel2_PWM_1:
clr channel2_port ;turn it on
dec Channel2_PWM_percent ;percent--
ret
;============================================================================
channel3_PWM:
mov A, Channel3_PWM_percent ;prepare for checking
jnz channel3_PWM_1 ;if it is not zero go for decreamentation
setb channel3_port ;turn it off
ret
channel3_PWM_1:
clr channel3_port ;turn it on
dec Channel3_PWM_percent ;percent--
ret
;============================================================================
channel4_PWM:
mov A, Channel4_PWM_percent ;prepare for checking
jnz channel4_PWM_1 ;if it is not zero go for decreamentation
setb channel4_port ;turn it off
ret
channel4_PWM_1:
clr channel4_port ;turn it on
dec Channel4_PWM_percent ;percent--
ret
;============================================================================
initialize_variables:
mov (Timer_counter_int16 + 0), #018h ;preset value
mov (Timer_counter_int16 + 1), #0FCh ;preset value
mov second, #000h
mov PWM_mscounter, #-10 ;preset value
mov sequence1_timer, #00 ;preset value
mov sequence1_counter, #00 ;preset value
clr fade1_to_off_in_progress
clr fade2_to_off_in_progress
clr fade3_to_off_in_progress
clr fade4_to_off_in_progress
clr fade1_to_on_in_progress
clr fade2_to_on_in_progress
clr fade3_to_on_in_progress
clr fade4_to_on_in_progress
setb Key_start
setb key_start_pause
setb key_stop_reset
setb key_record
setb sound_chip_PD
setb sound_chip_CE
setb sound_chip_PR
setb sound_chip_addr0
setb sound_chip_mode6
setb sound_chip_EOM
ret
;============================================================================
;Timer settings for second generating
Timer0_initialize:
mov A, #00000001b
orl TMOD, A ;timer0 16bit
mov TL0, #030h ;F830h=-2000, 1ms with 24MHz crystal
mov TH0, #0F8h ;F830h=-2000, 1ms with 24MHz crystal
clr PT0 ;disable interrupt priority
clr ET0 ;timer0 interrupt status
; setb EA ;interrupt enable
ret
;============================================================================
;Timer settings for second
Timer1_initialize:
mov A, #00010000b
orl TMOD, A ;timer1 16bit
mov TL1, #CYCLE_TIMER_LOWBYTE ;preset timer value
mov TH1, #CYCLE_TIMER_HIGHBYTE ;preset timer value
clr TF1 ;clear overflow flag
clr PT1 ;disable interrupt priority
; setb ET1 ;timer1 interrupt enable
; setb EA ;interrupt enable
ret
;============================================================================
External0_interrupt:
reti
;============================================================================
TimerA_interrupt:
reti
;============================================================================
External1_interrupt:
reti
;============================================================================
TimerB_interrupt:
reti
;============================================================================
Serial_interrupt:
reti
;============================================================================
int16_inc: ;Lowbyte address at R0
inc @R0
cjne @R0, #00h, int16_inc_exit
inc R0
inc @R0
int16_inc_exit:
dec R0
ret
;============================================================================
int16_dec: ;Lowbyte address at R0
dec @R0
cjne @R0, #0FFh, int16_dec_exit
inc R0
dec @R0
int16_dec_exit:
dec R0
ret
;============================================================================
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -