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

📄 aqua ok.asm

📁 基于pic的DS1302串行实时时钟程序
💻 ASM
📖 第 1 页 / 共 4 页
字号:
ecrit_menu_manu
	call    RELACHE
	movlw   01h                     ;clear display
	call    LCDCMD                  ;
	movlw   7Eh
	call    LCDCHAR
	movlw   HIGH(MENUTABLE)
	movwf   PCLATH
	movf    MENUPOS,W
	movwf   DONNEE
	call    MENUTABLE
	clrf    PCLATH
	call    LCDSTR
	movlw   0Eh                     ;ecriture de A - X - 0
	call    LCDSETADR
	movlw   ' '
	call    LCDCHAR
	movf    CPT,W
	andwf   CMDMANU,W
	movlw   'A'
	btfsc   STATUS,Z
	goto    fin_test_auto1
	movf    CPT,W
	andwf   SORTIES,W
	movlw   'X'
	btfsc   STATUS,Z
	movlw   '0'
fin_test_auto1
	call    LCDCHAR
	movlw   41h
	call    LCDSETADR
	movlw   HIGH(MENUTABLE)
	movwf   PCLATH
	incf    MENUPOS,W
	call    MENUTABLE
	clrf    PCLATH
	andlw   0FFh
	btfss   STATUS,Z                ;test si fin de menu
	goto    fin_menu_manu
	movlw   HIGH(MENUTABLE)
	movwf   PCLATH
	movf    TEMP2,W
	call    MENUTABLE
	clrf    PCLATH
fin_menu_manu
	call    LCDSTR
	movlw   4Eh                     ;ecriture de A - X - 0
	call    LCDSETADR
	movlw   ' '
	call    LCDCHAR
	rlf     CPT,W
	andwf   CMDMANU,W
	movlw   'A'
	btfsc   STATUS,Z
	goto    fin_test_auto2
	rlf     CPT,W
	andwf   SORTIES,W
	movlw   'X'
	btfsc   STATUS,Z
	movlw   '0'
fin_test_auto2
	call    LCDCHAR
attente_menu_manu
	clrwdt
	btfsc   PB,1                            ;suivant
	goto    menu_manu_suivant
	btfss   PB,2                            ;enter
	goto    attente_menu_manu
	call    RELACHE
	movlw   23h                             ;Sortie ?
	subwf   MENUPOS,W
	btfsc   STATUS,Z
	return
	movf    CPT,W
	xorwf   CMDMANU
	goto    ecrit_menu_manu
menu_manu_suivant
	rlf     CPT
	btfss   STATUS,C
	goto    test_fin_manu
	bsf     FLAGS,1                         ;on passe sur le composant 1

test_fin_manu
	incf    MENUPOS
	movlw   HIGH(MENUTABLE)
	movwf   PCLATH
	movf    MENUPOS,W
	call    MENUTABLE
	clrf    PCLATH
	andlw   0FFh
	btfss   STATUS,Z                ;test si fin de menu
	goto    ecrit_menu_manu
	movf    TEMP2,W
	movwf   MENUPOS
	goto    ecrit_menu_manu

;****************************************************************************
;       DEC2BCD = conversion de decimal (W) vers BCD (DONNEE)
;****************************************************************************

DEC2BCD
	movwf   TEMP1
	clrf    TEMP2
	clrf    DONNEE
	movlw   d'10'
continue_compt
	subwf   TEMP1
	btfss   STATUS,C
	goto    stop_compt
	incf    TEMP2
	goto    continue_compt
stop_compt
	swapf   TEMP2,W
	movwf   DONNEE
	movf    TEMP1,W
	addlw   d'10'
	iorwf   DONNEE
	return

;****************************************************************************
;       TEMPERATURE = lecture de la temperature
;****************************************************************************

TEMPERATURE
	bsf     STATUS,RP0              ;bank 1
	bsf     SSPCON2,SEN             ;start
	bcf     STATUS,RP0              ;bank 0
temp_start
	btfss   PIR1,SSPIF
	goto    temp_start
	movlw   b'10000001'             ;adresse thermometre
	movwf   SSPBUF
	bcf     PIR1,SSPIF
temp_adr
	btfss   PIR1,SSPIF
	goto    temp_adr
	btfsc   SSPCON2,ACKSTAT         ;si not ack
	return
	movlw   04h
	call    TEMPO
	bsf     STATUS,RP0
	bsf     SSPCON2,RCEN            ;reception
	bcf     STATUS,RP0
	bcf     PIR1,SSPIF
temp_lecture
	btfss   PIR1,SSPIF
	goto    temp_lecture
	movf    SSPBUF,W                ;lecture
	movwf   TEMPERATURE_ENTIER
	movlw   04h
	call    TEMPO
	bsf     STATUS,RP0
	bcf     SSPCON2,ACKDT           ;ack
	bsf     SSPCON2,ACKEN
	bcf     STATUS,RP0
	bcf     PIR1,SSPIF
