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

📄 3.asm

📁 this program has many parts and fully working, based on MCS51. Hand made PWM and wave forms for dim
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;=======================================================================
;In the name of ALLAH
;this project name is "MAN VA TO" and started at 16-3-2002
;Version	1.0
;============================================================================
;Definations
        PWS             	equ     0D0h
        PCON            	equ     087h

	channel1_port		equ	0B0h	;P3.0
	channel2_port		equ	0B1h	;P3.1
	channel3_port		equ	0B2h	;P3.2
	channel4_port		equ	097h	;P1.7
	Key_start		equ	090h	;P1.0

	key_start_pause		equ	0B7h	;P3.7
	key_stop_reset		equ	0B4h	;P3.4
	key_record		equ	0B5h	;P3.5
	sound_chip_PD		equ	095h	;P1.5
	sound_chip_CE		equ	093h	;P1.3
	sound_chip_PR		equ	096h	;P1.6
	sound_chip_addr0	equ	094h	;P1.4
	sound_chip_mode6	equ	092h	;P1.2
	sound_chip_EOM		equ	0B3h	;P3.3
	LED_record		equ	091h	;P1.1

	PWM_PULSE_PER_CYCLE	equ	-100	;PULSE / CYCLE
	Max_POWER		equ	075	;power percent
	CYCLE_TIMER_LOWBYTE	equ	006h	;pulse width timer
	CYCLE_TIMER_HIGHBYTE	equ	0FFh	;pulse width timer
;============================================================================
;Byte allocations
	Timer_counter_int16	equ	030h	;2byte timer counter for internal clock
	second			equ	032h	;second counter

	channel1_PWM_percent	equ	040h	;channels PWM counter
	channel2_PWM_percent	equ	041h	;channels PWM counter
	channel3_PWM_percent	equ	042h	;channels PWM counter
	channel4_PWM_percent	equ	043h	;channels PWM counter
	PWM_mscounter		equ	044h	;PWM timer
	channel1_fade_counter	equ	045h	;fade counter
	channel2_fade_counter	equ	046h	;fade counter
	channel3_fade_counter	equ	047h	;fade counter
	channel4_fade_counter	equ	048h	;fade counter
	channel1_fade_delay	equ	049h	;fade delay
	channel2_fade_delay	equ	04Ah	;fade delay
	channel3_fade_delay	equ	04Bh	;fade delay
	channel4_fade_delay	equ	04Ch	;fade delay
	channel1_fade_PWM	equ	04Dh	;fade PWM calculator
	channel2_fade_PWM	equ	04Eh	;fade PWM calculator
	channel3_fade_PWM	equ	04Fh	;fade PWM calculator
	channel4_fade_PWM	equ	050h	;fade PWM calculator
	channel1_fade_min	equ	051h	;minimum fade value
	channel2_fade_min	equ	052h	;minimum fade value
	channel3_fade_min	equ	053h	;minimum fade value
	channel4_fade_min	equ	054h	;minimum fade value
	channel1_fade_max	equ	055h	;maximun fade value
	channel2_fade_max	equ	056h	;maximun fade value
	channel3_fade_max	equ	057h	;maximun fade value
	channel4_fade_max	equ	058h	;maximun fade value
	sequence1_timer		equ	060h	;for each sequence timer
	sequence1_counter	equ	061h	;sequence number
;============================================================================
;Bit allocations
	second_flag		equ	000h	;second change flag
	msecond_flag		equ	001h	;milisecond change flag
	fade1_to_on_in_progress	equ	002h	;channel fade in progress
	fade1_to_off_in_progress equ	003h	;channel fade in progress
	fade2_to_on_in_progress	equ	004h	;channel fade in progress
	fade2_to_off_in_progress equ	005h	;channel fade in progress
	fade3_to_on_in_progress	equ	006h	;channel fade in progress
	fade3_to_off_in_progress equ	007h	;channel fade in progress
	fade4_to_on_in_progress	equ	008h	;channel fade in progress
	fade4_to_off_in_progress equ	009h	;channel fade in progress
	fade1_direction		equ	00Ah	;last time fading direction
	fade2_direction		equ	00Bh	;last time fading direction
	fade3_direction		equ	00Ch	;last time fading direction
	fade4_direction		equ	00Dh	;last time fading direction
	recording		equ	00Eh	;recording in progress
;============================================================================
	org	00h
	jmp	Main
;============================================================================
	org	03h
	jmp	External0_interrupt		;external 0 interrupt vector
