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

📄 9222asm.asm

📁 用78F9222做的电热水器程序
💻 ASM
📖 第 1 页 / 共 4 页
字号:

;--------------------------------
;-      MACRO   DEFINITION      -
;--------------------------------
PUSH_STACK      MACRO
                PUSH    AX
                PUSH    HL
                PUSH    BC                                                                      
                PUSH    DE
                ENDM
POP_STACK       MACRO
                POP     DE
                POP     BC
                POP     HL
                POP     AX
                ENDM     


;--------------------------------
;-      I/O DEFINE              -
;-------------------------------- 
key             EQU     P2.0     ;
water_tem       EQU     P2.1     ;
dig7            EQU     P2.2
dig6            EQU     P2.3

remote          EQU     P3.0    ;input
buzzer          EQU     P3.1    ;output
;NC             EQU	P3.4	;input  

clk             EQU     P4.0    ;
data            EQU     P4.1    ;o
dig1            EQU     P4.2    ;
dig2            EQU     P4.3    
dig3            EQU     P4.4    
dig4            EQU     P4.5

relay	        EQU	P12.3	;output

dig5            EQU     P13.0

;--------------------------------
;-      SYMBOL  DECLARATION     -
;--------------------------------
ram_start	EQU	0FE7FH
ram_end		EQU	0FEFFH
stack		EQU	0FEFFH 
display_address EQU     0FEE4H
key_channel     EQU     0
wt_channel      EQU     1  
add_key_high    EQU     150;140
add_key_low     EQU     120;130
sub_key_high    EQU     183;173
sub_key_low     EQU     153;163
onoff_key_high  EQU     210;200
onoff_key_low   EQU     180;190
set_key_high    EQU     101;91 
set_key_low     EQU     71;81 
run_night_key_high      EQU     236;226
run_night_key_low       EQU     206;216 
onoff_code      EQU     10000000B
set_code        EQU     10010000B
add_code        EQU     10001000B
sub_code        EQU     10001100B
run_night_code  EQU     10000100B 
custom_code     EQU     0FF00H
head_c_high	EQU	490        ;14141-4.19MHz,16875-5MHz,27000-8MHz
head_c_low	EQU	440        
dummy_head_c_high       EQU     470         ;11784,14062,22500
dummy_head_c_low        EQU     430        
one_c_high      EQU     100       ;2346,2800,4480
one_c_low       EQU     65
zero_c_high     EQU     60        ;1173,1400,2240
zero_c_low      EQU     25          		



;--------------------------------
;-      RAM  DECLARATION       	-
;--------------------------------
DATA	DSEG	at	0FE80H  
sum:                    DS      2
no_key_pressed_c:       DS      2
time_c:                 DS      2
t_3s:                   DS      2 
t_8s:                   DS      2
receive_c:              DS      2

display_buffer1:        DS      1   ;0 0 0 0 0 0 0 0
display_buffer2:        DS      1   ;- G F E D C B A
display_buffer3:        DS      1
display_buffer4:        DS      1
display_buffer5:        DS      1
display_buffer6:        DS      1
display_buffer7:        DS      1    
flash_c:                DS      1
flash_c1:               DS      1
loop_c:                 DS      1	;counter of the main loop 
time_s:                 DS      1        
time_m:                 DS      1
time_h:                 DS      1
settime_on_m:           DS      1
settime_on_h:           DS      1
settime_off_m:          DS      1
settime_off_h:          DS      1 
set_temp:               DS      1       ;setting temperature  
set_buffer:             DS      1 
high_bit_number:        DS      1
low_bit_number:         DS      1
display_high_bit:       DS      1
display_low_bit:        DS      1 
ad_c:                   DS      1       ;counter of the A/D convertion 
average_c:              DS      1       
min:                    DS      1
max:                    DS      1  
key_code:               DS      1 
key_code_buffer:        DS      1
key_ad_new:             DS      1
key_ad_old:             DS      1
key_pressed_c:          DS      1      
speedup_c:              DS      1
wt_buffer:              DS      1
wt_ad_new:              DS      1
wt_ad_old:              DS      1
wt:                     DS      1
wt_old:                 DS      1 
wt_display_buffer:      DS      1 
display_data_c:         DS      1       
display_data_bit_c:     DS      1 
two_degree_per8s_c:     DS      1  
ring_c:                 DS      1 
ring_c1:                DS      1
three_times:            DS      1 
receive_buffer:         DS      1
data_buffer:            DS      1
receive_buffer1:        DS      1
receive_buffer_low:     DS      1  
bit_c:                  DS      1 
error_c:                DS      1 
receive_bit_c:          DS      1
display_c:              DS      1 
delay_c:                DS      1 
over_t_error_c:         DS      1
sensor_error_c:         DS      1
       