temp_ack
	btfss   PIR1,SSPIF
	goto    temp_ack
	movlw   04h
	call    TEMPO
	bsf     STATUS,RP0
	bsf     SSPCON2,RCEN            ;reception
	bcf     STATUS,RP0
	bcf     PIR1,SSPIF
temp_lecture2
	btfss   PIR1,SSPIF
	goto    temp_lecture2
	movf    SSPBUF,W                ;lecture
	movwf   TEMPERATURE_DECIMALE
	movlw   04h
	call    TEMPO
	bsf     STATUS,RP0
	bsf     SSPCON2,ACKDT           ;not ack
	bsf     SSPCON2,ACKEN
	bcf     STATUS,RP0
	bcf     PIR1,SSPIF
temp_not_ack
	btfss   PIR1,SSPIF
	goto    temp_not_ack
	movlw   04h
	call    TEMPO
	bsf     STATUS,RP0              ;bank 1
	bsf     SSPCON2,PEN             ;stop
	bcf     STATUS,RP0              ;bank 0
	bcf     PIR1,SSPIF
temp_stop
	btfss   PIR1,SSPIF
	goto    temp_stop
	bcf     PIR1,SSPIF
	movf    TEMPERATURE_DECIMALE,W
	call    DEC2BCD
	movf    DONNEE,W
	movwf   TEMPERATURE_DECIMALE
	movf    TEMPERATURE_DECIMALE,W
	andlw   0Fh
	sublw   d'05'
	clrf    TEMP1
	btfss   STATUS,C
	incf    TEMP1
	swapf   TEMPERATURE_DECIMALE,W
	andlw   0Fh
	addwf   TEMP1,W
	movwf   TEMPERATURE_DECIMALE
	sublw   d'10'
	btfss   STATUS,Z
	return
	incf    TEMPERATURE_ENTIER
	clrf    TEMPERATURE_DECIMALE
	return

;****************************************************************************
;       AFF_TEMPERATURE = affichage de la temperature
;****************************************************************************

AFF_TEMPERATURE
	clrw
	call    LCDSETADR
	movf    TEMPERATURE_ENTIER,W
	call    LCDDEC
	movlw   "."
	call    LCDCHAR
	movf    TEMPERATURE_DECIMALE,W
	addlw   d'48'                           ;passage en ascii
	call    LCDCHAR
	movlw   0DFh                            ;"?
	call    LCDCHAR
	movlw   "C"
	call    LCDCHAR
	return

;****************************************************************************
;       SORTIE_LIBRE = gestion de la sortie libre avec PB1
;               activation si appui, desactivation si relache
;               si appui > 2s, interrupteur normal
;****************************************************************************

SORTIE_LIBRE
	btfsc   FLAGS,6                 ;l'appui a dur?plus de 2s ?
	goto    interrupteur            ;oui
	btfss   PB,1                    ;on appuie toujours
	goto    arret_sortie
	btfsc   FLAGS,5                 ;premier appui ?
	goto    pas_premier             ;non
	bsf     FLAGS,5
	bsf     SORTIES,7
	call    ECRIS_I2C0
	movlw   49h
	call    LCDSETADR
	movlw   "X"
	call    LCDCHAR
	movlw   60h
	movwf   MAX
	movf    SECONDES,W
	movwf   DONNEE
	call    INCREMENTE
	call    INCREMENTE
	movf    DONNEE,W
	movwf   FIN_X
	return
pas_premier
	movf    SECONDES,W
	subwf   FIN_X,W
	btfsc   STATUS,Z
	bsf     FLAGS,6
	return
interrupteur
	btfsc   FLAGS,4
	goto    deja_relache
	btfsc   PB,1
	return
	bsf     FLAGS,4
deja_relache
	btfss   PB,1
	return
arret_sortie
	bcf     FLAGS,5                 ;arret
	bcf     FLAGS,4
	bcf     FLAGS,6
	btfss   SORTIES,7
	return
	bcf     SORTIES,7
	call    ECRIS_I2C0
	movlw   49h
	call    LCDSETADR
	movlw   " "
	call    LCDCHAR
	return

;****************************************************************************
;       REGUL_TEMPERATURE = regulation de la temperature
;****************************************************************************

REGUL_TEMPERATURE
	movlw   TEMP_VISEE + 2
	call    LIS_EEPROM2
	movf    TEMPERATURE_ENTIER,W
	subwf   DONNEE,W
	btfsc   STATUS,Z                        ;temp_entier = temp_visee_entier, on teste la decimale
	goto    test_decimale
	btfsc   STATUS,C                        ;temp_entier > temp_visee
	goto    temp_faible
	btfss   SORTIES,6
	return
	bcf     SORTIES,6
	bsf     FLAGS,7
	return
