一半的程序:
LIST P=16F616
#INCLUDE<P16F616.INC>
__CONFIG _BOD_ON&_IOSCFS4&_CP_OFF&_MCLRE_ON&_PWRTE_ON&_WDT_OFF&_INTOSCIO
CBLOCK 20H
COUNT3
COUNT2
COUNT1
COUNT0
ENDC
ORG 00H
NOP
NOP
NOP
GOTO MAIN
MAIN CLRF COUNT3
CLRF COUNT2
CLRF COUNT1
CLRF COUNT0
BCF STATUS,RP0 ;A口初始化
CLRF PORTA
BSF STATUS,RP0
CLRF ANSEL ;A口为数字I/O
MOVLW 028H
MOVWF TRISA ;A口<5:3>为输入 <4,2:0>为输出
BCF STATUS,RP0 ;C口初始化
CLRF PORTC
BSF STATUS,RP0
MOVLW 0FH ;C口<3:0>为模拟输入端口 <5:4>为数字I/O
MOVWF ANSEL
MOVLW 0FH ;C口<3:0>为输入 <5:4>为输出
MOVWF TRISC
BCF STATUS,RP0
LOOP BTFSC PORTC,3 ;ON/OFF按键是否有按下
GOTO NOPUSH ;ON/OFF按键没有按下
BTFSC COUNT3,0 ;ON/OFF按键按下,判断马达是运转还是停止
GOTO STOPMOTOR ;马达运转,则停止马达运转
BTFSS PORTC,0 ;马达停止,判断液面开关是ON/OFF
GOTO LOOP ;液面开关ON
BTFSC PORTA,5 ;液面开关OFF,判断温度保护是否开启
GOTO TIMER ;温度保护没有开启,去检测拨码开关状态
BSF PORTC,4 ;温度保护开启,报警,点亮ALARM LED
GOTO LOOP
NOPUSH BTFSS COUNT3,0 ;判断马达是运转还是停止
GOTO LOOP ;马达停止
BTFSS PORTC,0 ;判断液面开关是ON/OFF
GOTO STOPMOTOR ;液面开关ON,停止马达运转
BTFSS PORTA,5 ;液面开关OFF,判断温度保护是否开启
GOTO ALARM ;温度保护开启,报警
BCF PORTC,4 ;报警清0
GOTO LOOP
ALARM BSF PORTC,4 ;报警,点亮ALARM LED
STOPMOTOR BCF STATUS,RP0
CLRF T2CON ;关闭TIMER2
BSF STATUS,RP0
CLRF PR2 ;PWM周期清0
BCF STATUS,RP0
CLRF CCP1CON ;关闭PWM输出
CLRF CCPR1L ;清占空比
BCF PIR1,1 ;TEMER2中断标志位清0
BCF PORTC,5 ;PWM端口输出清0
BCF COUNT3,0
CLRF T1CON ;TIMER1清0
CLRF TMR1L
CLRF TMR1H
BCF PIR1,0
CLRF COUNT2
CLRF COUNT1
CLRF COUNT0
GOTO LOOP
TIMER BCF PORTC,4 ;报警清0,熄灭ALARM LED
BTFSC PORTC,2 ;拨码开关S2是ON还是OFF
GOTO S1 ;S2是OFF,判断拨码开关S1是ON还是OFF
BTFSC PORTC,1 ;S2是ON,判断拨码开关S1是ON还是OFF
GOTO SET5MIN ;S1是OFF,转去5分钟定时程序
CALL RUNMOTOR ;S1是ON,无定时运转马达
GOTO LOOP
S1 BTFSC PORTC,1
GOTO LOOP ;S1是OFF,马达不动作,返回住程序
GOTO SET10MIN ;S1是ON,转去10分钟定时程序 |