com:    DS      1
dig_1   EQU     com.0
dig_2   EQU     com.1
dig_3   EQU     com.2
dig_4   EQU     com.3
dig_5   EQU     com.4
dig_6   EQU     com.5
dig_7   EQU     com.6
                                 
run_mode:       DS      1
on_off_f        EQU     run_mode.0                                 
keep_tem_f      EQU     run_mode.1
run_in_night_f  EQU     run_mode.2
set_turnon_f    EQU     run_mode.3
set_turnoff_f   EQU     run_mode.4    
                                 
error_f:        DS      1
over_tem_f      EQU     error_f.0
sensor_error_f  EQU     error_f.1
heat_no_water_f EQU     error_f.2 

set_flag:       DS      1
tem_set_f       EQU     set_flag.0
time_h_set_f    EQU     set_flag.1
time_m_set_f    EQU     set_flag.2
turnon_h_set_f  EQU     set_flag.3
turnon_m_set_f  EQU     set_flag.4
turnoff_h_set_f EQU     set_flag.5
turnoff_m_set_f EQU     set_flag.6

flag:                   DS      1
ad_first_f              EQU     flag.0  
set_by_remote_f         EQU     flag.1
first_pressed_f         EQU     flag.2
more_key_pressed_f      EQU     flag.3 
ring_f                  EQU     flag.4 
ring_3times_f           EQU     flag.5
AD_sample_end           EQU     flag.6
relay_f                 EQU     flag.7


flag0:                  DS      1
head_code_f             EQU     flag0.0
custom_code_f           EQU     flag0.1
data_f                  EQU     flag0.2
word_end_f              EQU     flag0.3                                         
receive_start_f         EQU     flag0.4
byte_end_f              EQU     flag0.5
low_byte_f              EQU     flag0.6
Receive_bit_error_f	EQU	flag0.7
                                  
flag1:          DS      1
value_change_f  EQU     flag1.0
turnon_f        EQU     flag1.1
turnoff_f       EQU     flag1.2
bit_start_f     EQU     flag1.3 
wt_old_f        EQU     flag1.4
relay_on_f      EQU     flag1.5


                 
    

;--------------------------------
;- VECTOR TABLE                 -
;--------------------------------
INT0	CSEG	at		0000H
		DW		Start
INT1	CSEG	at		0006H
INTLVI:		DW		Start
INT2	CSEG	at		0008H
INTP0:		DW		Receive
INT3	CSEG	at		000AH
INTP1:		DW		Unused
INT4	CSEG	at		000CH
INTTMH1:	DW		Display_buzzer
INT5	CSEG	at		000EH
INTTM000:	DW		Unused
INT6	CSEG	at		0010H
INTTM010:	DW		Unused
INT7	CSEG	at		0012H
INTAD:		DW		AD_sample
INT8	CSEG	at		0014H
INTFLC:		DW		Unused
INT9	CSEG	at		0016H
INTP2:		DW		Unused
INT10	CSEG	at		0018H
INTP3:		DW		Unused
INT11	CSEG	at		001AH
INTTM80:	DW		Timer
INT12	CSEG	at		001CH
INTSRE6:	DW		Unused
INT13	CSEG	at		001EH
INTSR6:		DW		Unused
INT14	CSEG	at		0020H
INTST6:		DW		Unused
;================================ 
OPT      DSEG   at      80H		;
OPTION:        DB	10010000b	;	
        				



PROG	CSEG	at      82H

Start:
	DI 