test_decimale
temp_faible
	btfsc   SORTIES,6
	return
	bsf     SORTIES,6
	bsf     FLAGS,7
	return


;****************************************************************************
;       programme principal
;****************************************************************************

MAIN
	clrwdt
	bsf     STATUS,RP0              ;bank 1
	movlw   b'11010101'             ;timer 0 prescaler 64
	movwf   OPTION_REG
	movlw   0FFh                    ;desactivation des
	movwf   ADCON1                  ;entrees analogiques
	movlw   78h                     ;port B
	movwf   TRISB
	clrf    TRISD                   ;port D, outputs
	clrf    TRISE                   ;port E, outputs
	movlw   d'127'                  ;vitesse clock I2C
	movwf   SSPADD                  ;20 kHz
	bcf     STATUS,RP0              ;bank 0
	bsf     PORTB,7
	bsf     INTCON,T0IE
	bsf     INTCON,GIE
	movlw   b'00101000'             ;I2C master mode
	movwf   SSPCON                  ;configuration I2C
	clrf    PB
	clrf    PORTE
	clrf    FLAGS
	clrf    EXDONNEE
	clrf    SORTIES
	clrf    SORTIES1
	clrf    REMPREAC
	clrf    M_REAC
	clrf    H_REAC
	clrf    CMDMANU
	clrf    CPT_MIN
	bsf     SORTIES,6
	call    LCDINIT
	call    LIS_HEURE
	call    AFF_HEURE
debut
	bsf     FLAGS,0
	call    LIS_EEPROM
	movlw   01h                     ;clear display
	call    LCDCMD                  ;
	call    BRASSAGE
boucle
	clrwdt
	movf    PB,W
	andlw   07h
	btfsc   STATUS,Z                ;doit on allumer le retroeclairage
	goto    pas_retro               ;non
	bcf     PORTB,7                 ;retroeclairage
	bcf     STATUS,C
	movf    SECONDES,W
	addlw   30h                     ;activer pendant 30s
	movwf   FINRETRO
	movlw   60h
	subwf   FINRETRO,W
	btfsc   STATUS,C
	movwf   FINRETRO
pas_retro
	call    SORTIE_LIBRE
	movf    SECONDES,W
	movwf   EXSECONDES
	movlw   b'10000001'             ;secondes
	call    DS1302
	movf    DONNEE,W
	andlw   7Fh
	movwf   SECONDES
	btfsc   FLAGS,0
	goto    minute_ecoulee          ;forcage minute ecoulee ?
	andlw   0FFh
	btfss   STATUS,Z                ;secondes = 0 ?
	goto    pas_min_ecoulee
	movf    EXSECONDES,W
	sublw   59h
	btfss   STATUS,Z                ;exsecondes = 59 ?
	goto    pas_min_ecoulee
minute_ecoulee
	bcf     FLAGS,0
	call    AFF_HEURE
	call    TEMPERATURE
	call    AFF_TEMPERATURE
	call    REGUL_TEMPERATURE
	movf    SECONDES,F
	btfsc   STATUS,Z
	call    LIS_I2C
	btfss   FLAGS,2                 ;forcage reacteur ?
	goto    react_normal            ;non
	call    REACT_REMP
	goto    suite_test
react_normal
	call    REACT
suite_test
	movlw   L_BLANCHE
	call    TEST_HEURE
	andlw   0FFh
	btfsc   STATUS,Z                ;marche L_BLANCHE ?
	goto    arret_blanche           ;non
	btfsc   SORTIES,0               ;L_BLANCHE deja allumee ?
	goto    test_bleue              ;oui
	bsf     SORTIES,0               ;non : l'allumer
	bsf     FLAGS,7
	goto    test_bleue
arret_blanche
	btfss   SORTIES,0               ;L_BLANCHE deja eteinte ?
	goto    test_bleue              ;oui
	bcf     SORTIES,0               ;non : l'eteindre
	bsf     FLAGS,7
test_bleue
	movlw   L_BLEUE
	call    TEST_HEURE
	andlw   0FFh
	btfsc   STATUS,Z                ;marche L_BLEUE ?
	goto    arret_bleue             ;non
	btfsc   SORTIES,1               ;L_BLEUE deja allumee ?
	goto    fin_lumiere             ;oui
	bsf     SORTIES,1               ;non : l'allumer
	bsf     FLAGS,7
	goto    fin_lumiere
arret_bleue
	btfss   SORTIES,1               ;L_BLEUE deja eteinte ?
	goto    fin_lumiere             ;oui
	bcf     SORTIES,1               ;non : l'eteindre
	bsf     FLAGS,7
