;***************************************************************************** ; * ; NOM: RS232 * ; Date: 23/07/2004 * ; Version: 1.0 * ; Circuit: Platine d'expérimentation * ; Auteur: Leaky * ; * ;***************************************************************************** ; * ; Fichier requis: P16F876.inc * ; * ;***************************************************************************** LIST p=16F876 ; Définition de processeur #include ; fichier include __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_ON & _HS_OSC ;***************************************************************************** ; ASSIGNATIONS SYSTEME * ;***************************************************************************** ;***************************************************************************** ; ASSIGNATIONS SYSTEME * ;***************************************************************************** ; REGISTRE OPTION_REG (configuration) ; ----------------------------------- OPTIONVAL EQU B'10001111' ; RBPU b7 : 1= Résistance rappel +5V hors service ; PSA b3 : 1= Assignation prédiviseur sur Watchdog ; PS2/PS0 b2/b0 valeur du prédiviseur = 256 LCD_DATA EQU PORTB ; LCD data lines interface LCD_DATA_TRIS EQU TRISB LCD_CTRL EQU PORTA ; LCD control lines interface ; PORTA bits LCD_E EQU 0 ; LCD Enable control line LCD_RW EQU 1 ; LCD Read/Write control line LCD_RS EQU 2 ; LCD Register-Select control line BUTTON EQU 3 ; PORTB bits DB7 EQU 0 ; LCD dataline 7 (MSB) DB6 EQU 1 ; LCD dataline 6 DB5 EQU 2 ; LCD dataline 5 DB4 EQU 3 ; LCD dataline 4 DB3 EQU 4 ; LCD dataline 3 DB2 EQU 5 ; LCD dataline 2 DB1 EQU 6 ; LCD dataline 1 DB0 EQU 7 ; LCD dataline 0 (LSB) ; misc. LCD_TEMP EQU 0x020 ; LCD subroutines internal use TABLE_INDEX EQU 0x021 ; Index to table strings COUNT EQU 0x022 ; A counter DELAY equ 0x023 ; Used in DELAYxxx routines X_DELAY equ 0x024 ; Used in X_DELAYxxx routines ; REGISTRE OPTION_REG (configuration) ; ----------------------------------- ;***************************************************************************** ; ASSIGNATIONS PROGRAMME * ;***************************************************************************** BRGVAL EQU D'51' ; pour un débit de 9720 bauds en mode high-speed ;***************************************************************************** ; MACRO * ;***************************************************************************** MESS macro a1,a2,a3,a4 ; inscrit le message dans bufout BANKSEL bufout ; passer en banque 3 movlw "[" ; mettre crochet movwf bufout ; dans bufout movlw a1 ; charger argument 1 movwf bufout+1 ; dans bufout movlw a2 ; charger argument 2 movwf bufout+2 ; dans bufout movlw a3 ; charger argument 3 movwf bufout+3 ; dans bufout movlw a4 ; charger argument 4 movwf bufout+4 ; dans bufout movlw "]" ; mettre crochet movwf bufout+5 ; dans bufout movlw 0x0D ; charger carriage return movwf bufout+6 ; dans bufout movlw 0x0A ; charger line-feed movwf bufout+7 ; dans bufout BANKSEL 0 ; repasser banque 0 endm ;***************************************************************************** ; VARIABLES BANQUE 0 * ;***************************************************************************** ; Zone de 80 bytes ; ---------------- CBLOCK 0x20 ; Début de la zone (0x20 à 0x6F) centaine:1 mode:1 dix:1 dixe:1 unite:1 ptr1 : 1 ; pointeur temporaire 1 ptr2 : 1 ; pointeur temporaire 2 octemp : 1 ; sauvegarde temporaire Time : 1 Count : 1 valeur : 1 pointeur : 1 RESULTAT : 1 ENDC ; Fin de la zone ;***************************************************************************** ; VARIABLES ZONE COMMUNE * ;***************************************************************************** ; Zone de 16 bytes ; ---------------- CBLOCK 0x70 ; Début de la zone (0x70 à 0x7F) volt:1 volt1:1 valh:1 compteurvir:1 w_temp : 1 ; Sauvegarde registre W status_temp : 1 ; sauvegarde registre STATUS FSR_temp : 1 ; sauvegarde FSR (si indirect en interrupt) PCLATH_temp : 1 ; sauvegarde PCLATH (si prog>2K) bufinptr : 1 ; pointeur sur caractère courant buffer entrée bufoutptr : 1 ; pointeur sur caractère courant buffer sortie flags : 1 ; flags divers ; b0 : parité calculée ; b1 : erreur de parité ; b2 : erreur de frame ; b3 : erreur overflow local1 : 1 ; variable locale pour interruptions ENDC #DEFINE PARITE flags,0 ; parité calculée #DEFINE ER_PAR flags,1 ; erreur de parité #DEFINE ER_FR flags,2 ; erreur de frame #DEFINE ER_OV flags,3 ; erreur d'overflow ;***************************************************************************** ; VARIABLES BANQUE 2 * ;***************************************************************************** ; Zone de 96 bytes ; ---------------- CBLOCK 0x110 ; Début de la zone (0x110 à 0x16F) bufin : D'96' ; zone de stockage des données entrées ENDC ; Fin de la zone ;***************************************************************************** ; VARIABLES BANQUE 3 * ;***************************************************************************** ; Zone de 96 bytes ; ---------------- CBLOCK 0x190 ; Début de la zone (0x190 à 0x1EF) bufout : D'96' ; message à envoyer ENDC ; Fin de la zone ;***************************************************************************** ; DEMARRAGE SUR RESET * ;***************************************************************************** org 0x000 ; Adresse de départ après reset goto init ; Initialiser ; //////////////////////////////////////////////////////////////////////////// ; I N T E R R U P T I O N S ; //////////////////////////////////////////////////////////////////////////// ;***************************************************************************** ; ROUTINE INTERRUPTION * ;***************************************************************************** ;----------------------------------------------------------------------------- ; La suppression des lignes "goto restorereg" permet dans ce cas de traiter ; l'interruption sur réception et sur émission en une seule fois ;----------------------------------------------------------------------------- ;sauvegarder registres ;--------------------- org 0x004 ; adresse d'interruption movwf w_temp ; sauver registre W swapf STATUS,w ; swap status avec résultat dans w movwf status_temp ; sauver status swappé movf FSR , w ; charger FSR movwf FSR_temp ; sauvegarder FSR ; switch vers différentes interrupts ;----------------------------------- ; Interruption réception USART ; ---------------------------- BANKSEL PIE1 ; sélectionner banque 1 btfss PIE1,RCIE ; tester si interrupt autorisée goto intsw1 ; non sauter bcf STATUS,RP0 ; oui, sélectionner banque0 btfss PIR1,RCIF ; oui, tester si interrupt en cours goto intsw1 ; non sauter call intrc ; oui, traiter interrupt ; Interruption transmission USART ; ------------------------------- intsw1 bsf STATUS,RP0 ; sélectionner banque1 btfss PIE1,TXIE ; tester si interrupt autorisée goto restorereg ; non sauter bcf STATUS,RP0 ; oui, sélectionner banque0 btfss PIR1,TXIF ; oui, tester si interrupt en cours goto restorereg ; non sauter call inttx ; oui, traiter interrupt ;restaurer registres ;------------------- restorereg movf FSR_temp , w ; charger FSR sauvé movwf FSR ; restaurer FSR swapf status_temp,w ; swap ancien status, résultat dans w movwf STATUS ; restaurer status swapf w_temp,f ; Inversion L et H de l'ancien W ; sans modifier Z swapf w_temp,w ; Réinversion de L et H dans W ; W restauré sans modifier status retfie ; return from interrupt ;***************************************************************************** ; INTERRUPTION RECEPTION USART * ;***************************************************************************** ;----------------------------------------------------------------------------- ; Reçoit le caractère de l'USART et le place dans le buffer d'entrée. ; Si la longueur atteint D'94', on n'encode plus, et on place 0x0D en avant- ; dernière position et 0x0A en dernière position ; Si la réception est terminée (longueur atteinte ou 0x0A reçu), on stoppe les ; interruptions de réception et on repositionne le pointeur au début du buffer ; Les erreurs sont détectées et signalées ;----------------------------------------------------------------------------- intrc ; tester si erreur de frame ; ------------------------- btfsc RCSTA,FERR ; tester si erreur de frame bsf ER_FR ; oui, signaler erreur de frame ; lire octet reçu ; --------------- bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movf bufinptr,w ; charger pointeur destination movwf FSR ; dans pointeur d'adresse movf RCREG,w ; charger octet reçu movwf INDF ; sauver dans buffer ; tester si erreur d'overflow ; --------------------------- btfsc PIR1,RCIF ; encore d'autres octets dans RCREG? goto intrc2 ; oui, vérifier caractère btfss RCSTA,OERR ; non, erreur d'overflow? goto intrc2 ; non, vérifier caractère bcf RCSTA,CREN ; oui, arrêt de la réception (reset de OERR) bsf RCSTA,CREN ; remise en service de la réception bsf ER_OV ; signaler erreur overflow goto intrcend ; et fin d'interruption ; tester si caractère reçu = 0x0A ; ------------------------------- intrc2 movf INDF,w ; charger caractère reçu xorlw 0x0A ; comparer avec line-feed btfsc STATUS,Z ; identique? goto intrcend ; oui, fin de message ; vérifier si buffer plein ; ------------------------ incf bufinptr,f ; incrémenter pointeur de caractères movf FSR,w ; charger pointeur xorlw 0x6D ; comparer avec dernièr emplacement possible btfss STATUS,Z ; identique? return ; non, fin de réception incf FSR,f ; pointeur sur emplacement suivant movlw 0x0D ; mettre carriage-return movwf INDF ; en avant-dernière position incf FSR,f ; pointer sur dernière position movlw 0x0A ; charger line-feed movwf INDF ; en dernière position ; fin de message ; -------------- intrcend movlw LOW bufin ; oui, adresse de départ du buffer d'entrée movwf bufinptr ; prochain caractère sera le premier bsf STATUS,RP0 ; passer banque 1 bcf PIE1,RCIE ; fin des interruptions de réception bcf STATUS,RP0 ; repasser banque 0 return ; et retour ;***************************************************************************** ; INTERRUPTION EMISSION USART * ;***************************************************************************** ;----------------------------------------------------------------------------- ; envoie le caractère pointé par bufoutptr, puis incrémente le pointeur ; Si ce caractère est le "line-feed", alors on arrête l'émission et on pointe de ; nouveau au début du buffer ;----------------------------------------------------------------------------- inttx ; prendre octet à envoyer ; ----------------------- bsf STATUS,IRP ; pointer banques 3 et 4 movf bufoutptr,w ; charger pointeur d'octets movwf FSR ; dans pointeur movf INDF,w ; charger octet à envoyer ; envoyer octet ; ------------- movf INDF,w ; charger octet à envoyer bcf STATUS,RP0 ; passer banque 0 movwf TXREG ; envoyer octet + parité incf bufoutptr,f ; pointer sur octet suivant ; tester si dernier octet ; ----------------------- xorlw 0x0A ; comparer octet envoyé avec Line-feed btfss STATUS,Z ; égalité? return ; non, retour d'interruption ; traiter fin d'émission ; ---------------------- bsf STATUS,RP0 ; passer en banque 1 bcf PIE1,TXIE ; fin des interruptions émission USART bcf STATUS,RP0 ; repasser banque 0 movlw LOW bufout ; adresse du buffer de sortie movwf bufoutptr ; prochain caractère = premier return ; fin d'interruption ;***************************************************************************** ; LCD ;***************************************************************************** ; ;============================================================================= ; LCDINIT ;============================================================================= LCDINIT ; Busy-flag is not yet valid CLRF LCD_CTRL ; ALL PORT output should output Low. ; power-up delay MOVLW 0x01E CALL X_DELAY500 ; 30 * 0.5mS = 15mS MOVLW 0x01E CALL X_DELAY500 ; Busy Flag should be valid from here MOVLW 0x01E CALL X_DELAY500 MOVLW 0x01E CALL X_DELAY500 MOVLW 0x01E CALL X_DELAY500 MOVLW 0x038 ; 8-bit-interface, 2-lines CALL LCDPUTCMD MOVLW 0x000 ; disp.off, curs.off, no-blink CALL LCDDMODE CALL LCDCLEAR MOVLW 0x004 ; disp.on, curs.OFF CALL LCDDMODE MOVLW 0x002 ; auto-inc (shift-cursor) CALL LCDEMODE RETURN ;============================================================================= ; LCD_ENABLE ;============================================================================= LCD_ENABLE BSF LCD_CTRL, LCD_E ; LCD E-line High BCF LCD_CTRL, LCD_E ; LCD E-line Low RETURN ;============================================================================= ; LCDBUSY ;============================================================================= LCDBUSY BSF STATUS,RP0 ; Select Register page 1 MOVLW 0x0FF ; Set PORTB for input MOVWF LCD_DATA_TRIS BCF STATUS, RP0 ; Select Register page 0 BCF LCD_CTRL, LCD_RS; Set LCD for command mode BSF LCD_CTRL, LCD_RW; Setup to read busy flag BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_DATA, W ; Read busy flag + DDram address BCF LCD_CTRL, LCD_E ; LCD E-line Low ANDLW 0x80 ; Check Busy flag, High = Busy BTFSS STATUS, Z GOTO LCDBUSY LCDNOTBUSY BCF LCD_CTRL, LCD_RW BSF STATUS, RP0 ; Select Register page 1 MOVLW 0x000 MOVWF LCD_DATA_TRIS ; Set PORTB for output BCF STATUS, RP0 ; Select Register page 0 RETURN ;============================================================================= ; LCDCLEAR ;============================================================================= LCDCLEAR MOVLW 0x001 CALL LCDPUTCMD RETURN ;============================================================================= ; LCDHOME ;============================================================================= LCDHOME MOVLW 0x002 CALL LCDPUTCMD RETURN ;============================================================================= ; LCDEMODE ; Sets entry mode of display. ; Required entry mode must be set in W ; b0 : 0 = no display shift 1 = display shift ; b1 : 0 = auto-decrement 1 = auto-increment ; b2-7 : don't care ; OK ;============================================================================= LCDEMODE ANDLW 0x003 ; Strip upper bits IORLW 0x004 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDDMODE ; Sets display control. ; Required display mode must be set in W ; b0 : 0 = cursor blink off 1 = cursor blink on ; b1 : 0 = cursor off 1 = cursor on ; b2 : 0 = display off 1 = display on (display data remains in DDRAM) ; b3-7 : don't care ; OK ;============================================================================= LCDDMODE ANDLW 0x007 ; Strip upper bits IORLW 0x008 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDSCGA ; Sets Character-Generator-RAM address. CGRAM is read/written after ; this setting. ; Required CGRAM address must be set in W ; b0-5 : required CGRAM address ; b6-7 : don't care ; ;============================================================================= LCDSCGA ANDLW 0x03F ; Strip upper bits IORLW 0x040 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDSDDA ; Sets the Display-Data-RAM address. DDRAM data is read/written after ; this setting. ; Required DDRAM address must be set in W ; b0-6 : required DDRAM address ; b7 : don't care ; OK ;============================================================================= LCDSDDA IORLW 0x080 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDGADDR ; Returns address counter contents, used for both DDRAM and CGRAM. ; RAM address is returned in W ; ;============================================================================= LCDGADDR BSF STATUS,RP0 ; Select Register page 1 MOVLW 0x0FF ; Set PORTB for input MOVWF LCD_DATA_TRIS BCF STATUS, RP0 ; Select Register page 0 BCF LCD_CTRL, LCD_RS; Set LCD for command mode BSF LCD_CTRL, LCD_RW; Setup to read busy flag BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_DATA, W ; Read busy flag + RAM address BCF LCD_CTRL, LCD_E ; LCD E-line Low ANDLW 0x07F ; Strip upper bit movwf RESULTAT BCF LCD_CTRL, LCD_RW BSF STATUS, RP0 ; Select Register page 1 MOVLW 0x000 MOVWF LCD_DATA_TRIS ; Set PORTB for output BCF STATUS, RP0 ; Select Register page 0 RETURN ;============================================================================= ; LCDPUTCHAR ; Sends character to LCD ; Required character must be in W ; OK ;============================================================================= LCDPUTCHAR MOVWF LCD_TEMP ; Character to be sent is in W CALL LCDBUSY ; Wait for LCD to be ready clrwdt BCF LCD_CTRL, LCD_RW; Set LCD in read mode BSF LCD_CTRL, LCD_RS; Set LCD in data mode BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_TEMP, W MOVWF LCD_DATA ; Send data to LCD BCF LCD_CTRL, LCD_E ; LCD E-line Low RETURN ;============================================================================= ; LCDPUTCMD ; Sends command to LCD ; Required command must be in W ; OK ;============================================================================= LCDPUTCMD MOVWF LCD_TEMP ; Command to be sent is in W CALL LCDBUSY ; Wait for LCD to be ready BCF LCD_CTRL, LCD_RW; Set LCD in read mode BCF LCD_CTRL, LCD_RS; Set LCD in command mode BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_TEMP, W MOVWF LCD_DATA ; Send data to LCD ;call DELAY500 BCF LCD_CTRL, LCD_E ; LCD E-line Low RETURN ;***************************************************************************** DELAY500 MOVLW D'162' ; +1 1 cycle MOVWF DELAY ; +2 1 cycle DELAY500_LOOP DECFSZ DELAY, F ; step 1 1 cycle GOTO DELAY500_LOOP ; step 2 2 cycles DELAY500_END RETURN ; +3 2 cycles ; ; X_DELAY500 MOVWF X_DELAY ; +1 1 cycle X_DELAY500_LOOP CALL DELAY500 ; step1 wait 500uSec CALL DELAY500 CALL DELAY500 CALL DELAY500 CALL DELAY500 DECFSZ X_DELAY, F ; step2 1 cycle GOTO X_DELAY500_LOOP ; step3 2 cycles X_DELAY500_END RETURN ; +2 2 cycles ; ; TEMPO movlw 0x04 movwf Time Boucle call X_DELAY500 decfsz Time,f goto Boucle return ; //////////////////////////////////////////////////////////////////////////// ; P R O G R A M M E ; //////////////////////////////////////////////////////////////////////////// ;***************************************************************************** ; INITIALISATIONS * ;***************************************************************************** init ; Registre d'options (banque 1) ; ----------------------------- bsf STATUS,RP0 movlw OPTIONVAL ; charger masque movwf OPTION_REG ; initialiser registre option ; registres interruptions (banque 1) ; ---------------------------------- bsf INTCON,PEIE ; autoriser interruptions périphériques ; initialiser USART ******************************************** a regler su 8 bit ; ----------------- movlw B'00000100' ; émission sur 8 bits, mode haute vitesse movwf TXSTA ; dans registre de contrôle movlw BRGVAL ; valeur pour baud rate generator movwf SPBRG ; dans SPBRG (4800 bauds GPS) bcf STATUS,RP0 ; passer banque 0 movlw B'10000000' ; module USART en service, réception 8 bits movwf RCSTA ; dans registre de contrôle ; Initialiser message de bienvenue ; -------------------------------- ;MESS "P","R","E","T" ; inscrire PRET dans le buffer de sortie ; initialiser variables ; --------------------- clrf flags ; effacer flags movlw LOW bufin ; adresse du buffer de réception movwf bufinptr ; dans pointeur movlw LOW bufout ; adresse basse du buffer d'émission movwf bufoutptr ; dans pointeur ; autoriser interruptions (banque 0) ; ---------------------------------- CLRF STATUS ; Do initialization, Select bank 0 CLRF PCLATH ; Keep in lower 2KByte CLRF PORTA ; ALL PORT output should output Low. CLRF PORTB BSF STATUS, RP0 ; Select bank 1 MOVLW 0X06 ;E8 MOVWF ADCON1 MOVLW 0xf8 ; RA2-1-0 outputs, RA4-3 inputs;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MOVWF TRISA MOVLW 0x000 ; RB7-0 outputs MOVWF TRISB BSF OPTION_REG, NOT_RBPU ; Disable PORTB pull-ups BCF STATUS, RP0 ; Select bank 0 CALL LCDINIT ; Initialize LCDisplay ; mise à 0 du mode d'affichage bsf INTCON,GIE ; valider interruptions CLRF mode goto start ; programme principal ;***************************************************************************** ; PREPARER LA REPONSE * ;***************************************************************************** ;----------------------------------------------------------------------------- ; copie le buffer d'entrée inversé dans le buffer de sortie ; en modifiant cette sous-routine, vous pouvez changer le fonctionnement ; de votre programme. Vous pouvez inventer ici de nouvelles règles de ; réponse ;----------------------------------------------------------------------------- preprep movf mode,w xorlw 0x00 btfsc STATUS,Z goto hmh movf mode,w xorlw 0x01 btfsc STATUS,Z goto localisation movf mode,w xorlw 0x02 btfsc STATUS,Z goto Vitesse movf mode,w xorlw 0x03 btfsc STATUS,Z goto description ; rechercher la fin du message ; ---------------------------- hmh movlw LOW bufin-1 ; pointer sur début du message-1 movwf FSR ; dans pointeur bsf STATUS,IRP ; pointer banques 3 et 4 en indirect prep1 incf FSR,f ; pointer sur suivant movf INDF,w ; charger caractère xorlw 'M' ; comparer avec line-feed btfsc STATUS,Z ; tester si car = 0x0A goto detectM ; non, suivant movf INDF,w ; charger caractère xorlw 0x0A ; comparer avec line-feed btfss STATUS,Z ; tester si car = 0x0A goto prep1 goto detectR ; envoie sue ecran l'altitude ; --------------------------- detectM decf FSR,f ;just avant le M donc sur , movf INDF,w xorlw 0x2c btfsc STATUS,Z goto virgu goto detectR virgu virgule decf FSR,f movf INDF,w xorlw 0x2c btfss STATUS,Z goto virgule goto AfficheLCD AfficheLCD ; arriver ici on est sur la premier virgule avant la donnée movlw 0x00 call LCDHOME incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z goto Changervaleur decf FSR,f mess incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z goto SuiteMessage movf INDF,w xorlw 0x30 btfsc STATUS,Z goto mess go movf INDF,w xorlw '.' btfsc STATUS,Z goto SuiteMessage movf INDF,w call LCDPUTCHAR ;****************************************** incf FSR,f goto go Changervaleur movlw 'X' call LCDPUTCHAR goto SuiteMessage SuiteMessage movlw ' ' call LCDPUTCHAR movlw 'm' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR ;detection heure detectR movlw LOW bufin-1 ; pointer sur début du message-1 movwf FSR ; dans pointeur bsf STATUS,IRP ; pointer banques 3 et 4 en indirect prep2 clrwdt incf FSR,f ; pointer sur suivant movf INDF,w ; charger caractère xorlw 'R' ; comparer avec line-feed btfsc STATUS,Z ; tester si car = 0x0A goto suitedetectR ; non, suivant movf INDF,w ; charger caractère xorlw 0x0A ; comparer avec line-feed btfss STATUS,Z ; tester si car = 0x0A goto prep2 return suitedetectR incf FSR,f incf FSR,f incf FSR,f incf FSR,f clrwdt movlw 0x40 call LCDSDDA clrwdt movlw 0x04 movwf compteurvir loop3 movlw ' ' call LCDPUTCHAR clrwdt decfsz compteurvir,f goto loop3 movf INDF,w movwf valh movf INDF,w call LCDPUTCHAR clrwdt incf FSR,f movf INDF,w xorlw 0x39 btfsc STATUS,Z goto decal movf INDF,w addlw 0x01 no call LCDPUTCHAR movlw ':' call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR movlw ':' call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR movlw 0x08 call LCDSDDA movlw 0x08 movwf compteurvir date incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z decfsz compteurvir,f goto date ;apres huit virgules incf FSR,f movf INDF,w call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR movlw '/' call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR movlw '/' CALL LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR incf FSR,f movf INDF,w call LCDPUTCHAR return ; et fin decal incf valh,f movlw 0x44 call LCDSDDA clrwdt movf valh,w call LCDPUTCHAR movlw 0x30 goto no ; SI le flags MODE est sur 1 *********************************************************** localisation movlw LOW bufin-1 ; pointer sur début du message-1 movwf FSR ; dans pointeur bsf STATUS,IRP ; pointer banques 3 et 4 en indirect prep3 clrwdt incf FSR,f ; pointer sur suivant movf INDF,w ; charger caractère xorlw 'R' ; comparer avec line-feed btfsc STATUS,Z ; tester si car = 0x0A goto lat ; non, suivant movf INDF,w ; charger caractère xorlw 0x0A ; comparer avec line-feed btfss STATUS,Z ; tester si car = 0x0A goto prep3 return lat movlw 0x03 movwf compteurvir lat2 incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z decfsz compteurvir,f goto lat2 movlw 0x00 call LCDSDDA movlw 'L' call LCDPUTCHAR movlw 'A' call LCDPUTCHAR movlw 'T' call LCDPUTCHAR movlw ':' call LCDPUTCHAR suitelat incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z goto nord movf INDF,w call LCDPUTCHAR goto suitelat nord incf FSR,f movf INDF,w call LCDPUTCHAR long incf FSR,f ;mets sur la virgule long2 movlw 0x40 call LCDSDDA movlw 'L' call LCDPUTCHAR movlw 'O' call LCDPUTCHAR movlw 'N' call LCDPUTCHAR movlw ':' call LCDPUTCHAR suitelon incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z goto sud movf INDF,w call LCDPUTCHAR goto suitelon sud incf FSR,f movf INDF,w call LCDPUTCHAR return Vitesse movlw LOW bufin-1 ; pointer sur début du message-1 movwf FSR ; dans pointeur bsf STATUS,IRP ; pointer banques 3 et 4 en indirect prep4 clrwdt incf FSR,f ; pointer sur suivant movf INDF,w ; charger caractère xorlw 'R' ; comparer avec line-feed btfsc STATUS,Z ; tester si car = 0x0A goto vit ; non, suivant movf INDF,w ; charger caractère xorlw 0x0A ; comparer avec line-feed btfss STATUS,Z ; tester si car = 0x0A goto prep4 return vit movlw 0x07 movwf compteurvir vit2 incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z decfsz compteurvir,f goto vit2 incf FSR,f movlw 0x00 call LCDSDDA movlw 'V' call LCDPUTCHAR movlw 'i' call LCDPUTCHAR movlw 't' call LCDPUTCHAR movlw 'e' call LCDPUTCHAR movlw 's' call LCDPUTCHAR movlw 's' call LCDPUTCHAR movlw 'e' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw '3' call LCDPUTCHAR movlw '0' call LCDPUTCHAR movlw '6' call LCDPUTCHAR movlw 0x40 call LCDSDDA movf INDF,w xorlw 0x2c btfsc STATUS,Z goto affichz2 movf INDF,w movwf centaine movlw 0x30 subwf centaine,f incf FSR,f movf INDF,w xorlw 0x2c btfsc STATUS,Z goto suita movf INDF,w movwf dixe movlw 0x30 subwf dixe,f movf INDF,w xorlw 0x2c btfsc STATUS,Z goto suita movf INDF,w movwf unite movlw 0x30 subwf unite,f suita movlw 0x00 movwf compteurvir movf centaine,w xorlw 0x00 btfsc STATUS,Z goto dixaine cent movlw d'100' addwf compteurvir,f decfsz centaine,f btfss STATUS,C goto cent dixaine movf dixe,w xorlw 0x00 btfsc STATUS,Z goto unit movlw d'10' addwf compteurvir,f decfsz dixe,f btfss STATUS,C goto dixaine unit movf unite,w xorlw 0x00 btfsc STATUS,Z goto jok movlw 0x01 addwf compteurvir,f decfsz unite,f btfss STATUS,C goto unit jok movf compteurvir,w movwf unite movwf centaine bcf STATUS,C ;**************** celacul 1 + 1/2 + 1/4 + 1/8 RRF unite,f movf unite,w addwf compteurvir,f bcf STATUS,C RRF unite,f movf unite,w addwf compteurvir,f bcf STATUS,C RRF unite,f movf unite,w addwf compteurvir,f movf compteurvir,w movwf volt movlw 0x00 movwf compteurvir reC incf compteurvir,f movlw D'100' subwf volt,f btfss STATUS,C goto reC decf compteurvir,f movf compteurvir,w movwf centaine movlw D'100' addwf volt,f movlw 0x00 movwf compteurvir reD incf compteurvir,f movlw D'10' subwf volt,f btfss STATUS,C goto reD decf compteurvir,f movf compteurvir,w movwf dixe movlw D'10' addwf volt,f movf volt,w movwf unite movlw 0x30 addwf centaine,f movlw 0x30 addwf dixe,f movlw 0x30 addwf unite,f movf centaine,w caLL LCDPUTCHAR movf dixe,w CALL LCDPUTCHAR movf unite,w CALL LCDPUTCHAR affichz movlw ' ' call LCDPUTCHAR movlw 'K' call LCDPUTCHAR movlw 'm' call LCDPUTCHAR movlw '/' call LCDPUTCHAR movlw 'h' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR return affichz2 movlw 'X' call LCDPUTCHAR goto affichz ;************************************************************************* description movlw 0x00 call LCDSDDA movlw 'C' call LCDPUTCHAR movlw 'r' call LCDPUTCHAR movlw 'e' call LCDPUTCHAR movlw 'e' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw 'P' call LCDPUTCHAR movlw 'a' call LCDPUTCHAR movlw 'r' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw 'L' call LCDPUTCHAR movlw 'e' call LCDPUTCHAR movlw 'a' call LCDPUTCHAR movlw 'k' call LCDPUTCHAR movlw 'y' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw 0x40 call LCDSDDA movlw 'V' call LCDPUTCHAR movlw 'e' call LCDPUTCHAR movlw 'r' call LCDPUTCHAR movlw 's' call LCDPUTCHAR movlw 'i' call LCDPUTCHAR movlw 'o' call LCDPUTCHAR movlw 'n' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw '1' call LCDPUTCHAR movlw '.' call LCDPUTCHAR movlw '0' call LCDPUTCHAR movlw ' ' call LCDPUTCHAR movlw 'G' call LCDPUTCHAR movlw 'P' call LCDPUTCHAR movlw 'S' call LCDPUTCHAR return ;***************************************************************************** ; PROGRAMME PRINCIPAL * ;***************************************************************************** start ; lancer l'émission, message de bienvenue ; --------------------------------------- clrwdt ; lancer la réception ; -------------------- bcf STATUS,RP0 ; passer banque 0 bsf RCSTA,CREN ; lancer la réception ; revevoir le message ; ------------------- bsf STATUS,RP0 ; passer banque 1 loop bsf PIE1,RCIE ; autoriser interruption réception clrwdt ; effacer watchdog btfsc PIE1,RCIE ; tester si message complet reçu goto $-2 ; non, attendre clrwdt bcf STATUS,RP0 ; traitement normal du message ; ---------------------------- messprep bcf STATUS,RP0 ; passer banque 0 call preprep ; préparer réponse msuite btfss PORTA,BUTTON goto recommence call LCDCLEAR incf mode,f movf mode,w xorlw 0x04 ; BLOK FONCTION BATTERIE VOLTAGE ************************************************* btfsc STATUS,Z goto misea0 eh bouclb call TEMPO clrwdt btfsc PORTA,BUTTON goto eh goto recommence misea0 CLRF mode boucla call TEMPO clrwdt btfsc PORTA,BUTTON goto misea0 recommence bsf STATUS,RP0 ; passer banque 1 bsf PIE1,RCIE ; réautoriser interruption réception ; envoyer réponse ; --------------- goto loop ; traiter message suivant END ; directive fin de programme