;============================================================================
	org	0Bh
	jmp	TimerA_interrupt		;timer 0 interrupt vector
;============================================================================
	org	013h
	jmp	External1_interrupt		;external 1 interrupt vector
;============================================================================
	org	01Bh
	jmp	TimerB_interrupt		;timer 1 interrupt vector
;============================================================================
	org	023h				;serial interrupt vector
	jmp	Serial_interrupt		;goto serial interrup
;============================================================================
	org 	030h				;start from vector 30
Main:
        mov     SP, #01h                        ;I need R0, R1
	call	initialize_variables		;clean and preset variables
	call	Timer0_initialize		;prepare timers
	Setb	TR0				;start timer
	call	Timer1_initialize		;prepare timers
	Setb	TR1				;start timer

Loop:
	call	Timer0_process			;obviuse !
	call	Timer1_process			;obviuse !
	call	sequence1			;go for sequence
	jmp	Loop
;============================================================================
sound_configure:
	setb	sound_chip_mode6		;stay in mode 6
	clr	sound_chip_addr0		;stay in mode 6
	setb	sound_chip_PR			;high p/R# pin, play mode
	clr	recording			;I am not recording

sound_reset:
	jb	key_stop_reset, sound_reset_x
 sound_reset_it:
	setb	sound_chip_PD			;high PD pin
	mov	A, #10
	djnz	ACC,$
	clr	sound_chip_PD			;low PD pin
sound_reset_x:

sound_record:
	jb	key_record, sound_record_x1	;exit
	clr	LED_record			;set it ON
	clr	sound_chip_PD			;low PD pin
	clr	sound_chip_PR			;low p/R# pin, recorde mode
 sound_record_1:				;if user wants to recode online
	jb	key_start, sound_record_2
	setb	recording
	mov	sequence1_counter, #07
	clr	sound_chip_CE			;CE pulsed low, recorde start
	mov	A, #10
	djnz	ACC,$
	setb	sound_chip_CE
	ret
 sound_record_2:
	jnb	key_stop_reset, sound_record_x1
	jb	key_start_pause, sound_record_1	;wait for key1 press, to start recording
	jnb	key_start_pause, $
	clr	sound_chip_CE			;CE pulsed low, recorde start
	mov	A, #10
	djnz	ACC,$
	setb	sound_chip_CE
	clr	A
 sound_record_3:
	jb	key_start_pause,sound_record_3
	djnz	ACC, sound_record_3
	clr	sound_chip_CE
	mov	A, #10
	djnz	ACC,$
	setb	sound_chip_CE			;CE puslsed low, pause
sound_record_x1:
	setb	sound_chip_PR			;P/R# gose back high, redy for playback.
	setb	LED_record			;set it OFF

	jb	key_start_pause, sound_play_x
	clr	sound_chip_CE			;CE puslsed low, pause
	mov	A, #10
	djnz	ACC,$
	setb	sound_chip_CE			;CE puslsed high, countinue
sound_play_x:
	ret
;============================================================================
sequence1:
	mov	A, sequence1_counter		;get sequence number
	
sequence1_0:
	cjne	A, #00, sequence1_1		;wait for reset
	mov	channel1_fade_PWM, #00		;turn them off
	mov	channel2_fade_PWM, #00		;turn them off
	mov	channel3_fade_PWM, #00		;turn them off
	mov	channel4_fade_PWM, #00		;turn them off
	call	sound_reset_it			;reset sound chip
	inc	sequence1_counter		;sequence++
	ret

sequence1_1:
	cjne	A, #01, sequence1_2		;wait for reset
	call	sequence2			;play demostration
	call	sound_configure			;configure sound chip
	jb	recording, sequence1_1_1
	jb	key_start, sequence1_1_1	;wait for key
	inc	sequence1_counter		;sequence++
 sequence1_1_1:
	ret

sequence1_2:
	cjne	A, #02, sequence1_3		;wait for reset
	mov	channel1_fade_delay, #0FCh	;timeout
	mov	channel1_fade_max, #Max_POWER	;stop condition
	call	channel1_fade_to_on_init	;turn it on
	mov	channel2_fade_delay, #0FCh	;timeout
	mov	channel2_fade_max, #Max_POWER	;stop condition
	call	channel2_fade_to_on_init	;turn it on
	mov	channel3_fade_delay, #0FCh	;timeout
	mov	channel3_fade_max, #Max_POWER	;stop condition
	call	channel3_fade_to_on_init	;turn it on
	mov	channel4_fade_delay, #0FCh	;timeout
	mov	channel4_fade_max, #Max_POWER	;stop condition
	call	channel4_fade_to_on_init	;turn it on
	mov	sequence1_timer, #00		;reset timer
	inc	sequence1_counter		;sequence++
	ret