fin_lumiere
	btfsc   FLAGS,7                 ;Changement sur le bus 0 ?
	call    ECRIS_I2C0
	movlw   42h
	call    LCDSETADR
	movlw   " "
	btfsc   SORTIES,0
	movlw   "B"
	call    LCDCHAR
	movlw   " "
	btfsc   SORTIES,1
	movlw   "b"
	call    LCDCHAR
	movlw   48h
	call    LCDSETADR
	movlw   " "
	btfsc   SORTIES,6
	movlw   "C"
	call    LCDCHAR
	movlw   " "
	btfsc   SORTIES,7
	movlw   "X"
	call    LCDCHAR
	movlw   " "
	btfsc   SORTIES1,0
	movlw   "R"
	call    LCDCHAR
	movlw   " "
	btfsc   FLAGS,2                 ;remplissage
	movlw   "r"
	call    LCDCHAR
	movlw   " "
	btfsc   SORTIES1,2
	movlw   "O"
	call    LCDCHAR
	movf    MINUTES,W
	andlw   0FFh                    ;une heure ecoulee ?
	btfsc   STATUS,Z
	call    BRASSAGE
	btfss   FLAGS,2                 ;pompe de remplissage ?
	goto    pas_rempliss            ;non
	call    REMPLISS_M
pas_min_ecoulee
	btfss   FLAGS,2                 ;pompe de remplissage ?
	goto    pas_rempliss            ;non
	call    REMPLISS_S              ;oui
pas_rempliss
	movf    SECONDES,W
	subwf   FINRETRO,W
	btfsc   STATUS,Z
	bsf     PORTB,7                 ;arret retroeclairage
	btfss   PB,0
	goto    boucle
	call    RELACHE
	bcf     PORTB,7                 ;retroeclairage
	call    MENU_UTIL
	bsf     PORTB,7                 ;arret retroeclairage
	goto    debut

	org     0800h

;****************************************************************************
;       MSG == messages utilises dans les Menus
;****************************************************************************

MSG
	addwf   PCL
	DT      "Commandes manu",0      ;00h
	DT      "Reglages",0            ;0Fh
	DT      "Mesure pH",0           ;18h
	DT      "Sortie",0              ;22h
	DT      "A propos...",0         ;29h
	DT      "date / heure",0        ;35h
	DT      "Reset",0               ;42h
	DT      "Lumiere blanche",0     ;48h
	DT      "Lumiere bleue",0       ;58h
	DT      "Reacteur calc.",0      ;66h
	DT      "Remplissage",0         ;75h
	DT      "Pompes brassage",0     ;81h
	DT      "Pompe 1",0             ;91h
	DT      "Pompe 2",0             ;99h
	DT      "Pompe 3",0             ;A1h
	DT      "Pompe 4",0             ;A9h
	DT      "Temperature",0         ;B1h
	DT      "Libre",0               ;BDh
	DT      "Osmoseur",0            ;C3h
	DT      "Etalonage",0           ;CCh
	DT      "Reacteur calc.2",0     ;D6h
	DT      "Heures Rempliss",0     ;E6h

	org     0900h

;****************************************************************************
;       MSG2 == messages
;****************************************************************************

MSG2
	addwf   PCL
	DT      "Julien Schmitt",0      ;00h
	DT      "V1.0  19/06/2000",0    ;0Fh
	DT      "Menu utilisateur",0    ;20h
	DT      "****************",0    ;31h
	DT      "jour",0                ;42h
	DT      "mois",0                ;47h
	DT      "annee",0               ;4Ch
	DT      "heure",0               ;52h
	DT      "minutes",0             ;58h
	DT      "Aquamate",0            ;60h
	DT      "Etes vous sur ?",0     ;69h
	DT      "OUI",0                 ;79h
	DT      "NON",0                 ;7Dh
	DT      "debut",0               ;81h
	DT      "fin",0                 ;87h
	DT      "chaque",0              ;8Bh
	DT      "pendant",0             ;92h
	DT      "min.",0                ;9Ah
	DT      "sec.",0                ;9Fh

	org     0A00h

;****************************************************************************
;       MENUTABLE == gestion des messages du menu
;****************************************************************************

MENUTABLE
	addwf   PCL
	DT      00h,0Fh,18h,29h,22h,0                    ;menu principal : 00h
	DT      35h,48h,58h,66h,0D6h,75h,81h,0E6h,0B1h,42h,22h,0   ;menu reglages  : 06h
	DT      91h,99h,0A1h,0A9h,22h,0                  ;reglage des pompes : 12h
	DT      48h,58h,91h,99h,0A1h,0A9h,0B1h,0BDh,66h,75h,0C3h,22h,0 ;Menu Manu : 18h

	END



⌨️ 快捷键说明

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