;17/07/09 mofif routine reception ;12/07/2009 modif pour adaptation specifique au XPORT ; schema voir 16F877_Nokia_Xport_090502.DSN ; K => ecriture PCF en local via clavier ..OK ; E => ecriture PCF via XPORT voir _Test6 projet RealJ ; plus d'echo car perturbateur coté XPORT ;29 mai 2009 adaptation reception directe 8 bits pour Xport ;27/03/09 echelle 0,00 a 40.96°C sur EA1 CH0 avec LM35DZ + Ampli 10x => resolution 0,04°C ;16/03/2009 Envoi complet sur RS232 sans passer par le menu pour Test avec XPORT Webserver ;13/03/2009 : Bug sur jour Date envoyée sur RS232 (mais OK sur LCD!) ; debordement LastCDA et compteur subroutine Affbinaire_hexa en bank1! ; rajout 2 infos au menu ; voir @@ modif 08/03/09 ; nota: test application programmée pour Q=10Mhz et RS=19200 bds ; test avec Q=4Mhz .. appli & LCD OK mais speed RS = BAD car entre 2 vitesses standard ! ; test avec Q=5,068MHz .appli & LCD OK Speed RS=9600 bds ; test avec Q=20Mhz .. appli & LCD OK speed RS=38400 bds ;---------------------------------------------------------------------- ;Release build of project `C:\Mplab8\_Mesprojets\_16F877\16F877_nokia.mcp' started. ;Sun Jul 12 15:08:27 2009 ;---------------------------------------------------------------------- ;Clean: Deleting intermediary and output files. ;Clean: Deleted file "C:\Mplab8\_Mesprojets\_16F877\NOKIA_877_XPORT_090709.err". ;Clean: Deleted file "C:\Mplab8\_Mesprojets\_16F877\NOKIA_877_XPORT_090709.cod". ;Clean: Deleted file "C:\Mplab8\_Mesprojets\_16F877\NOKIA_877_XPORT_090709.hex". ;Clean: Deleted file "C:\Mplab8\_Mesprojets\_16F877\NOKIA_877_XPORT_090709.lst". ;Clean: Deleted file "C:\Mplab8\_Mesprojets\_16F877\16F877_nokia.mcs". ;Clean: Done. ;Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F877 ;"NOKIA_877_XPORT_090709.asm" ;/l"NOKIA_877_XPORT_090709.lst" /e"NOKIA_877_XPORT_090709.err" /aINHX8M ;Loaded C:\Mplab8\_Mesprojets\_16F877\NOKIA_877_XPORT_090709.cod. ;---------------------------------------------------------------------- ;Release build of project `C:\Mplab8\_Mesprojets\_16F877\16F877_nokia.mcp' succeeded. ;Sun Jul 12 15:08:32 2009 ;---------------------------------------------------------------------- ;BUILD SUCCEEDED ;Sun Jan 18 15:37:22 2009 ;16F877_Nokia_090118.DSN ;---------------------------------------------------------------------- ;adresse EEPROM 24LC256 ;----------------------------------------------------------------------------- ; Rappel : bootloader incorpore dans le PIC16F877 ; chargement *.HEX avec PIC DOWNLOADER 1.09 sur comx a 19200 bauds ;------------------------------------------------------------- ; rajout zones texte en FLASH ; 06/07/08 correction Bug : si Bargraphe =0 sautait la suite du traitement... ; 27/05 modif saisie car. par car. avec affichage echo sur LCD ; test OK debordement taille buffer (16 car max) ; modif SP effacement LCD .. 9 au lieu de 8 lignes et 97 au lieu de 96 pixel ; 25/05 rajout lecture permanente port PCF8574_2 ; 24/05 affichage Ecr PCF8574 en binaire et hexadec... saisie par paquet ; rev 23/05 PB avec deplacement table caracteres en 1000H pour avoir plus de place code.. ; attention gestion de PCLATH obligatoire avec code debordant l'adresse 0x7FF = page 0 ; programme en page 2 > 0x1000 appele apres BSF PCLATH,4 (BCF PCLATH,3) ; attention BCF PCLTAH,4 si appel de SP en page 0 ; Executing: "C:\Mplab8\MPASM Suite\MPASMWIN.exe" /q /p16F877 "nokia_877_080526.asm" ; rajout ecriture PCF8574 ; rev 23/05 rajout saisie M MAJ date .. teste OK ; rev 17/04 table car 5x7 placee en page 5 au lieu de 4 ; rev 14/04/2008 avec nouveau LCD 3410 certifie monte sur support C.I. ; on obtient bien 8 lignes de 96 car (l'ancien n'affichait que 5 lignes et 1/2 ...a moitie HS!!!!) ; rev 23/03/2008 ; to ADD ,PCF854,24LC256 ; rajout gestion I2C pour RTC DS1307 ; rev 4/1/08 bug barregraphe si valeur <11 ......solde! ; rev PF 30dec 2007 ; version avec PIC16F877 bottloader 19200bds Quartz 10MHz ;**************************************************************** ;affichage sur LCD: ;************************ ;Date et heure 1ere ligne ;CH0 + 5.11 Deg 2em simili flotant ;CH1 0030 POINTS 3em en points sur 4 digits ;CH2 00030 POINTS 4em en points sur 5 digits ;========= bargraph 5em sur CH2 ;Ports 8b PCF8574 6em ;Ecr 10001100 =8Ah 7em ;Lec 11110001 =F1h 8em ;ou ;MAJ DS1307 6em ;AAMMJJWWHHMMSS 7em ;08052605181800 8em ;********************************************* ;TO DO: ;to ADD ,PCF854,24LC256 ;modif gestion I2C en hardware ...pour RTC DS1307 ;graphique ; rev 4/1/08 bug barregraphe si valeur <11 ......solde! ; rev PF 30dec 2007 ; version avec PIC16F877 bottloader 19200bds Quartz 10MHz ;------------------------------- ; #include <../P16F877.inc> ; P16F877.INC Standard Header File, Version 1.00 Microchip Technology, Inc. LIST list p=PIC16F877,c=132,n=60,st=ON,mm=ON,t=ON,x=ON,r=hex __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF &_BODEN_OFF & _PWRTE_ON &_WDT_OFF & _HS_OSC ERRORLEVEL -302 ;======================================================== ; voir lcd_controller_pcd8544.pdf ; I2_cours.pdf Overview and Use of the PICmicro MSSP I2C Interface ; Hardware ; Quartz 10MHz encadr‚ de 2x22pF ;------------------------------------------------------ ; 1 MCLR --> 4,7K --> au +5V ; 2 RA0 <-- Anlog Input --- potar 4,7K 0 a 4.096V ; 3 RA1 <-- Anlog Input --- potar 4,7K 0 a 4.096V ; 4 RA2 - ref a 0V ; 5 RA3 + ref a +4.096V via reference TO92 4040D Z4.1 ; 6 RA4 not used ; 7 RA5 <-- Anlog Input --- potar 4,7K 0 a 4.096V ; ; 8 RE0 ---> out--> 2.7K-> LED blanche --> +5V ; 9 RE1 ... Dispo ;10 RE2 ... Dispo ;11 VDD +5V ;12 VSS 0V ;13 Quartz 10MHz -- 22pF CRYSTAL, 10M, 18PF CL, HC49/4H RALTRON - AS-10.000-18 R100WFB8x ;14 Quartz 10MHz -- 22pF FARNELL REF 1611856 ;----- Liaison SPI avec LCD Nokia --------------------- ; Pin 16F877 Nokia 3410 Pin ;15 RC0 SCE 4.7K 5 CS Chips Select ;16 RC1 D/C 4.7K 4 D/C data ou Commande ;17 RC2 Reset 4.7K 8 RES Reset ;18 RC3 SCL 4.7K 2 SCK clock ;23 RC4 SDA 4.7K 3 DIN Data input ; Power 1 +3V VDD ; Gnd 6 0V GND ; Vc 7 capa 1uF ;------------------------------------------------------ ;19 RD0 ... Dispo ;20 RD1 ... Dispo ;21 RD2 ... Dispo ;22 RD3 ... Dispo ;-------------------- ;24 RC5 ... dispo ;----- Liaison RS232 19200bds 8,N,1 --- ;25 RC6 Tx ----vert ---- 3 de DS275 5 -- RS232 --> Ecran ;26 RC7 Rx --- blc/vert--- 1 de DS275 7 -- RS232 <-- Clavier ;----------------------------------------------------- ;27 RD4 ... Dispo ;28 RD5 ... Dispo ;29 RD6 ... Dispo ;30 RD7 ... Dispo ;------------ Liaison I2C Software -------------------- ;31 --> VSS 0V ;32 --> VDD +5V ;33 RB0 ... Dispo ;34 RB1 <-- inp BP Mise a l'heure par defaut ;35 RB2 ---> out--> 2.7K-> LEDrouge --> +5V ;36 RB3 <-- 0V Sacrifie pour programmation LVP ;37 RB4 ... Dispo ;38 RB5 ... Dispo ;39 RB6 <--in/out---> SCL ;40 RB7 ---> output-->SDA ;====================================================== cblock 0x20 Annee Mois Jour JourSem HEURE MIN SEC CtrlReg BUFFER OUTER ;delay variable mS BoucleExt BoucleInt caractere offset_caractr pointeur_msg ;message (max. 255 caracteres) rotulo ;indique la position PCL dans le message Progression DATAL DATAH count1 count2 count3 Cpt1 E_value L_value ACCaLO ;Variables de calcul ACCaHI ACCbLO ACCbHI ACCcLO ACCcHI ACCdLO ACCdHI temp Flags ; pour calculs Conf dummy ADDR ; I2C devices O_BYTE I_BYTE _N _N0 _N1 _Cpt1 _Cpt2 _RsByte _Temp1 _Temp2 _10it Drapeaux ; Drapeaux de 8 bits a usage multiple ;7 signe 1= RETENUE si negatif ;6 elligible =1 ;5 si=1 => affichage simili flottant XX.XX ou en entier XXXX si =0 ;4 si=1 => affichage 5 digits (99999 ou XXX.XX), sinon si=0 4 digits ! ;3 si=1 ;2 si=1 => ;1 si=1 => ;0 si=1 => affichage LCD sinon sur RS232 endc LastBank0 EQU Drapeaux IF ( LastBank0 >= 0x70 ) ERROR "Attention debordement zone RAM bank0" ENDIF ;******************* ; COMMON DATA AREA ;-------------------- CBLOCK 0x71 ;Attention 0x70 used by ICD ; 0x71 ... 0x7B used by bootloader w_temp: 1 ; Sauvegarde registre W status_temp: 1 ; sauvegarde registre STATUS FSR_temp: 1 ; sauvegarde FSR (si indirect en interrupt) PCLATH_temp: 1 time:1 Buff_In_Ptr: 1 ; pointeur sur caractere courant buffer entree Buff_Out_Ptr: 1 ; pointeur sur caractere courant buffer sortie flags : 1 ; 8 flags divers value ADR_HI ADR_LO MenuChoice ENDC LastCDA equ MenuChoice IF ( LastCDA > 0x7E ) ERROR "Attention debordement zone RAM Bootloader en bank0" ENDIF ;#DEFINE xx flags,0 ; xxxxxxxxx #DEFINE ER_FR flags,1 ; erreur de frame #DEFINE ER_OV flags,2 ; erreur d'overflow #DEFINE Fin_de_saisie flags,3 ; 1=signale fin de saisie #DEFINE Abort_Saisie flags,4 ; abort saisie #DEFINE Saisie_Xport flags,5 ; 1=from Xport 0=from Keyboard ;#DEFINE xx flags,6 ; xxxxxxxxx ;#DEFINE xx flags,7 ; xxxxxxxxx ;#DEFINE Aff_Aide MenuChoice,0 ; #DEFINE Aff_Date MenuChoice,1 ; envoi date sur RS232 #DEFINE AffEcr8 MenuChoice,2 ; envoi modif ecr 8b #DEFINE AffLect8 MenuChoice,3 ; envoi lect 8 bits #DEFINE Aff_Aide MenuChoice,4 ; envoi Help /Rs232 #DEFINE Cons1 MenuChoice,5 ;AN0 RA0 #DEFINE Cons2 MenuChoice,6 ;AN1 RA1 #DEFINE Cons3 MenuChoice,7 ;AN5 RA5 Buffer_MAJ equ 0x20 ;Define macro Channel_Sel numero Channel_Sel macro numero IF (numero==1) ; ch0 RA0 000 bcf ADCON0,3 bcf ADCON0,4 bcf ADCON0,5 endif IF (numero==2) ;ch1 RA1 001 bsf ADCON0,3 bcf ADCON0,4 bcf ADCON0,5 endif ; IF (numero==3) ;ch2 RA2 mais utilise comme -Vref ; bcf ADCON0,3 ; bsf ADCON0,4 ; 010 ; bcf ADCON0,5 ; endif ; IF (numero==4) ; ch3 RA3 mais utilise comme +Vref ; bsf ADCON0,3 ; bsf ADCON0,4 ; 011 ; bcf ADCON0,5 ; endif IF (numero==3) ; ch4 RA5 bcf ADCON0,3 ; 100 bcf ADCON0,4 bsf ADCON0,5 endif call delay_10ms ENDM ;*********************** ; VARIABLES BANQUE 1 ;*********************** ; Zone de 80 bytes cblock 0xA0 ; en bank1 Cpt10 ; Bcd Mcount btmp btmp1 dixmil mille cent dix un ; variables 16 bits SommeTamb :2 Tamb_F :2 ; Tamb STamb_F :2 valx :2 val1 :2 val2 :2 val3 :2 val4 :2 reste :2 result :2 Nb_1 :2 ; compteur endc #DEFINE Taille_buffer D'14' ;*********************** ; VARIABLES BANQUE 2 ;*********************** ; Zone de 96 bytes CBLOCK 0x110 ; Debut de la zone (0x110 a 0x16F) Buffin : Taille_buffer + 2 ; zone de stockage des donnees saisies ENDC ; Fin de la zone ;*********************** ; VARIABLES BANQUE 3 ;*********************** ; Zone de 96 bytes ; ---------------- CBLOCK 0x190 ; Debut de la zone (0x190 a 0x1EF) Buffout : Taille_buffer + 2 ; message a envoyer ; addwrite Buffer_EE :64 ENDC ;==== Parametrage pour RS232 ==== #define FOSC D'10000000' ; <<< frequence du quartz[Hz] ici= 10 MHz #define BAUD D'19200' ; <<< vitesse du port serie [bit/sec] ici=19200 #define BAUD_ERROR D'4' ; <<< erreur de vitesse [%] #define TIMEOUT D'10' ;===== verification ============================ IF ((FOSC/(D'16' * BAUD))-1) < D'256' #define DIVIDER (FOSC/(D'16' * BAUD))-1 #define HIGH_SPEED 1 ELSE #define DIVIDER (FOSC/(D'64' * BAUD))-1 #define HIGH_SPEED 0 ENDIF BAUD_REAL EQU FOSC/((D'64'-(HIGH_SPEED*D'48'))*(DIVIDER+1)) IF BAUD_REAL > BAUD IF (((BAUD_REAL - BAUD)*D'100')/BAUD) > BAUD_ERROR ERROR "mauvaise vitesse de la liaison serie" ENDIF ELSE IF (((BAUD - BAUD_REAL)*D'100')/BAUD) > BAUD_ERROR ERROR "mauvaise vitesse de la liaison serie" ENDIF ENDIF ;----------- F(Quartz) ------------ IF FOSC > D'10240000' #define T1PS 8 #define T1SU 0x31 ELSE IF FOSC > D'5120000' #define T1PS 4 #define T1SU 0x21 ELSE IF FOSC > D'2560000' #define T1PS 2 #define T1SU 0x11 ELSE #define T1PS 1 #define T1SU 0x01 ENDIF ENDIF ENDIF TIMER EQU (D'65538'-(FOSC/(D'10'*4*T1PS))); ; valeur de reprise pour TIMER1 (0.1s int) ;==================================================== #define Quartz 10 ; pour les tempos! #define TABUL .9 #define OFFSET_ANA .512 #define RETENUE Drapeaux,7 #define ELLIGIBLE Drapeaux,6 #define SCE PORTC,0 #define DC PORTC,1 #define RST PORTC,2 #define BP_MAL PORTB,1 ; tirage au +5V si mise a zero =>Mise a L'heure par defaut #define LEDrouge PORTB,2 #define I2C_SDA PORTB,7 ;RB7 (pin 40) ---> output-->SDA #define I2C_SCL PORTB,6 ;RB6 (pin 39) <--in/out---> SCL #define LEDblanche PORTE,0 #define OUT_LCD Bsf Drapeaux,1 ; sortie sur LCD #define OUT_RS232 Bcf Drapeaux,1 ; sortie sur COM #DEFINE DEV_DS1307 0xD0 ; adresse DS1307 RTC #DEFINE DEV_PCF8574_1 0x48 ; Adresse PCF8574 8 Output 0x40+08 #DEFINE DEV_PCF8574_2 0X4A ; Adresse PCF8574 8 Input ; 1 0 1 0 A2 A1 A0 R/W soit A0+04H ;-------------------- ORG 0x0000 nop ; pour ICSP nop ; pour ICSP nop ; pour ICSP goto Init ;*********************** ; interruptions ;*********************** org 0x04 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 movf PCLATH , w ; charger PCLATH movwf PCLATH_temp ; le sauver clrf PCLATH ; on est en page 0 bank0 ; passer en banque0 ;------------------------------ ; est-ce une interrupt sur RB0 ;---------------------------------- ; btfsc INTCON,INTE ; tester si interrupt Rb0 autorisee ; btfss INTCON,INTF ; oui, tester si Flag Rb0 arme ; goto Timer1_int ; NON ;Rb0_int ; bcf INTCON,INTE ; raz autorise int RB0 ; bcf INTCON,INTF ; en sortie de traitement interrupt Rb0 devalid‚e! ;todo.................. ; goto restorereg btfss INTCON,PEIE ; tester si interrupt PERIPH autorisee goto restorereg ;-------------------------------- ; Interruption reception USART ;------------------------------- Uart_Rx_Int bank1 btfss PIE1,RCIE ; tester si interrupt autorisee goto Timer1_int ; non sauter bank0 btfss PIR1,RCIF ; oui, tester si interrupt en cours goto Timer1_int ; non sauter call intrc ; oui, traiter interrupt ;-------------------------------- ; Interruption TIMER1 ;------------------------------- Timer1_int bank1 btfss PIE1,TMR1IE ; tester si interrupt timer autorisee goto restorereg bank0 btfss PIR1,TMR1IF ; oui, tester si Flag interrupt arme goto restorereg ; non test suivant decf _10it,f btfss STATUS,Z goto Tim11 bsf ELLIGIBLE ; arme drapeau,6 => ok pour mesure movlw .20 movwf _10it ;1sec movlw .32 xorwf PORTA,f ; clignote led Blanche Tim11 bcf T1CON,TMR1ON ; stopper le timer 1 movlw LOW (.65536-.15535) movwf TMR1L movlw HIGH (.65536-.15535) movwf TMR1H bsf T1CON,TMR1ON ; autoriser le timer 1 bcf PIR1,TMR1IF ; RAZ flag interrupt restorereg bank0 movf PCLATH_temp , w ; recharger ancien PCLATH movwf PCLATH ; le restaurer movf FSR_temp , w ; charger FSR sauv‚ movwf FSR ; restaurer FSR swapf status_temp , w ; swap ancien status, r‚sultat movwf STATUS ; restaurer status swapf w_temp , f ; Inversion L et H de l'ancien ; sans modifier Z swapf w_temp , w ; Reinversion de L et H dans ; W restaure sans modifier retfie ; return from interrupt ;************************************************* ; INTERRUPTION RECEPTION USART * ;************************************************* ; Recoit le caractere de l'USART et le place dans le buffer d'entree. ; Si la longueur atteint Taille_buffer(=14), on n'encode plus, et on place 0x0D 0x0A ; en derniere position ; Si la reception est terminee (longueur atteinte ou 0x0A recu), on stoppe les ; interruptions de reception et on repositionne le pointeur au debut du buffer ;----------------------------------------------------------------------------- intrc ; tester si erreur de frame btfsc RCSTA,FERR ; tester si erreur de frame bsf ER_FR ; oui, signaler erreur de frame ; lire octet resu bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movf Buff_In_Ptr,w ; charger pointeur destination movwf FSR ; dans pointeur d'adresse movf RCREG,w ; charger octet recu movwf dummy movwf INDF ; sauver dans buffer incf Buff_In_Ptr,f ; incrementer pointeur de caracteres bcf STATUS,IRP ;@modif 17/7/09 ; tester si erreur d'overflow btfss RCSTA,OERR ; non, erreur d'overflow? goto intrc2 ; non, verifier caractere bcf RCSTA,CREN ; oui, arret de la reception (reset de OERR) bsf RCSTA,CREN ; remise en service de la reception bsf ER_OV ; signaler erreur overflow ; tester si caractere recu = 0x0A ou 0x0D intrc2 movf dummy,w sublw .14 ; 0A ou 0D (LF ou CR) btfsc STATUS,C ; W- caractere ->negatif ?si code caractere <14 BSF Fin_de_saisie ; oui, fin de message btfsc STATUS,C ; goto intrc3 ; oui, fin de message ; verifier si buffer plein movf Buff_In_Ptr,w ; incrementer pointeur de caracteres xorlw LOW Buffin + Taille_buffer -1 ; comparer avec dernier emplacement possible 110 a 11F btfss STATUS,Z ; identique? return ; non, fin de reception BSF Fin_de_saisie goto intrcend intrc3 ; @modif 17/07/09 ; movlw 0x0D ; mettre carriage-return ; movwf INDF ; en avant-derniere position ; incf FSR,f ; pointer sur derniere position ; movlw 0x0A ; charger line-feed ; movwf INDF ; en derniere position return ; fin de message intrcend movlw LOW Buffin ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractRre sera le premier bsf STATUS,RP0 ; passer banque 1 bcf PIE1,RCIE ; fin des interruptions de reception bcf STATUS,RP0 ; repasser banque 0 return ;********************************************** ; INITIALISATIONS ;********************************************** Init bank0 clrf MenuChoice clrf PORTA clrf PORTB clrf PORTC clrf PORTE clrf flags ; effacer flags movlw LOW Buffin ; adresse du buffer de reception movwf Buff_In_Ptr ; dans pointeur movlw LOW Buffout ; adresse basse du buffer d'emission movwf Buff_Out_Ptr ; dans pointeur ;------------------------------------------ ; Configuration Voie ANALOGIQUE et logiques en bank1! ; MSB right justified ; min.ref sur 0,00V RA2 et max.ref sur 5,0V RA3 ; voie analogique AN0 pin RA0 et AN1 pin RA1 AN2 pin RA2 AN3 pin RA5 ; digital sur RE0..RE2 ;------------------------------------------- bank1 movlw b'10001100' ; RA0,RA1,RA2,RA5= ANA, RA3=+Vref, RE0..RE2=digital ,cadre a droite movwf ADCON1 ; 1100 D D D A VREF+ VREF- A A movlw b'00111111' ; RA0 .... RA5 en entrees car ANA en Entrees movwf TRISA movlw b'00000010' ; RB1 en entree movwf TRISB movlw b'10011000' ; SCL, SDA et Rx Uart en entrees movwf TRISC movlw b'00000000' ; RE0,1,2 en sortie movwf TRISE ;init variable en bank1 clrf val1 clrf val1+1 clrf Nb_1 clrf Nb_1+1 bank0 ;------------------------------------------ ;Definition Voie ANALOGIQUE (en bank0!) ;right justified, max.ref = sur RA4 et min.ref= 0 ;voie analogique AN0 pint Ra0 ;bit 7-6: ADCS1:ADCS0: A/D Conversion Clock Select bits 10 = FOSC/32 ;bit 5-3: CHS2:CHS0: Analog Channel Select bits 000 = channel 0, (RA2/AN2) RA0,1,2,3,5 ;bit 2: GO/DONE: A/D Conversion Status bit,If ADON = 1 1=in progress 0=Done ;bit 1: Unimplemented: Read as '0' ;bit 0: ADON: A/D On bit 1= A/D converter module is operating bank0 movlw b'10000001' ;clock/32 Channel=0 ADON=1 movwf ADCON0 clrf INTCON bsf SCE ;/SCE a 1 bsf DC ;D/C a 1 bsf RST ;/RESET a 1 bcf LEDrouge ;--------------------------------------------------------------------- ;config UART asynchrone PIC 16F877 DIL 40 broches ; pin 25 RC6 Tx ---vert ----- 3 de DS275 --- RS232 --> Ecran ; pin 26 RC7 Rx ---blnc/vert-- 1 de DS275 --- RS232 <-- Clavier ;---------------------------------------------------------------------- ;movlw 0x90 ; SPEN = 1, CREN = 1 ;movwf RCSTA ;configures RC7/RX/DT and RC6/TX/CK pins as serial port CLRF RCSTA ; SYNC=0 asynchrone , mode 8 bits data BSF RCSTA,SPEN ;serial port Enable BSF RCSTA ,CREN ;Enable receiver bank1 CLRF TXSTA ; 8 bits datas IF HIGH_SPEED == 1 ; bsf TXSTA,BRGH ; ELSE bcf TXSTA,BRGH ENDIF bsf TXSTA,TXEN ;transmit enable bit movlw DIVIDER ;generateur de baud rate =32 @10MHz for 19200bds movwf SPBRG bank0 movlw TIMEOUT+1 movwf time ;--------------------------- ;config TIMER1 ;--------------------------- ;T1CON ;b7 : Inutilise : lu comme ® 0 ¯ ;b6 : Inutilise : lu comme ® 0 ¯ ;b5 : T1CKPS1 : Timer 1 oscillator ClocK Prescale Select bit1 0=1 0=2 1=4 1=8 ;b4 ; T1CKPS0 : Timer 1 oscillator ClocK Prescale Select bit0 0 0 1 0 1 ;b3 : T1OSCEN : Timer 1 OSCillator ENable control bit ;b2 : T1SYNC : Timer 1 external clock input SYNChronisation control bit ;b1 : TMR1CS : TiMeR 1 Clock Source select bit ;b0 : TMR1ON : TiMeR 1 ON bit movlw b'00110000' ; prescaler=8 Internal clock=Fosc/4 movwf T1CON movlw LOW (.65536-.15535) movwf TMR1L movlw HIGH (.65536-.15535) movwf TMR1H movlw .20 movwf _10it OUT_RS232 ; bcf Drapeaux,1 ; sortie sur RS232 CALL Rs_CrLf ; purge RS232 call delay_100ms bsf LEDrouge ; eteint Led rouge bcf LEDblanche ; allume led blanche movlw 0 call Msg_Eeprom CALL Rs_CrLf call delay_1s ; mise a l'heure par defaut (pour debugging) btfsc BP_MAL ; si RB1=0 => force valeur par defaut goto Heure_courante MOVLW 0x00 ;00 Sec MOVWF SEC movlW 0X45 ;45 Mn movWF MIN MOVLW 0x16 ; 16 Heure MOVWF HEURE MOVLW 0x06 ;day samedi MOVWF JourSem MOVLW 0x04 ;date 04 MOVWF Jour MOVLW 0x04 ;Mois Avr MOVWF Mois MOVLW 0x09 ; ANNEE=09 MOVWF Annee MOVLW B'10010000' ;Registre de controle SQWE=1 RS0=RS1=0 sortie 1Hz MOVWF CtrlReg CALL Rs_CrLf call Affiche_Time CALL Rs_CrLf call Init_RTC ; la Led sur RTC DS1307 doit clignoter a 1HZ! CALL Rs_CrLf movlw HIGH Txt3 movwf ADR_HI movlw LOW Txt3 movwf ADR_LO CALL aff_char_flash CALL Rs_CrLf call delay_2_5s Heure_courante ; presentation sur PC movlw HIGH Txt0 ; 0x1500 movwf ADR_HI movlw LOW Txt0 ; movwf ADR_LO CALL aff_char_flash CALL Rs_CrLf call Envoi_Aide CALL Rs_CrLf OUT_LCD ; Bsf Drapeaux,1 ; sortie sur LCD call INIT_LCD call CLR_LCD call normal_video ;affiche TRAME de texte FIXE movlw EE1-EE0 call Affiche_Msg movlw EE13-EE0 call Affiche_Msg movlw EE14-EE0 call Affiche_Msg movlw EE5-EE0 ; place bargraph call Affiche_Msg movlw EE2-EE0 call Affiche_Msg movlw .7 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel iorlw b'10000000' ;bit de commande call TX_SPI_C movlw EE21-EE0 call Affiche_Msg bank1 bsf PIE1,TMR1IE ; autoriser interruptions timer 1 bank0 bsf INTCON,GIE ; Autorise ALL IT bsf INTCON,PEIE ; autoriser interruptions peripheriques bsf LEDblanche ; eteint led blanche = fin d'init clrf flags ;*************************************************** Main_Boucle OUT_LCD ;Bsf Drapeaux,1 ; sortie sur LCD clrf dummy movlw .4 xorwf PORTB,f ; clignote led rouge nop call Lecture_DS1307 ;lecture heure movlw .0 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel iorlw b'10000000' ;bit de commande call TX_SPI_C call delay_100ms call Affiche_Time ; sur LCD ; capture eventuelle d'un caractere emis sur la comm bank1 bsf PIE1,RCIE ; Autorise IT Reception bank0 BSF RCSTA,CREN ; enable reception call delay_250ms call delay_250ms ; fenetre temporelle pour saisie caractere call delay_250ms BCF RCSTA,CREN ;disable Reception bank1 bcf PIE1,RCIE ; interdit IT Reception bank0 movf dummy,w ; test contenu de dummy btfsc STATUS,Z goto MAIN4 ; pas de caracteres ;routage et traitement caractere recu ;si car alpha en minuscule -> passe en majuscule movlw 0x60 ; 96 subwf dummy,w btfss STATUS,C goto MAIN2 movlw 0x20 ;32 subwf dummy,f MAIN2 movf dummy,W ; CALL Rs_Putchar ; echo car sur ecran ; CALL Rs_CrLf movlw 'U' ; Update et MAJ horloge RTC xorwf dummy,W btfss STATUS,Z goto Main20 call MAJ_DS1307 goto MAIN4 Main20 movlw 'H' ; Help xorwf dummy,W btfss STATUS,Z goto Main22 movlw .16 xorwf MenuChoice,f goto MAIN4 Main22 movlw 'K' ; Ecriture sur port 8 bits PCF8574_1 via clavier PC xorwf dummy,W btfss STATUS,Z goto Main23 call Ecriture_8bits movlw .4 xorwf MenuChoice,f goto MAIN4 Main23 movlw 'L' ; Lecture sur port 8 bits PCF8574_2 xorwf dummy,W btfss STATUS,Z goto Main24 ;2Eme PCF non installé a ce jour! call Lecture_8bits movlw .8 xorwf MenuChoice,f goto MAIN4 Main24 movlw '1' ;Consigne1 xorwf dummy,W btfss STATUS,Z goto Main25 movlw .32 xorwf MenuChoice,f goto MAIN4 Main25 movlw '2' ;Consigne2 xorwf dummy,W btfss STATUS,Z goto Main26 movlw .64 xorwf MenuChoice,f goto MAIN4 Main26 movlw '3' ; ;Consigne3 xorwf dummy,W btfss STATUS,Z goto Main27 movlw .128 xorwf MenuChoice,f goto MAIN4 Main27 Main31 movlw 'E' ; Ecriture sur port 8 bits PCF8574_1 via XPORT xorwf dummy,W btfss STATUS,Z goto MAIN4 bsf Saisie_Xport call Lecture_Xport_8bits call Ecriture_8bits bcf Saisie_Xport movlw .4 xorwf MenuChoice,f goto MAIN4 MAIN4 bank0 clrf dummy OUT_LCD Channel_Sel 1 bcf Drapeaux,5 ; simili flottant bcf Drapeaux,4 ; affiche 5 digits BCD Call Acquis_Ana bsf Drapeaux,5 ; 1=simili flottant bcf Drapeaux,4 ; 1= affiche 5 digits BCD 0=4digits ;* 5 le resultat call multi_4 ; en Units simili flottant............ movlw .1 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .6*.5 ;X address in pixel 6em car iorlw b'10000000' ;bit de commande call TX_SPI_C call bcd_temp ; remplit le buffer d'affichage ASCII avec val1 call delay_10ms bcf Drapeaux,5 bcf Drapeaux,4 ; affiche 5 digits BCD Channel_Sel 2 Call Acquis_Ana movlw .2 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .6*.4 ;X address in pixel= 5em car iorlw b'10000000' ;bit de commande call TX_SPI_C bcf Drapeaux,5 ; mode XXXXX non sign‚ bcf Drapeaux,4 ; affiche 4 digits bcf RETENUE call bcd_temp ; affichage ASCII call delay_10ms Channel_Sel 3 Call Acquis_Ana movlw .3 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .6*.4 ;X address in pixel= 5em car iorlw b'10000000' ;bit de commande call TX_SPI_C bcf Drapeaux,5 ; mode XXXXX non sign‚ bsf Drapeaux,4 ; affiche 5 digits bcf RETENUE call bcd_temp ; affichage ASCII call delay_10ms bcf Drapeaux,4 ; affiche 5 digits ; Mise a l'echelle 1024 -> 96 pixels bank1 movf val4,w ; recupere derniere valeur ANA acquise et sauvegardee movwf val1 ;Hi movf val4+1,w movwf val1+1 ;Low movlw 0 movwf val2 ;Hi movlw .11 ;1024/96=11 movwf val2+1 ;Low call div16 ; val1 = val1 / val2 bank0 ; Bargraphe 1 ligne de 96 points movlw .4 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .95 movwf Cpt1 Efface movlw .4 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movf Cpt1,W iorlw b'10000000' ;bit de commande call TX_SPI_C movlw b'00000000' ; efface pixels call TX_SPI_D call delay_100us decfsz Cpt1,f goto Efface bank1 clrf result ; MSB movf result+1,w ;LSB -> X address in pixel bank0 XORLW 0 ;si result =0 ..on n'allume rien! BTFSC STATUS,Z goto Entree_Sorties movwf Cpt1 Allume movlw .4 ;Y address in Lines iorlw b'01000000' ;bit de commande call TX_SPI_C movf Cpt1,W iorlw b'10000000' ;bit de commande call TX_SPI_C movlw b'00111100'; Allume les pixels du centre call TX_SPI_D call delay_100us decfsz Cpt1,f goto Allume Entree_Sorties movlw .5 ;Y address in Lines =7eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel= 1er car iorlw b'10000000' ;bit de commande call TX_SPI_C movlw EE2-EE0 call Affiche_Msg movlw EE21-EE0 call Affiche_Msg movlw .6 ;Y address in Lines =8eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .6 *.4 ;X address in pixel= 4 em car iorlw b'10000000' ;bit de commande call TX_SPI_C movf E_value,w call aff_binaire_hexa movlw .7 ;Y address in Lines =7eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel= 1er car iorlw b'10000000' ;bit de commande call TX_SPI_C movlw EE22-EE0 ; lect 8 bits call Affiche_Msg call Lecture_8bits movlw .7 ;Y address in Lines =8eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .6 *.4 ; address in pixel= 5em car iorlw b'10000000' ;bit de commande call TX_SPI_C movf L_value,w call aff_binaire_hexa ; 01010101=55h ; envoi sur RS232 OUT_RS232 call Envoi_Date call Read_Temp_CH0 call Read_Ana_CH1 call Read_Ana_CH2 ; flags,7 call Read_PCF call Rs_Tabul call Write_PCF EnvRS_1 movf MenuChoice,w andlw b'00010000' btfsc STATUS,Z ;16 goto EnvRS_2 call Rs_Tabul call Envoi_Aide EnvRS_2 CALL Rs_CrLf goto Main_Boucle ;******************************************** multi_4 bank1 bcf STATUS,C rlf val1,f rlf val1+1,f rlf val1,f rlf val1+1,f ;4 fois val1 bank0 return Write_PCF movlw EE7-EE0 call Affiche_Msg movlw EE71-EE0 call Affiche_Msg movf E_value,w call aff_binaire_hexa return Read_PCF movlw EE7-EE0 call Affiche_Msg movlw EE72-EE0 call Affiche_Msg movf L_value,w call aff_binaire_hexa return Start_Write OUT_RS232 ; test lecture en Flash 2em partie from 0x1800... movlw HIGH Txt2 movwf ADR_HI movlw LOW Txt2 ; movwf ADR_LO CALL aff_char_flash CALL Rs_CrLf OUT_LCD return Lecture_EE OUT_RS232 ; test lecture en Flash 2em partie from 0x1800... movlw HIGH Txt2 movwf ADR_HI movlw LOW Txt2 ; movwf ADR_LO CALL aff_char_flash CALL Rs_CrLf OUT_LCD return ; affiche chaine de caractere en memoire Flash ; termine sur car=0 ou apres car=13 aff_char_flash call read_flash ANDLW 0x0FF BTFSC STATUS, Z Return CALL Output_Char ; movf caractere ; ANDLW 0x0D ; CR ; BTFSC STATUS, Z ; Return incf ADR_LO,f goto aff_char_flash read_flash bank2 ;Attention textes dans la meme page de 256 bytes ; movlw HIGH Txt0 ; 0x1500 ; movwf ADR_HI ; movlw HIGH Txt0 ; adresse en DUR ! movf ADR_HI,W movwf EEADRH movf ADR_LO,W movwf EEADR bank3 bsf EECON1,EEPGD ;Point to Program memory bsf EECON1,RD ;Start read operation NOP NOP bank2 nop movf EEDATA,W ;DATAL = EEDATA bank0 return ;-------------------------- Envoi_Date bank0 clrf dummy movlw 0x20 CALL Rs_Putchar ; echo car sur ecran Terminal call Affiche_Time call Rs_Tabul call Rs_Tabul return ;---------------------------- Envoi_Aide clrf dummy CALL Rs_CrLf movlw HIGH Txt1 movwf ADR_HI movlw LOW Txt1 ; movwf ADR_LO CALL aff_char_flash CALL Rs_CrLf bcf Aff_Aide return ;----------------------------- ReadCH clrf dummy movlw 'E' CALL Output_Char movlw 'A' CALL Output_Char return Read_Temp_CH0 call ReadCH bcf Drapeaux,5 ; simili flottant bcf Drapeaux,4 ; affiche 5 digits BCD movlw '1' CALL Output_Char movlw '=' CALL Output_Char Channel_Sel 1 Call Acquis_Ana ;* 5 le resultat call multi_4 bsf Drapeaux,5 ; simili flottant bcf Drapeaux,4 ; affiche 5 digits BCD goto aff_read_Ana ;----------------------- Read_Ana_CH1 bcf Drapeaux,5 bcf Drapeaux,4 ; affiche 5 digits BCD call ReadCH movlw '2' CALL Output_Char movlw '=' CALL Output_Char Channel_Sel 2 goto Read_Ana_CHx ;------------------------- Read_Ana_CH2 bcf Drapeaux,5 ; xxxxx bsf Drapeaux,4 ; affiche 4 digits BCD call ReadCH movlw '3' CALL Output_Char movlw '=' CALL Output_Char bank0 Channel_Sel 3 ;--- Read_Ana_CHx Call Acquis_Ana ; bcf RETENUE aff_read_Ana call bcd_temp ; affichage ASCII call Rs_Tabul clrf dummy return ;------------------------- Ecriture_8bits movlw .5 ;Y address in Lines =7eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel= 1er car iorlw b'10000000' ;bit de commande call TX_SPI_C movlw EE2-EE0 call Affiche_Msg movlw .6 ;Y address in Lines =8eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .6 *4 ;X address in pixel= 5 em car iorlw b'10000000' ;bit de commande call TX_SPI_C bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movlw LOW Buffin ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractRre sera le premier bcf STATUS,IRP ;call Saisie_Clavier ; par paquet ; Saisie_Clavier avec echo sur LCD btfss Saisie_Xport ; saute si reception via XPORT call Saisie_car_by_car ; btfsc Saisie_Xport ; call Lecture_Xport_8bits movlw .6 ;Y address in Lines =8eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .6 *4 ;X address in pixel= 5 em car iorlw b'10000000' ;bit de commande call TX_SPI_C clrf value Movlw .128 Movwf _N1 bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movlw LOW Buffin-1 ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractRre sera le premier Decode_8b1 bsf STATUS,IRP ; pointer banques 2 et 3 en indirect incf Buff_In_Ptr,f ; incrementer pointeur de caracteres movf Buff_In_Ptr,w movwf FSR ; dans pointeur d'adresse movf INDF,w ; lecture buffer ex: '0' bank0 bcf STATUS,IRP ; pointer banques 2 et 3 en indirect movwf dummy movwf caractere call Affiche_Char movlw '1' xorwf dummy,W btfss STATUS,Z goto Decode_8b2 movf _N1,w iorwf value,f ; mise a jour value Decode_8b2 bcf STATUS,C rrf _N1,f ; divide par 2 btfss STATUS,C ; sortie bit sur Carry? goto Decode_8b1 ; non continue.. movf value,w movwf E_value call Ecriture_PCF8574 clrf dummy return ;----------------------------------- ;avec echo direct sur LCD Saisie_car_by_car movf RCREG,w ; vide registre bcf Abort_Saisie BCF Fin_de_saisie saisicar_1 clrf dummy bank1 bsf PIE1,RCIE ; Autorise IT Reception bank0 BsF RCSTA,CREN ; enable reception saisicar_11 movf dummy,w Btfsc STATUS,Z goto saisicar_11 BCF RCSTA,CREN ;disable Reception bank1 bcf PIE1,RCIE ; disable IT Reception bank0 btfsc Fin_de_saisie ; si OA ou OD goto saisicar_20 movf dummy,w ; lecture copie du car movwf caractere CALL Rs_Putchar ; DEBUG echo car sur ecran TERMINAL RS232 saisicar_12 xorlw .27 ; comparer avec ESC btfsc STATUS,Z ; identique? bsf Abort_Saisie btfsc STATUS,Z ; identique? goto saisicar_30 ; oui, fin de message movf dummy,w movf caractere,w call Affiche_Char saisicar_13 btfss Fin_de_saisie goto saisicar_1 saisicar_20 bank0 BCF Fin_de_saisie ; clrf dummy return saisicar_30 bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movlw LOW Buffin ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractRre sera le premier bcf STATUS ,IRP clrf dummy bank0 BCF Fin_de_saisie return ;--------------------------------------------- ; saisie XPORT Lecture_Xport_8bits bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movlw LOW Buffin ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractRre sera le premier bcf STATUS ,IRP bank0 movf RCREG,w ; vide registre bcf Abort_Saisie BCF Fin_de_saisie saisicar_X1 clrf dummy bank1 bsf PIE1,RCIE ; Autorise IT Reception bank0 BsF RCSTA,CREN ; enable reception saisicar_X11 movf dummy,w Btfsc STATUS,Z goto saisicar_X11 BCF RCSTA,CREN ;disable Reception bank1 bcf PIE1,RCIE ; disable IT Reception bank0 btfsc Fin_de_saisie goto saisicar_X30 ; movwf caractere ; call Affiche_Char bank0 goto saisicar_X1 ; next car saisicar_X30 clrf dummy bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movlw LOW Buffin ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractRre sera le premier bcf STATUS ,IRP bank0 BCF Fin_de_saisie return ;------------------------------------------------------------- ; affiche le contenu de "W" en 8 bits binaire et hexadecimal ; uses value,dummy,btmp,caractere aff_binaire_hexa movwf dummy movwf value bank1 movlw .8 movwf btmp bank0 aff_b1 bcf STATUS,C rlf value,f btfss STATUS,C movlw '0' btfsc STATUS,C movlw '1' movwf caractere CALL Output_Char bank1 decf btmp,f bank0 btfss STATUS ,Z goto aff_b1 movlw '=' movwf caractere CALL Output_Char movf dummy,w movwf value ;------------------------ ; affichage octet (W) --> hexadecimal 2 digits ( de 00 a FF )sur LCD hex8 swapf value,W andlw 0x0f addlw -0x0a btfsc STATUS,C addlw 0x07 addlw 0x3a movwf caractere CALL Output_Char bank1 movf btmp,W bank0 movf dummy,W andlw 0x0f addlw -0x0a btfsc STATUS, C addlw 0x07 addlw 0x3a movwf caractere CALL Output_Char movlw 'h' movwf caractere CALL Output_Char return ;======================================================== ; saisie de 14 caracteres definissant la date et heure ; AAMMJJXXHHMMSS terminateur = CR ou LF (ou ESC=Abort) ; rangement des valeurs correspondantes dans le buffer + CR+LF ; puis tranlation des couples de caracteres en valeur BCD ; ANNEE MOIS JS JOUR HEURE SECONDE ;JS jour de la semaine Lundi=00 a dimanche=06 ; MAJ_DS1307 OUT_RS232 movlw EE4-EE0 call Affiche_Msg call Rs_CrLf OUT_LCD movlw .5 ;Y address in Lines =7eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel= 1er car iorlw b'10000000' ;bit de commande call TX_SPI_C movlw EE3-EE0 call Affiche_Msg ; affiche saisie buffer input movlw .7 ;Y address in Lines =8eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel= 1er car iorlw b'10000000' ;bit de commande call TX_SPI_C bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movlw LOW Buffin ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractRre sera le premier ; Saisie_Clavier avec attente 1 car call Saisie_car_by_car movlw .7 ;Y address in Lines =8eme iorlw b'01000000' ;bit de commande call TX_SPI_C movlw .0 ;X address in pixel= 1er car iorlw b'10000000' ;bit de commande call TX_SPI_C btfsc Abort_Saisie return ; rangement ASCII -> BCD clrf _N1 bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movlw LOW Buffin ; oui, adresse de depart du buffer d'entree movwf Buff_In_Ptr ; prochain caractere sera le premier Decode_Date bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movf Buff_In_Ptr,w movwf FSR ; dans pointeur d'adresse movf INDF,w ; lecture buffer ex: '0' incf Buff_In_Ptr,f ; incrementer pointeur de caracteres bank0 movwf dummy ; CALL Output_Char movlw 0x0F Andwf dummy,f BCF STATUS,C rlf dummy,f rlf dummy,f rlf dummy,f rlf dummy,f ;@@ reactivé la ligne cidessous le 08/03/09 @@ bsf STATUS,IRP ; pointer banques 2 et 3 en indirect movf Buff_In_Ptr,w movwf FSR movf INDF,w ; lecture buffer ex: '8' incf Buff_In_Ptr,f ; incrementer pointeur de caracteres bank0 ; CALL Output_Char ANDLW 0x0F addwf dummy,w ;=08H movwf dummy bcf STATUS,IRP movf _N1,W ;pointer de rangement addlw Buffer_MAJ ; offset table movwf FSR movf dummy,w movwf INDF ; CALL Rs_Putchar ; echo car sur ecran incf _N1,f ;14 cars btfss _N1,3 ; boucle si < 8 goto Decode_Date call Init_RTC call delay_1s return ;----------------------------------------- ;#define OFFSET_ANA .512 Acquis_Ana ; acquisition Analogique bank0 ; bcf ADCON0,CHS1 ; bcf ADCON0,CHS2 ; btfsc Drapeaux,2 ; si =1 selection RA1 ANA ; bsf ADCON0,CHS0 ; btfss Drapeaux,2 ; bcf ADCON0,CHS0 nop bsf ADCON0,ADON ; Test si Validation conversion ANA (ADCON0,0=1) call delay_25us bsf ADCON0,GO_DONE ; Arme la conversion (ADCON0,2=1) bcf RETENUE ; Positif not_yet btfsc ADCON0,NOT_DONE ; conversion AD ok ?(ADCON0,2=0 ???) goto not_yet bank0 movf ADRESH,w bank1 movwf val1 movwf val3 ; sauvegarde valeur ANA MSB movf ADRESL,w movwf val1+1 movwf val3+1 ; sauvegarde valeur ANA LSB bank0 ; ; btfss Drapeaux,5 ; mode XXX.XX sign‚ ? ; goto Posit1 ; bank1 ; movlw High(OFFSET_ANA) ; (Nb Points- offset de 512) ; movwf val2 ; movlw Low(OFFSET_ANA) ; movwf val2+1 ; call sub16 ; val1=val1-val2 ; btfss val1,7 ; btfss STATUS,C bit de signe ? ; goto Posit1 ; bank0 ; bsf RETENUE ; car valeur negative! ; bank1 ; COMF val1,f ; COMF val1+1,f Posit1 call delay_10ms bank1 movf val3,w movwf val4 movf val3+1,w movwf val4+1 bank0 bcf ADCON0,ADON return ;---------------------------------------- Affiche_Msg bank0 movwf Cpt1 Aff_Msg1 movf Cpt1,w call Read_EE movwf caractere incf Cpt1,f ANDLW 0x0FF BTFSC STATUS, Z Return movf caractere ,w call Output_Char goto Aff_Msg1 return ;------ print char 6x8 pixels ---- Affiche_Char bcf PCLATH,3 clrf offset_caractr bsf PCLATH,4 call Search_In_ascii_Table ; col 1 du caractere bcf PCLATH,4 call TX_SPI_D ; incf offset_caractr,F bsf PCLATH,4 call Search_In_ascii_Table ;col 2 du caractere bcf PCLATH,4 call TX_SPI_D incf offset_caractr,F bsf PCLATH,4 call Search_In_ascii_Table ;col 3 du caractere bcf PCLATH,4 call TX_SPI_D incf offset_caractr,F bsf PCLATH,4 call Search_In_ascii_Table ;col 4 du caractere bcf PCLATH,4 call TX_SPI_D incf offset_caractr,F bsf PCLATH,4 call Search_In_ascii_Table ;col 5 du caractere bcf PCLATH,4 call TX_SPI_D incf offset_caractr,F bsf PCLATH,4 call Search_In_ascii_Table ;col 6 du caractere bcf PCLATH,4 call TX_SPI_D incf offset_caractr,F return ;************************************************** ;Routines de control du LCD NOKIA 3310 en mode SPI ;************************************************** INIT_LCD call CFG_SPI ;configuration mode SPI movlw d'80' call delay call RST_LCD ;reset LCD movlw d'80' call delay call SET_LCD ;initialisation LCD movlw d'80' call delay call CLR_LCD ;Raz ecran movlw d'80' call delay return ;********************************* ;Configuration du port serie SPI ;*********************************** CFG_SPI ;voir AN735 ;set I2C rate =((FOSC/Bitrate)/4)-1; ;8000000/1000000=80 80/4=20 20-1=19 movlw .19 ; setup value banksel SSPADD ; select SFR bank movwf SSPADD ; baud rate = 100KHz @ 8MHz movlw b'00000000' movwf SSPSTAT bank0 ; Registre de configuration SSPCON ; SSPEN <5> Enable=1 ; SSPM3:SSPM0 Hardware master mode=1000 ; I2C master mode, clock = FOSC / (4 * (SSPADD+1) ) movlw b'00101000' movwf SSPCON return ; Generation d'un Reset pour initialiser le LCD3310 RST_LCD bcf RST ; reset au niveau bas call delay_1ms ;retard bsf RST ; reset niveau haut nop return ;============================== ;Inicialisation du LCD SET_LCD ;Function SET: 00100_PD_V_H ; PD=0=>chip active ; V =0 =>Addressage Horizontal ; H =1 => extended instructions set movlw b'00100001' call TX_SPI_C ;Set VOP : 1_VOP6..VO0 ;VLCD = a + (VOP6 to VOP0)* b [V]. ; a = 3.06 and b = 0.06 soit 3,00 a 10,68V a T Amb ; movlw b'11001011' ;3.06+75*0.06=8.1 movlw b'10010000' ;3.06+162*0.06=4.02 call TX_SPI_C ; compensation temperature TC0 TC1 movlw b'00000101' ; TC0=1 TC1=0 call TX_SPI_C ;bias System : 000010_BS2_BS1_BS0 movlw b'00010011' ;bias System 1:48 -> n=4 call TX_SPI_C ;Function SET: 00100_PD_V_H ; PD=0=>chip active ; V =0 =>Addressage Horizontal ; H =0 => normal instructions set movlw b'00100000' ;chip activo, H=0 call TX_SPI_C ;Display mode control set : 00001_D_0_E ; D=1 ; E=0 call delay_1ms movlw b'00001100' ;mode [Normal mode] call TX_SPI_C return ;================================= ;RAZ memoire RAM LCD CLR_LCD movlw .0 ;Y address call Y_address movlw .0 ;X address call X_address movlw b'00001000' ; mode Display Blank call TX_SPI_C ; envoi Commande movlw d'9' ;8 movwf BoucleExt Bint movlw d'96' ;96 =768 movwf BoucleInt Bint1 movlw b'00000000' call TX_SPI_D ;envoi Data decfsz BoucleInt,f goto Bint1 decfsz BoucleExt,f goto Bint movlw .0 ;Y address call Y_address movlw .0 ;X address call X_address return ;position X contenue dans W X_address iorlw b'10000000' ;bit de commande call TX_SPI_C return ;position Y contenue dans W Y_address iorlw b'01000000' ;bit de commande call TX_SPI_C return ;video inverse Invert_video movlw b'00001101' ;mode [Inverse video mode] call TX_SPI_C return ;video normal normal_video movlw b'00001100' ;mode [normal mode] call TX_SPI_C return ;Transmision de Cde TX_SPI_C bcf DC ;Mode COMMANDE nop ;Transmision de donnees TX_SPI_D bcf SCE ;enable display! movwf SSPBUF ;Transmission sur port SPI TXSPID1 btfss PIR1,SSPIF ; goto TXSPID1 bcf PIR1,SSPIF nop nop bsf SCE ;display OFF nop nop bsf DC ;Mode DATA (par defaut) nop nop return ;=================== Rs_CrLf bank0 movlw .13 call Rs_Putchar movlw .10 call Rs_Putchar return ;--------------- Rs_Tabul bank0 movlw .9 call Rs_Putchar return ;--------------- Output_Char bank0 movwf caractere btfsc Drapeaux,1 call Affiche_Char btfss Drapeaux,1 call Rs_Putchar return ;--------------- Rs_Putchar bank0 clrwdt Rs_P1 btfss PIR1,TXIF ; while(!TXIF) goto Rs_P1 movwf TXREG ; TXREG = octet return ;--------------- Msg_Eeprom bank0 movwf Cpt1 Msg_eep1 movf Cpt1,w call Read_EE movwf caractere incf Cpt1,f ANDLW 0x0FF BTFSC STATUS, Z Return movf caractere,w call Output_Char goto Msg_eep1 return ;------- ; subroutine to read EEPROM memory ;(adresse & resultat en w) Read_EE ; 16F876 bank2 MOVWF EEADR ;Data Memory Address to read bank3 BCF EECON1, EEPGD ;Point to DATA memory BSF EECON1, RD ;EEPROM Read bank2 MOVF EEDATA, W bank0 return ;------------ Rs_Getchar clrwdt movf time,w btfsc STATUS,Z ; regarder si time==0 goto getchar3 btfss PIR1,TMR1IF ; regarder si le TIMER1 a deborde goto getchar3 ; pas de debordement bcf T1CON,TMR1ON ; timeout 0.1 sec decfsz time,f ; time-- goto getchar2 retlw 0 ; if time==0 then return getchar2 bcf PIR1,TMR1IF movlw high TIMER movwf TMR1H ; preset TIMER1 for 0.1s timeout bsf T1CON,TMR1ON getchar3 btfss PIR1,RCIF ; while(!RCIF) goto Rs_Getchar movf RCREG,w ; RCREG return ;========================================= ; conv mot 16bits --> en XX.XXøC 25.42øC bcd_temp bank1 movf val1,W movwf valx movf val1+1,W movwf valx+1 swapf valx,W iorlw 0xf0 movwf mille addwf mille,F addlw 0xE2 ; 226 movwf cent addlw 0x32 ;50 movwf un movf valx,W andlw 0x0F addwf cent,F addwf cent,F addwf un,F addlw 0xE9 ;233 movwf dix addwf dix,F addwf dix,F swapf valx+1,W ;<- modif 20mars03 was val1 andlw 0x0F addwf dix,F addwf un,F rlf dix,F rlf un,F comf un,F rlf un,F movf valx+1,W andlw 0x0F addwf un,F rlf mille,F movlw 0x07 movwf dixmil movlw 0x0A Lb1: addwf un,F decf dix,F btfss STATUS,C goto Lb1 Lb2: addwf dix,F decf cent,F btfss STATUS,C goto Lb2 Lb3: addwf cent,F decf mille,F btfss STATUS,C goto Lb3 Lb4: addwf mille,F decf dixmil,F btfss STATUS,C goto Lb4 bank0 btfss Drapeaux,5 ; 1 => affichage 00000 a 999999 goto Bcd5ascii ; 0 => affichage + ou - XXX.XX movlw '+' btfsc RETENUE movlw '-' call Output_Char bank1 movf mille,w btfss STATUS,Z ; si digit=0 remplace par Blanc goto Lb5 bank0 movlw ' ' call Output_Char goto Lb6 Lb5 bank0 addlw '0' call Output_Char Lb6 bank1 movf cent,w addlw '0' call Output_Char movlw '.' call Output_Char bank1 movf dix,w addlw '0' call Output_Char bank1 movf un,w addlw '0' call Output_Char return ;--------------- Bcd5ascii btfss Drapeaux,4 ; 0=4 digits 1=5 digits goto Bcd4ascii bank1 movf dixmil,w addlw '0' call Output_Char Bcd4ascii bank1 movf mille,w addlw '0' call Output_Char Bcd3ascii bank1 movf cent,w addlw '0' call Output_Char bank1 movf dix,w addlw '0' call Output_Char bank1 movf un,w addlw '0' call Output_Char movlw ' ' call Output_Char return ;======================= Affiche_Time bank0 SWAPF Jour,W ANDLW 0x0F ; btfss STATUS,Z ;@ 5/2/07 ; goto Aff_T1 ; remplace 0 par espace en tete de message ; movlw 0x20 ; espace ; goto Aff_T2 ;Aff_T1 ADDLW 30H Aff_T2 CALL Output_Char MOVF Jour,W ANDLW 0FH ADDLW 30H CALL Output_Char MOVLW "/" CALL Output_Char SWAPF Mois,W ANDLW 0x0F ADDLW 30H CALL Output_Char MOVF Mois,W ANDLW 0FH ADDLW 30H CALL Output_Char btfsc Drapeaux,1 MOVLW " " btfss Drapeaux,1 MOVLW "/" CALL Output_Char btfsc Drapeaux,1 ; si sortie RS232 rajoute annéee goto Aff_T21 SWAPF Annee,W ANDLW 0x0F ADDLW 30H CALL Output_Char MOVF Annee,W ANDLW 0FH ADDLW 30H CALL Output_Char Aff_T21 MOVLW " " CALL Output_Char Affiche_Heure SWAPF HEURE,W ANDLW 0x0F btfss STATUS,Z ;@ 5/2/07 goto Aff_T3 movlw ' ' goto Aff_T4 Aff_T3 ADDLW 30H Aff_T4 CALL Output_Char MOVF HEURE,W ANDLW 0x0F ADDLW 30H CALL Output_Char MOVLW "H" CALL Output_Char SWAPF MIN,W ANDLW 0x0F ADDLW 30H CALL Output_Char MOVF MIN,W ANDLW 0FH ADDLW 30H CALL Output_Char MOVLW "M" CALL Output_Char SWAPF SEC,W ANDLW 0x0F ADDLW 30H CALL Output_Char MOVF SEC,W ANDLW 0FH ADDLW 30H CALL Output_Char MOVLW "S" CALL Output_Char return ;-------------------------------------- ; The following routines are low level I2C routines applicable to most ; interfaces with I2C devices. ;---------------------------------------- I2C_DELAY goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 return ;--------------- START: bsf STATUS,RP0 bcf I2C_SDA bcf STATUS,RP0 bsf I2C_SDA bsf I2C_SCL ;I2C start: change of SDA call I2C_DELAY ;from 1 to 0 while SCL = 1 bcf I2C_SDA call I2C_DELAY bcf I2C_SCL return ;--------------------- STOP: bsf STATUS,RP0 bcf I2C_SDA bcf STATUS,RP0 bcf I2C_SDA bsf I2C_SCL ;I2C stop: change of SDA call I2C_DELAY ;from 0 to 1 while SCL = 1 bsf I2C_SDA return ;--------------------- M_ACK: bsf STATUS,RP0 bcf I2C_SDA bcf STATUS,RP0 bcf I2C_SDA ;I2C master acknowledge: call I2C_DELAY ;SDA = 0 bsf I2C_SCL call I2C_DELAY bcf I2C_SCL return ;---------- NACK: bsf STATUS,RP0 bcf I2C_SDA bcf STATUS,RP0 bsf I2C_SDA ;I2C master non-acknowledge: call I2C_DELAY ;SDA = 1 bsf I2C_SCL call I2C_DELAY bcf I2C_SCL return ;----------- ACK: bsf STATUS,RP0 bsf I2C_SDA bcf STATUS,RP0 call I2C_DELAY ;I2C device acknowledge: bsf I2C_SCL ;SDA set 1 by master call I2C_DELAY ;SDA = 1 if device doesn't ACK bsf STATUS,Z ;SDA = 0 if devcie acknowledges btfsc I2C_SDA bcf STATUS,Z ;STATUS,Z=1 if device acknowledges bcf I2C_SCL ;STATUS,Z=0 if device doesn't ACK return ;------------ CLOCK_PULSE: ; SCL momentarily to logic one CALL HIGH_SCL call I2C_DELAY CALL LOW_SCL call I2C_DELAY RETURN ;------------ HIGH_SDA: ; high impedance by making SDA an input BSF I2C_SDA bank1 nop BSF I2C_SDA ; make SDA pin an input bank0 call I2C_DELAY RETURN ;------------ LOW_SDA: bank1 BCF I2C_SDA ; make SDA pin an output bank0 nop BCF I2C_SDA call I2C_DELAY RETURN ;------------ HIGH_SCL: BSF I2C_SCL bank1 nop BSF I2C_SCL ; make SCL pin an input bank0 call I2C_DELAY RETURN ;------------ LOW_SCL: bank1 BCF I2C_SCL ; make SCL pin an output bank0 BCF I2C_SCL call I2C_DELAY RETURN ;--------------------- ; The following routines are low level I2C routines applicable to most ; interfaces with I2C devices. IN_BYTE ; read byte on i2c bus CLRF I_BYTE MOVLW .8 MOVWF _N0 ; set index to 8 CALL HIGH_SDA ; be sure SDA is configured as input IN_BIT CALL HIGH_SCL ; clock high BTFSS I2C_SDA ; test SDA bit GOTO IN_ZERO GOTO IN_ONE IN_ZERO BCF STATUS, C ; clear any carry RLF I_BYTE, F ; i_byte = i_byte << 1 | 0 GOTO CONT_IN IN_ONE BCF STATUS, C ; clear any carry RLF I_BYTE, F INCF I_BYTE, F ; i_byte = (i_byte << 1) | 1 GOTO CONT_IN CONT_IN CALL LOW_SCL ; bring clock low DECFSZ _N0, F ; decrement index GOTO IN_BIT RETURN ;------------- OUT_BYTE: ; send o_byte on I2C bus MOVWF O_BYTE MOVLW .8 MOVWF _N0 OUT_BIT: BCF STATUS,C ; clear carry RLF O_BYTE, F ; left shift, most sig bit is now in carry BTFSS STATUS, C ; if one, send a one GOTO OUT_ZERO GOTO OUT_ONE OUT_ZERO: CALL LOW_SDA ; SDA at zero CALL CLOCK_PULSE CALL HIGH_SDA GOTO OUT_CONT OUT_ONE: CALL HIGH_SDA ; SDA at logic one CALL CLOCK_PULSE GOTO OUT_CONT OUT_CONT: DECFSZ _N0, F ; decrement index GOTO OUT_BIT RETURN ;--------------- Init_RTC CALL STOP call delay_25ms CALL START MOVLW DEV_DS1307; B'11010000'=0xD0 = adresse device CALL OUT_BYTE CALL ACK clrf ADDR MOVF ADDR, W ; addresse registre CALL OUT_BYTE CALL ACK MOVF SEC,W CALL OUT_BYTE CALL ACK ; a ce momment la led connectee sur pin7 doit osciller a 1HZ ! MOVf MIN,W CALL OUT_BYTE CALL ACK Movf HEURE,w CALL OUT_BYTE CALL ACK Movf JourSem,w ;Jour de la semaine=07 CALL OUT_BYTE CALL ACK Movf Jour,w ;Jour du mois=02 CALL OUT_BYTE CALL ACK MOVF Mois,W ;Mois= 12 CALL OUT_BYTE CALL ACK MOVF Annee,W ;ANNEE=07 CALL OUT_BYTE CALL ACK MOVLW B'10010000' ;Registre de controle SQWE=1 RS0=RS1=0 sortie 1Hz CALL OUT_BYTE CALL NACK call STOP call delay_25ms return ;----------------------------- Lecture_DS1307 Call STOP call delay_25us CALL START movlw DEV_DS1307 CALL OUT_BYTE CALL ACK clrf ADDR ; adresse 0 MOVF ADDR, W ; send high byte of address CALL OUT_BYTE CALL ACK movlw DEV_DS1307+1 CALL START ;genere un start bit movlw DEV_DS1307+1 CALL OUT_BYTE CALL NACK ;-------- CALL IN_BYTE Call M_ACK MOVF I_BYTE,W MOVWF SEC CALL IN_BYTE Call M_ACK MOVF I_BYTE,W MOVWF MIN CALL IN_BYTE Call M_ACK MOVF I_BYTE,W MOVWF HEURE CALL IN_BYTE Call M_ACK MOVF I_BYTE,W MOVWF JourSem CALL IN_BYTE Call M_ACK MOVF I_BYTE,W MOVWF Jour CALL IN_BYTE Call M_ACK MOVF I_BYTE,W MOVWF Mois CALL IN_BYTE Call M_ACK MOVF I_BYTE,W MOVWF Annee ; CALL IN_BYTE ; Call M_ACK ; MOVF I_BYTE,W ; MOVWF CtrlReg ; call M_ACK CALL STOP return ;------------------------------- div16 ; assume all data in bank1 bcf STATUS,C clrf reste ; division 16 bits clrf reste+1 ; val1 = val1 / val2 ( reste ) movlw .16 movwf Mcount div161 rlf val1+1,f rlf val1,f rlf reste+1,f rlf reste,f movf val2,w subwf reste,W btfss STATUS,Z goto div162 movf val2+1,W subwf reste+1,W div162 btfss STATUS,C goto div163 movf val2+1,W subwf reste+1,f movf val2,W btfss STATUS,C incfsz val2,f subwf reste,f div163 rlf result+1,f rlf result,f DECFSZ Mcount,f goto div161 fin16 movf result,w movwf val1 movf result+1,w movwf val1+1 return ;-------------------- sub16 bank1 bcf STATUS,C movf val2+1,W ; source subwf val1+1,F ; dest movf val2,W btfss STATUS,C incfsz val2,W subwf val1,F ;dest = dest - source, WITH VALID CARRY return ;*******************************************************************; ; Multiplication : ACCb(16 bits) * ACCa(16 bits) -> ACCb,ACCc ( 32 bits ) ; (a) Load the 1st operand in location ACCaLO & ACCaHI ( 16 bits ) ; (b) Load the 2nd operand in location ACCbLO & ACCbHI ( 16 bits ) ; (c) CALL D_mpy ; (d) The 32 bit result is in location ( ACCbHI,ACCbLO,ACCcHI,ACCcLO ) ;*******************************************************************; ; ( ACCb*ACCa -> ACCb,ACCc ) : 32 bit output with high word ; in ACCb ( ACCbHI,ACCbLO ) and low word in ACCc ( ACCcHI,ACCcLO ). D_mpyS ;results in ACCb(16 msb's) and ACCc(16 lsb's) call setupmult bcf STATUS,C mloop rrf ACCdHI,F ;rotate d right rrf ACCdLO,F btfss STATUS,C ;need to add? goto No_add movf ACCaLO,W ; Addition ( ACCb + ACCa -> ACCb ) addwf ACCbLO,F ;add lsb btfsc STATUS,C ;add in carry incf ACCbHI,F movf ACCaHI,W addwf ACCbHI,F ;add msb No_add rrf ACCbHI,F rrf ACCbLO,F rrf ACCcHI,F rrf ACCcLO,F decfsz temp,F ;loop until all bits checked goto mloop return ; Double Precision Addition ( ACCb + ACCa -> ACCb ) ; D_add bcf Flags,C ;Clear temp Carry bit movf ACCaLO,W ; Addition ( ACCb + ACCa -> ACCb ) addwf ACCbLO,F ;add lsb btfsc STATUS,C ;add in carry incf ACCbHI,F btfsc STATUS,C bsf Flags,C movf ACCaHI,W addwf ACCbHI,F ;add msb btfsc Flags,C bsf STATUS,C return ; setupmult movlw .16 ; for 16 shifts movwf temp movf ACCbHI,W ;move ACCb to ACCd movwf ACCdHI movf ACCbLO,W movwf ACCdLO clrf ACCbHI clrf ACCbLO end1 return ;==================================== ;delaisfQ.inc pour Fquartz=X ;definition f(Quartz) ;a declarer dans le programme principale : ; #define Quartz 32 ; valeur du Quartz employe ; count1 ;delay routines ; count2 ;delay routines ; count3 ;delay routines ;delay_RS ; f(quartz) ;delay1 ; 5(count3-1)+1282(count2-1)+32764(count1-1)+6 ;delay_25us ;delay_100us ;delay_1ms ;delay_10ms ;delay_25ms ;delay_100ms ;Delay_1sec ;Delay_2_5sec ;delay_10sec ;------------------------------------ delay_25us movlw 0x01 movwf count1 movlw 0x01 movwf count2 movlw .5*Quartz/4 movwf count3 goto delay1 delay_100us movlw 0x01 movwf count1 movlw 0x01 movwf count2 movlw .20*Quartz/4 movwf count3 goto delay1 delay_1ms movlw 0x01 ; 1,001 mS /4Mhz movwf count1 ; 1,13 ms / 32Mhz movlw 1*Quartz/4 movwf count2 movlw .200/(Quartz/4) movwf count3 goto delay1 delay_10ms movlw 0x01 ; 9,99 ms / 4Mhz movwf count1 ; 10,2mS /32Mhz movlw (.8*Quartz/4) ; 10,1mS /16Mhz movwf count2 movlw .204 movwf count3 goto delay1 delay_25ms movlw 0x01 ;24,36mS /4Mhz movwf count1 ;25,4mS /32Mhz movlw (.20*Quartz/4) movwf count2 movlw 0x01 movwf count3 goto delay1 delay_100ms movlw 1+(Quartz/.16) movwf count1 movlw (.79+(Quartz*.10/.4)) movwf count2 movlw .1 movwf count3 goto delay1 delay_250ms movlw .1+ (Quartz*.6/.32) movwf count1 movlw .196 /(Quartz/.4) movwf count2 movlw .1 movwf count3 goto delay1 delay_1s movlw .4*Quartz/.4 movwf count1 movlw .14 movwf count2 movlw .56 movwf count3 goto delay1 delay_2_5s movlw .8 * (Quartz/.4) movwf count1 movlw (.640 /Quartz) movwf count2 movlw .218 movwf count3 goto delay1 delay1 decfsz count3,f goto $-1 decfsz count2,f goto $-3 decfsz count1,f goto $-5 return ;------------------------ delay movwf OUTER out_loop call delay_1ms decfsz OUTER,F goto out_loop return ;********************************************* ; Subroutines ;********************************************* ;------------------------------- Ecriture_PCF8574 call STOP call delay_25us CALL START movlw DEV_PCF8574_1 ; @48H adresse device CALL OUT_BYTE CALL ACK MOVF E_value,W CALL OUT_BYTE CALL NACK call STOP return ;------------------------------------------------------- Lecture_8bits Call STOP call delay_25us CALL START movlw DEV_PCF8574_1 ADDLW 1 CALL OUT_BYTE CALL ACK CALL IN_BYTE MOVF I_BYTE,W MOVWF L_value call NACK ; Call M_ACK; <- PB .. affecte lecture DS1307 ?? call STOP clrf dummy return NOP z_Fin_Sub EQU $ IF (z_Fin_Sub >= 0x1000 ) ERROR "Attention debordement sur TABLE CAR" ENDIF z_reste_dispo EQU 0x1000 - z_Fin_Sub ;******************************************************************************* org 0x1000 ;position de la table en memoire Flash de programe ;RECHERCHE DANS TABLE DE CARACTERES ASCII Search_In_ascii_Table movf caractere,W movwf ACCaLO ;valeur ascii comme premier operande de la multiplication movlw .0 ; A Raz Resultat HI movwf ACCaHI movwf ACCbHI ;B Raz resultat HI movlw .6 movwf ACCbLO ;second operande de la multiplication bcf PCLATH,4 call D_mpyS ; multiplication valeur ascii par 6 ;------------------------------------ movlw .16 ;position de la table ascii en page movwf PCLATH ; initailise compteur de page movlw init_table ; Charge la position relative de la table movwf Progression movf ACCcHI,W ; resultat HI multipilcation -> W addwf PCLATH,F ; charge PAGE movf ACCcLO,W ; Resulta LO de la multiplication addwf offset_caractr,W; rajoute position de la colonne dan sle caractere btfsc STATUS,C ; test si depassement incf PCLATH,F ;si oui incremente PCLATH addwf Progression,F btfsc STATUS,C ;test si depassement incf PCLATH,F ;si oui incremente PCLATH ;matrice 6x8 pour caractere 5x7 , contient donc l'inter espace caractere ; 96 pixels -> 16 car de (5+1) pixels de large init_table addwf PCL,F ; Police6x8 include <./police_6x7.txt> ;police_6x8.txt dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x00 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x01 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x02 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x03 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x04 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x05 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x06 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x07 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x08 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x09 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x0A dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x0B dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x0C dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x0D dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x0E dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x0F dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x10 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x11 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x12 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x13 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x14 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x15 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x16 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x17 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x18 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x19 dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x1A dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x1B dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x1C dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x1D dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x1E dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x1F dt 0x00,0x00,0x00,0x00,0x00,0x00 ; 0x20 dt 0x00,0x00,0x5F,0x00,0x00,0x00 ; ! 0x21 dt 0x00,0x07,0x00,0x07,0x00,0x00 ; " 0x22 dt 0x14,0x7F,0x14,0x7F,0x14,0x00 ; # 0x23 dt 0x24,0x2A,0x7F,0x2A,0x12,0x00 ; $ 0x24 dt 0x26,0x16,0x08,0x34,0x32,0x00 ; % 0x25 dt 0x76,0x49,0x55,0x22,0x50,0x00 ; & 0x26 dt 0x00,0x00,0x05,0x03,0x00,0x00 ; ' 0x27 dt 0x00,0x1C,0x22,0x41,0x00,0x00 ; ( 0x28 dt 0x00,0x41,0x22,0x1C,0x00,0x00 ; ) 0x29 dt 0x14,0x08,0x3E,0x08,0x14,0x00 ; * 0x2A dt 0x08,0x08,0x3E,0x08,0x08,0x00 ; + 0x2B dt 0x00,0x50,0x30,0x00,0x00,0x00 ; , 0x2C dt 0x08,0x08,0x08,0x08,0x08,0x00 ; - 0x2D dt 0x00,0x60,0x60,0x00,0x00,0x00 ; . 0x2E dt 0x20,0x10,0x08,0x04,0x02,0x00 ; / 0x2F dt 0x3E,0x51,0x49,0x45,0x3E,0x00 ; 0 0x30 dt 0x00,0x42,0x7F,0x40,0x00,0x00 ; 1 0x31 dt 0x42,0x61,0x51,0x49,0x46,0x00 ; 2 0x32 dt 0x21,0x41,0x45,0x4B,0x31,0x00 ; 3 0x33 dt 0x18,0x14,0x12,0x7F,0x10,0x00 ; 4 0x34 dt 0x27,0x45,0x45,0x45,0x39,0x00 ; 5 0x35 dt 0x3C,0x4A,0x49,0x49,0x30,0x00 ; 6 0x36 dt 0x01,0x01,0x79,0x05,0x03,0x00 ; 7 0x37 dt 0x36,0x49,0x49,0x49,0x36,0x00 ; 8 0x38 dt 0x06,0x49,0x49,0x29,0x1E,0x00 ; 9 0x39 dt 0x00,0x36,0x36,0x00,0x00,0x00 ; : 0x3A dt 0x00,0x56,0x36,0x00,0x00,0x00 ; ; 0x3B dt 0x00,0x08,0x14,0x22,0x41,0x00 ; < 0x3C dt 0x14,0x14,0x14,0x14,0x14,0x00 ; = 0x3D dt 0x41,0x22,0x14,0x08,0x00,0x00 ; > 0x3E dt 0x02,0x01,0x51,0x09,0x06,0x00 ; ? 0x3F dt 0x3E,0x41,0x49,0x55,0x5E,0x00 ; @ 0x40 dt 0x7E,0x11,0x11,0x11,0x7E,0x00 ; A 0x41 dt 0x7F,0x49,0x49,0x49,0x36,0x00 ; B 0x42 dt 0x3E,0x41,0x41,0x41,0x22,0x00 ; C 0x43 dt 0x7F,0x41,0x41,0x22,0x1C,0x00 ; D 0x44 dt 0x7F,0x49,0x49,0x49,0x41,0x00 ; E 0x45 dt 0x7F,0x09,0x09,0x09,0x01,0x00 ; F 0x46 dt 0x3E,0x41,0x49,0x49,0x3A,0x00 ; G 0x47 dt 0x7F,0x08,0x08,0x08,0x7F,0x00 ; H 0x48 dt 0x00,0x41,0x7F,0x41,0x00,0x00 ; I 0x49 dt 0x20,0x41,0x41,0x3F,0x00,0x00 ; J 0x4A dt 0x7F,0x08,0x14,0x22,0x41,0x00 ; K 0x4B dt 0x7F,0x40,0x40,0x40,0x40,0x00 ; L 0x4C dt 0x7F,0x02,0x0C,0x02,0x7F,0x00 ; M 0x4D dt 0x7F,0x04,0x08,0x10,0x7F,0x00 ; N 0x4E dt 0x3E,0x41,0x41,0x41,0x3E,0x00 ; O 0x4F dt 0x7F,0x09,0x09,0x09,0x06,0x00 ; P 0x50 dt 0x3E,0x41,0x51,0x21,0x5E,0x00 ; Q 0x51 dt 0x7F,0x09,0x19,0x29,0x46,0x00 ; R 0x52 dt 0x46,0x49,0x49,0x49,0x31,0x00 ; S 0x53 dt 0x01,0x01,0x7F,0x01,0x01,0x00 ; T 0x54 dt 0x3F,0x40,0x40,0x40,0x3F,0x00 ; U 0x55 dt 0x1F,0x20,0x40,0x20,0x1F,0x00 ; V 0x56 dt 0x3F,0x40,0x3C,0x40,0x3F,0x00 ; W 0x57 dt 0x63,0x14,0x08,0x14,0x63,0x00 ; X 0x58 dt 0x07,0x08,0x70,0x08,0x07,0x00 ; Y 0x59 dt 0x61,0x51,0x49,0x45,0x43,0x00 ; Z 0x5A dt 0x00,0x7F,0x41,0x41,0x00,0x00 ; [ 0x5B dt 0x02,0x04,0x08,0x10,0x20,0x00 ; \ 0x5C dt 0x00,0x41,0x41,0x7F,0x00,0x00 ; ] 0x5D dt 0x04,0x02,0x01,0x02,0x04,0x00 ; ^ 0x5E dt 0x40,0x40,0x40,0x40,0x40,0x00 ; _ 0x5F dt 0x00,0x01,0x02,0x04,0x00,0x00 ; ` 0x60 dt 0x20,0x54,0x54,0x54,0x78,0x00 ; a 0x61 dt 0x7F,0x48,0x44,0x44,0x38,0x00 ; b 0x62 dt 0x38,0x44,0x44,0x44,0x20,0x00 ; c 0x63 dt 0x38,0x44,0x44,0x48,0x7F,0x00 ; d 0x64 dt 0x38,0x54,0x54,0x54,0x18,0x00 ; e 0x65 dt 0x08,0x7E,0x09,0x01,0x02,0x00 ; f 0x66 dt 0x08,0x54,0x54,0x54,0x3C,0x00 ; g 0x67 dt 0x7F,0x08,0x04,0x04,0x78,0x00 ; h 0x68 dt 0x00,0x44,0x7D,0x40,0x00,0x00 ; i 0x69 dt 0x20,0x40,0x44,0x3D,0x00,0x00 ; j 0x6A dt 0x7F,0x10,0x28,0x44,0x00,0x00 ; k 0x6B dt 0x00,0x41,0x7F,0x40,0x00,0x00 ; l 0x6C dt 0x7C,0x04,0x18,0x04,0x78,0x00 ; m 0x6D dt 0x7C,0x08,0x04,0x04,0x78,0x00 ; n 0x6E dt 0x38,0x44,0x44,0x44,0x38,0x00 ; o 0x6F dt 0x7C,0x14,0x14,0x14,0x08,0x00 ; p 0x70 dt 0x08,0x14,0x14,0x18,0x7C,0x00 ; q 0x71 dt 0x7C,0x08,0x04,0x04,0x08,0x00 ; r 0x72 dt 0x48,0x54,0x54,0x54,0x20,0x00 ; s 0x73 dt 0x04,0x3F,0x44,0x40,0x20,0x00 ; t 0x74 dt 0x3C,0x40,0x40,0x20,0x7C,0x00 ; u 0x75 dt 0x1C,0x20,0x40,0x20,0x1C,0x00 ; v 0x76 dt 0x3C,0x40,0x38,0x40,0x3C,0x00 ; w 0x77 dt 0x44,0x28,0x10,0x28,0x44,0x00 ; x 0x78 dt 0x0C,0x50,0x50,0x50,0x3C,0x00 ; y 0x79 dt 0x44,0x64,0x54,0x4C,0x44,0x00 ; z 0x7A dt 0x00,0x08,0x36,0x41,0x00,0x00 ; { 0x7B dt 0x00,0x00,0x7F,0x00,0x00,0x00 ; | 0x7C dt 0x00,0x41,0x36,0x08,0x00,0x00 ; } 0x7D dt 0x08,0x08,0x2A,0x1C,0x08,0x00 ; ->0x7E dt 0x08,0x1C,0x2A,0x08,0x08,0x00 ; <-0x7F ;****************************************************** ORG 0x1700 ;Flash_Messages Txt0 DT " PIC16F877 avec bootloader Q=10Mhz",.10,.13 DT " MPLAB version 8.10",.10,.13 DT " NOKIA_877_XPORT_090717.asm",.10,.13,0 Txt1 DT .10,.13 DT "elp",.10,.13 DT "<1>Consigne 1",.10,.13 DT "<2>Consigne 2",.10,.13 DT "<3>Consigne 3",.10,.13 DT "ecture PCF",.10,.13 DT "criture PCF",.10,.13 DT "pdate RTC",.10,.13,.0 fin_Flash_txt1 equ $ IF (fin_Flash_txt1 > 0x17FF ) ERROR "Attention debordement adresse 0x1800" ENDIF ;****************************************************** ORG 0x1B00 ;Flash_Messages Txt2 DT " LECTURE Msg en FLASH depuis 0x1800",.10,.13 DT " Page = ",.10,.13 DT " Page = ",.10,.13 DT " Page = ",.10,.13 DT " Page = ",.10,.13 DT " Page = ",.10,.13 DT " 2345678901234567890123456789012",.10,.13,0 fin_Flash_txt2 equ $ IF (fin_Flash_txt2 > 0x1BFF ) ERROR "Attention debordement adresse 0x1C00" ENDIF ;*************************************************** ORG 0x1C00 ;Flash_Messages Txt3 DT " Init RTC par defaut",.10,.13 DT " aux valeurs definies en dur ..",.10,.13 DT " dans le programme car RB1=0 ..",.10,.13 DT " ..............................",.10,.13 DT " .............................. ",.10,.13 DT " Version speciale XPORT........ ",.10,.13 DT " 2345678901234567890123456789012",.10,.13,0 fin_Flash_txt3 equ $ IF (fin_Flash_txt3 > 0x1CFF ) ERROR "Attention debordement adresse 0x1D00" ENDIF ;*************************************************** ORG 0x2100 ; 256 bytes of eeprom EEPROM EQU $ EE0 DT "16F877 w bootldr" DT "Q=10Mhz 19200bds",0 ;1234567890123456" EE1 DT "09/07 15H23M32S " EE12 DT "CH0 " EE121 DT "unit",0 EE13 DT "CH1 " EE131 DT "Points ",0 EE14 DT "CH2 " EE141 DT " Points",0 EE15 DT "CH5 " EE151 DT "Points ",0 EE2 DT "Ports 8b PCF8574",0 EE21 DT "Ecr ",0 EE22 DT "Lec ",0 EE3 DT "MAJ DS1307 " EE4 DT "AAMMJJWWHHMMSS " EE5 DT " ",0 ;1234567890123456" EE6 DT ".................",0 EE7 DT "PCF ",0 EE71 DT "Ecr=",0 EE72 DT "Lec=",0 EE_end Equ $ IF (EE_end > 0x21FF ) ERROR "Attention debordement zone EEPROM" ENDIF END