HDInitial:
	MOV	PCC,#0
	MOV     PPCC,#0
	MOV	IF0,#00
        MOV 	IF1,#00
        MOV	MK0,#0FFH
        MOV     MK1,#0FFH 
        MOVW	AX,#stack
	MOVW	SP,AX
	MOVW	HL,#ram_start
Ram_clear:
	MOV     A,#0
        MOV     [HL],A
   	INCW    HL
        MOVW    AX,HL
        CMPW	AX,#ram_end
        BC      $Ram_clear  
SFR_initial:
        MOV	PM2,#11110011B
        MOV	PM3,#11111101B
        MOV	PM4,#11000000B
        MOV	PM12,#11110001B
        MOV     PMC2,#00000011B
        MOV	PU2,#00001111B
        MOV	PU3,#00000011B
        MOV	PU4,#00111111B
        MOV	PU12,#00001000B 
        MOV     WDTM,#011001111B        ;l
        MOV     ADM,#00111001B
        MOV     ADS,#key_channel 
        MOV     CR80,#249               ;interval time is 2ms
        MOV     TMHMD1,#00010000B                     
        MOV     CMP01,#49              ;invterval time is 25us
        MOV     PRM00,#1                ;f=fxp/4
        MOVW    AX,#0FFFFH 
        MOVW    CR000,AX
Ram_initial:  
        MOV     ad_c,#6
        MOV     average_c,#3
        MOV     display_data_bit_c,#9 
        MOV     set_temp,#75  
        MOV     error_c,#10
        MOV     set_flag,#10000000b 
        MOV     display_buffer1,#0FFH
        MOV     display_buffer2,#0FFH
        MOV     display_buffer3,#0FFH
        MOV     display_buffer4,#0FFH
        MOV     display_buffer5,#0FFH
        MOV     display_buffer6,#0FFH
        MOV     display_buffer7,#0FFH 
        SET1    ring_f
        MOV     com,#1 
        CLR1    ADMK
        CLR1    PMK0
        CLR1    TMMKH1
        CLR1    TMMK80 
        SET1    ADCS            ;A/D convertion start    
        SET1    TCE80               
        SET1    TMHE1
        EI
Main_loop: 
        MOV     WDTE,#0ACH      ;
        CMP     loop_c,#5       ;the loop cycle is about 10ms
        BC      $Main_loop
        MOV     loop_c,#0  
        MOV     A,error_f
        CMP     A,#0
        BZ      $Loop
        CALL    !Error_deal
        BR      loop1
Loop:  
        CALL    !AD_convert      
        CALL    !Key_remote_deal 
        CALL    !Run_control
loop1:
        CALL    !Buzzer_deal
        CALL    !Pre_display
        BR      Main_loop
;================================
;-	SUB-program	        -
;================================
AD_convert: 
        BT      AD_sample_end,$AD_convert0
        BR      Error_monitor_r
AD_convert0:               
        CLR1    AD_sample_end    
        SET1    ADCS
        MOV     A,key_ad_new
        CMP     A,key_ad_old
        BZ      $AD_convert1
        MOV     key_ad_old,A
        BR      AD_convert2
AD_convert1: 
        MOV     key_code_buffer,A
AD_convert2: 
        MOV     A,wt_ad_new
        CMP     A,wt_ad_old
        BZ      $Error_monitor
        MOV     wt_ad_old,A
        BR      Error_monitor_r
Error_monitor:               
        CMP     A,#88
        BNC     $Sensor_detect 
Sensor_error:  
        MOV     A,sensor_error_c
        CMP     A,#3
        BNC     $Sensor_error0
        INC     sensor_error_c
        BR      Error_monitor_r
Sensor_error0:
        SET1    sensor_error_f
        CALL    !Error_deal
        BR      Error_monitor_r
Sensor_detect:
        CMP     A,#253 
        BC      $Over_tem_detect
        BR      Sensor_error
Over_tem_detect:
        MOV     sensor_error_c,#0
        MOVW    HL,#WT_TABLE            
        SUB     A,#88
        CALL    !Check_table
        CMP     A,#90
        BC      $Heat_no_water_detect
        MOV     A,over_t_error_c
        CMP     A,#3
        BNC     $Over_tem_detect0
        INC     over_t_error_c
        BR      Error_monitor_r
