#ifndef CR #define CR 13 #define LF 10 #endif // la Pin de sortie est definie dans le main program sbit TX3_Pin at LATA.B2; sbit TX3_Pin_Direction at TRISA.B2; unsigned char c3 absolute 0x0020; unsigned char RS_Count; unsigned char RS_tmp; unsigned char RS_Delay ; void UART3_Write(unsigned char c1); // ecrit 1 char void UART3_Write_Text(unsigned char *T); // ecrit un texte situé en RAM void UART3_Write_CText(const char *txt3); // ecrit un texte en dur (situé en ROM) void CRLF3(void) ; // envoit saut de Ligne 13 , 10 ( CR LF) void UART3_Write_CText(const char *txt3) { while (*txt3) { UART3_Write(*txt3++); // Delay_us(500); } } void UART3_Write_Text(unsigned char *T) // at adress 0x002 taille 42 bytes { while(*(T)>0) // verif sur VBRAY en mode ASCII { UART3_Write(*(T++)); // c3 variable globale } } void CRLF3() { UART3_Write(CR); UART3_Write(LF); } void UART3_Write(unsigned char cc) // 16MHz 19200 bauds { c3=~cc; // complement du caractere ! // avec TX3_PIN => RA2 _asm{ RSsend2: movlw 8 ; 8 bits movwf _RS_Count ; compteur de bits envoyés bcf LATA,2 ; bit de start call RSdelai2 ; tempo // rrf _c1,f ; on recupere dans C le bit à envoyer // syntaxe à revoir en fonction du PIC utilisé rrcf avec 18F87J50 L00: rrf _c3,1 ; on recupere dans C le bit à envoyer btfsc STATUS,C ; bit à envoyer = 1 ? goto L10 ; oui bsf LATA,2 ; sinon 0 goto L20 ; on continue sur la tempo L10: bcf LATA,2 ; bit à 1 L20: call RSdelai2 ; tempo decfsz _RS_Count,1 ; on decremente le compteur de bits envoyés goto L00 ; on continue sur les bits suivants bsf LATA,2 ; bit de stop call RSdelai2 ; tempo pour bit de stop call RSdelai2 ; tempo pour bit de stop goto LA1 RSdelai2: // 52µS / bit at 19200 bauds MOVLW 28 ; MOVWF _RS_tmp ; RS00: NOP; ; fait parti de la tempo! NOP; NOP; NOP; // NOP; DECFSZ _RS_tmp,F ; GOTO RS00 ; NOP; NOP; NOP; RETURN ; LA1: nop; } }