LIST p=16F628 #include ; _CP_ON _CP_OFF Code protection ; _PWRTE_ON _PWRTE_OFF Timer reset sur power on ; _WDT_ON _WDT_OFF Watch-dog ; _LP_OSC _XT_OSC _HS_OSC _RC_OSC Oscillateur __CONFIG _BODEN_OFF & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_OFF & _INTRC_OSC_NOCLKOUT ;Envoi et recoit a 115200 baud avec pic à 4MHz ; premier caractere recu taille puis renvoie #DEFINE VERSION "0" #include ;movlf movff movE movwe save_env load_env incEeadr CBLOCK 0x22 ; 94 byte local1:1 local2:1 local3:1 local4:1 CharRecu:1 bool:1 ENDC #DEFINE BOUTON PORTB,3 #DEFINE LED_STATUS PORTA,1 #DEFINE TX_RS232 PORTA,2 #DEFINE RX_RS232 PORTA,3 ;LOCAL FONCTION #DEFINE Tempo local1 #DEFINE Tempo2 local2 #DEFINE NbrBit local3 #DEFINE Caractere_RS local4 #DEFINE First bool,0 ;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯; ; DEBUT DU PROGRAMME ; ;_______________________________; org H'0' ;Vecteur de reset goto On_Reset org H'4' ;Vecteur d'interruptions On_Interrupt save_env load_env retfie Fin_Interrupt org Fin_Interrupt+H'55' On_Reset BANKSEL TRISA movlf B'00001000',TRISA movlf B'11111001',TRISB movlf B'00100000',INTCON movlf B'10000100',OPTION_REG ;1:128b 110 BANKSEL EEADR clrf EEADR ; BANKSEL PCON ; bsf PCON,OSCF ;4mhz BANKSEL PORTA movlf H'07',CMCON ; Comparateurs eteints clrf PORTB; clrf PORTA; ;-------------------------------- ; PROGRAMME PRINCIPAL ;-------------------------------- prog call RecoiChar bsf LED_STATUS movwf CharRecu movf CharRecu,W call EnvoiChar bcf LED_STATUS goto prog ;-------------------------------- ; ROUTINES ;-------------------------------- Attend25us ;Attend25us () { incfsz Tempo,F goto Attend25us return ; } Attente ;Attente () { incfsz Tempo,F goto Attente incf Tempo2,F clrwdt btfss Tempo2,7 goto Attente clrf Tempo2 return ; } ;-------------------------------------- ;RecoiChar () 115200 ;AttendDebut ;btfsc RX_RS232 ;goto AttendDebut ;goto RecoiChar RecoiChar ; Attente de reception btfss RX_RS232 goto RecoiChar clrwdt ;nop ;tolérance : 3 à 7 nop nop nop nop nop RecoiCharIm ;reception immédiate ( à utiliser si on désire recevoir en interruption) movlw D'8' movwf NbrBit clrf Caractere_RS _BitSuiva rrf Caractere_RS, F bcf Caractere_RS, 7 btfss RX_RS232 bsf Caractere_RS, 7 clrwdt ;nop nop decfsz NbrBit, F goto _BitSuiva movf Caractere_RS, W return ;----------------------------------------- 115200 bauds à 4Mhz org Fin_Interrupt EnvoiChar movwf Caractere_RS _Start_Bit bsf TX_RS232 clrwdt ;nop _Bit0 nop nop nop movlw low _Bit1 btfss Caractere_RS,0 goto _Envoi_0 nop bcf TX_RS232 nop _Bit1 nop nop movlw low _Bit2 btfss Caractere_RS,1 goto _Envoi_0 nop bcf TX_RS232 nop _Bit2 nop nop nop movlw low _Bit3 btfss Caractere_RS,2 goto _Envoi_0 nop bcf TX_RS232 nop _Bit3 nop nop nop movlw low _Bit4 btfss Caractere_RS,3 goto _Envoi_0 nop bcf TX_RS232 nop _Bit4 clrwdt ;nop nop movlw low _Bit5 btfss Caractere_RS,4 goto _Envoi_0 nop bcf TX_RS232 nop _Bit5 nop nop nop movlw low _Bit6 btfss Caractere_RS,5 goto _Envoi_0 nop bcf TX_RS232 nop _Bit6 nop nop nop movlw low _Bit7 btfss Caractere_RS,6 goto _Envoi_0 nop bcf TX_RS232 nop _Bit7 clrwdt ;nop nop movlw low _Stop_Bit btfss Caractere_RS,7 goto _Envoi_0 nop bcf TX_RS232 _Stop_Bit movlw D'2' ; 7 instruction movwf Tempo _Teeempo decfsz Tempo, F goto _Teeempo bcf TX_RS232 nop movlw D'2' ; 8 instruction movwf Tempo _Teeeepo2 decfsz Tempo, F goto _Teeeepo2 return _Envoi_0 bsf TX_RS232 movwf PCL END ; fin du programme