Over_tem_detect0:
        SET1    over_tem_f
        CALL    !Error_deal
        BR      Error_monitor_r
Heat_no_water_detect:          
        MOV     over_t_error_c,#0
        MOV     wt,A
        MOV     A,delay_c
        CMP     A,#100
        BNC     $Wt_display_update
        INC     delay_c
        BR      Heat_no_water_detect00
Wt_display_update:
        MOV     delay_c,#0
        MOV     A,wt
        MOV     wt_display_buffer,A
Heat_no_water_detect00:          
        MOV     A,two_degree_per8s_c
        CMP     A,#4
        BC      $Heat_no_water_detect0
        SET1    heat_no_water_f
        CALL    !Error_deal
        BR      Error_monitor_r
Heat_no_water_detect0:
        BF      wt_old_f,$Heat_no_water_detect1            
        MOVW    AX,t_8s 
        CMPW    AX,#400
        BNC     $Heat_no_water_detect2
        INCW    AX
        MOVW    t_8s,AX
        BR      Error_monitor_r
Heat_no_water_detect1:
        SET1    wt_old_f 
        MOV     A,wt
        MOV     wt_old,A  
        MOVW    AX,#0
        MOVW    t_8s,AX
        BR      Error_monitor_r
Heat_no_water_detect2:
;        MOVW    AX,#0
;        MOVW    t_8s,AX
;        CLR1    wt_old_f
        MOV     A,wt
        CMP     A,wt_old
        BNC     $Heat_no_water_detect3
        MOV     two_degree_per8s_c,#0
        BR      Heat_no_water_detect1
Heat_no_water_detect3:
        SUB     A,wt_old
        CMP     A,#1
        BNC     $Heat_no_water_detect4 
        MOV     two_degree_per8s_c,#0
        BR      Heat_no_water_detect1
Heat_no_water_detect4:
        INC     two_degree_per8s_c 
        BR      Heat_no_water_detect1 
Error_monitor_r:
        RET
;--------------------------------
Error_deal:
        CLR1    relay
        DBNZ    error_c,$Error_deal_r
        MOV     error_c,#100
        SET1    ring_f
Error_deal_r:
        RET
;--------------------------------
Run_control:
        BF      on_off_f,$Run_stop
        BF      keep_tem_f,$Heat_control
Keep_tem_control:
        MOV     A,wt
        ADD     A,#8
        CMP     A,set_temp
        BC      $Heaten      
        BR      Run_stop
Heat_control:
        MOV     A,wt
        CMP     A,set_temp
        BC      $Heaten
        SET1    keep_tem_f   
Run_stop:  
        CLR1    relay
        BR      Run_control_r
Heaten:                   
        CLR1    keep_tem_f 
        SET1    relay
Run_control_r:
        RET              
;--------------------------------
Key_remote_deal:
        MOV     A,key_code_buffer
        CMP     A,#onoff_key_high
        BNC     $Set_judge
        CMP     A,#onoff_key_low
        BC      $Set_judge
        MOV     key_code,#onoff_code
        CALL    !Key_pressed_deal 
        BR      Key_remote_deal0
Set_judge:
        CMP     A,#set_key_high
        BNC     $Add_key_judge
        CMP     A,#set_key_low
        BC      $Add_key_judge
        MOV     key_code,#set_code
        CALL    !Key_pressed_deal
        BR      Key_remote_deal0
Add_key_judge:
        CMP     A,#add_key_high
        BNC     $Sub_key_high
        CMP     A,#add_key_low
        BC      $Sub_key_high
        MOV     key_code,#add_code
        CALL    !Key_pressed_deal
        BR      Key_remote_deal0
Sub_key_high:
        CMP     A,#sub_key_high
        BNC     $Run_in_night_judge
        CMP     A,#sub_key_low
        BC      $Run_in_night_judge
        MOV     key_code,#sub_code
        CALL    !Key_pressed_deal
        BR      Key_remote_deal0
Run_in_night_judge:
        CMP     A,#run_night_key_high
        BNC     $No_key_press_judge
        CMP     A,#run_night_key_low
        BC      $No_key_press_judge   

⌨️ 快捷键说明

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