;****************************************************** ;* Interface USB ver LPT * ;* Version 6 décembre 2009 * * ;****************************************************** ;* Clock = 4 MHz ;* Dialogue PC par RS232 à 9600 bauds ;* ; LIST p=16F883,r=dec __CONFIG _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTOSCIO __CONFIG _CONFIG2, _WRT_OFF & _BOR21V INCLUDE "P16F883.INC" ; Définition des pins #Define TX PORTC,6 #Define RX PORTC,7 #DEFINE Strobe PORTC,4 #DEFINE D0 PORTB,0 ;............. #DEFINE D7 PORTB,7 #DEFINE Led1 PORTC,0 #DEFINE Led2 PORTC,1 #DEFINE Led3 PORTC,2 #DEFINE Led4 PORTC,3 ;--------------------------------------------------------- ; DECLARATION VARIABLES CBLOCK 0x20 ; Mémoires RAM CarRecu : 1 ; Conserve le dernier reçu RS232 Compteur : 1 ENDC ;--------------------------------------------------------- ;+++++++++++++ RESET GENERAL ++++++++++++++++++++++++++ org 0 goto Start ; Traitement IRQ org 4 retfie ; Fin IRQ ;Debut programme principal Start BANKSEL TRISA ; bank 1 movlw 01101000B ; Horloge interne 4 MHz movwf OSCCON ; Set oscillateur interne movlw 00111111B ; set directions movwf TRISA movlw 0 ; set direction port B movwf TRISB movlw 10000000B ; set direction port C Tx en sortie movwf TRISC movlw 00100110B movlw 00000110B movwf ADCON1 movlw 00100100B movwf TXSTA movlw 25 ; valeur pour 9600 bauds à 4 MHz movwf SPBRG BANKSEL ANSEL ; Bank 3 clrf ANSEL ;digital I/O clrf ANSELH ;digital I/O BANKSEL RCSTA ; Bank 0 movlw 10010000B ; USART ON, 8 bits, -, Enable continu Rx movwf RCSTA clrf PORTC movfw RCREG ; lectures pour vider le récepteur movfw RCREG ; Pile FIFO de 2 + RCREG movfw RCREG clrf PORTB clrf PORTC BclMain AttA btfsc RCSTA,FERR ; Erreur frame ? goto ErrFerr btfsc RCSTA,OERR goto ErrOerr ; Erreur overflow ? goto ATTA1 ; Pas d'erreurs ErrFerr bcf RCSTA,CREN bsf RCSTA,CREN movfw RCREG movfw RCREG movfw RCREG bcf Led1 bsf Led3 goto RstCom ErrOerr bcf RCSTA,CREN bsf RCSTA,CREN movfw RCREG movfw RCREG movfw RCREG bcf Led2 bsf Led3 RstCom movlw 10010000B ; USART ON, 8 bits, -, Enable continu Rx movwf RCSTA goto BclMain ATTA1 btfss PIR1,RCIF ; Caractère reçu ? goto BclMain ; non, on reboucle bsf Led1 ; Caractère valide, on éteint les leds bsf Led2 movfw RCREG movwf CarRecu btfsc CarRecu, 7 ; Lexture seule ? goto SkipSetPort movlw 01101010B andwf CarRecu,W ; Data à 0, Set Dir seulement et moteur movwf PORTB nop nop movfw CarRecu movwf PORTB nop nop movlw 01101010B ; On ne touche pas au Dir andwf CarRecu,W movwf PORTB movlw 01000000B andwf CarRecu,W movwf PORTB SkipSetPort movfw PORTA call Send goto BclMain ;********************************* ;Envoi W sur TX a 9600 bauds , * ;********************************* Send BANKSEL TXSTA ; Bank 1 send1 btfss TXSTA,TRMT goto send1 BANKSEL TXREG ; Bank0 movwf TXREG return de "Version 6/12/2009 - 9600 bauds" ;=========================================================== end