sequence1_3:
	cjne	A, #03, sequence1_4		;wait for reset
	jb	fade1_to_on_in_progress, sequence1_3_1
	jb	fade2_to_on_in_progress, sequence1_3_1
	jb	fade3_to_on_in_progress, sequence1_3_1
	jb	fade4_to_on_in_progress, sequence1_3_1
	inc	sequence1_counter		;sequence++
 sequence1_3_1:
	ret

sequence1_4:
	cjne	A, #04, sequence1_5		;turn all lights ON with half
	mov	channel1_fade_min, #15		;start condition
	call	channel1_fade_to_off_init	;turn it on
	mov	channel2_fade_min, #15		;start condition
	call	channel2_fade_to_off_init	;turn it on
	mov	channel3_fade_min, #15		;start condition
	call	channel3_fade_to_off_init	;turn it on
	mov	channel4_fade_min, #15		;start condition
	call	channel4_fade_to_off_init	;turn it on
	inc	sequence1_counter		;sequence++
	ret

sequence1_5:
	cjne	A, #05, sequence1_6		;wait for fade then play welcome
	jb	fade1_to_off_in_progress, sequence1_5_1
	jb	fade2_to_off_in_progress, sequence1_5_1
	jb	fade3_to_off_in_progress, sequence1_5_1
	jb	fade4_to_off_in_progress, sequence1_5_1
	inc	sequence1_counter		;sequence++
	setb	sound_chip_PD			;low PD pin
	mov	A, #10
	djnz	ACC,$
	clr	sound_chip_PD			;low PD pin
	clr	sound_chip_CE			;CE puslsed low,pause
	mov	A, #10
	djnz	ACC,$
	setb	sound_chip_CE			;CE puslsed low,pause
 sequence1_5_1:
	ret

sequence1_6:
	cjne	A, #06, sequence1_7		;wait for welcome to finish then read start key
	call	sequence3			;play demostration
	jb	sound_chip_EOM, sequence1_6_1
	jb	key_start, sequence1_6_1
	inc	sequence1_counter		;sequence++
	clr	sound_chip_CE			;CE puslsed low,pause
	mov	A, #10
	djnz	ACC,$
	setb	sound_chip_CE			;CE puslsed low,pause
 sequence1_6_1:
	ret

sequence1_7:
	cjne	A, #07, sequence1_8		;turn all lights ON with full
	mov	channel1_fade_delay, #0FAh	;timeout
	mov	channel1_fade_max, #Max_POWER	;stop condition
	call	channel1_fade_to_on_init	;turn it on
	mov	channel2_fade_delay, #0FAh	;timeout
	mov	channel2_fade_max, #Max_POWER	;stop condition
	call	channel2_fade_to_on_init	;turn it on
	mov	channel3_fade_delay, #0FAh	;timeout
	mov	channel3_fade_max, #Max_POWER	;stop condition
	call	channel3_fade_to_on_init	;turn it on
	mov	channel4_fade_delay, #0FAh	;timeout
	mov	channel4_fade_max, #Max_POWER	;stop condition
	call	channel4_fade_to_on_init	;turn it on
	mov	sequence1_timer, #00		;reset timer
	inc	sequence1_counter		;sequence++
	ret

sequence1_8:
	cjne	A, #08, sequence1_9		;wait for timer
	mov	A, sequence1_timer		;check timer
	cjne	A, #015, sequence1_8_1		;if time not reached
	inc	sequence1_counter		;sequence++
 sequence1_8_1:
	ret

sequence1_9:
	cjne	A, #09, sequence1_10		;turn two by two ON and OFF
	mov	channel1_fade_min, #00		;start condition
	call	channel1_fade_to_off_init	;turn it off
	mov	channel2_fade_min, #00		;start condition
	call	channel2_fade_to_off_init	;turn it off
	mov	channel3_fade_max, #Max_POWER	;stop condition
	call	channel3_fade_to_on_init	;turn it on
	mov	channel4_fade_max, #Max_POWER	;stop condition
	call	channel4_fade_to_on_init	;turn it on
	mov	sequence1_timer, #00		;reset timer
	inc	sequence1_counter		;sequence++
	ret

⌨️ 快捷键说明

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