Hi Friend I'm working in an serial adquisition system for a PC with an 16C71 but the PIC software is not working this is the code: ;********************************************************* ; ; A/D ADQUISITION SERIAL FOR PC ; ; THIS PROGRAM USE THE PIC 16C71 LIKE A/D COVERTER AND CPU ; TO ADQUIRE 4 ANALOG SIGNALS WHEN THE COMPUTER SENT THE ; FOLLOWING COMMANDS: ; "p" = 70H = ADQUIRE ALL 4 INPUTS IN SECUENCE ; "a" = 61H = ADQUIRE ONLY IN0 (RA0) ; "b" = 62H = ADQUIRE ONLY IN1 (RA1) ; "d" = 64H = ADQUIRE ONLY IN2 (RA2) ; "h" = 68H = ADQUIRE ONLY IN3 (RA3) ; ; THE SYSTEM CLOCK IS 10 MHZ, AMD THE SERIAL SPEED IS 9600 BPS ; ; THE VREF IS VCC = 5 VOLTS AND EVERY A/D STEP IS 5/256 VOLTS ; A/D STEP = 19.5 mVOLTS ; ; THE CONVERTION RESULT IS A BYTE AND ITS VALUE IS: ; RESULT = BYTE x 5 VOLTS / 256 ; ; THE ANALOG CHANNELS ARE: ; RA0 = CHANNEL 0 ; RA1 = CHANNEL 1 ; RA2 = CHANNEL 2 ; RA3 = CHANNEL 3 ; ; ; THE SERIAL PIN TX IS RB3 ; THE SERIAL RX PIN IS RB0 ; ; WE CONECT A LED IN RB4 TO CONVERTION FLAG ; THERE ARE A SECOND LED LIKE SERIAL TRANSMITER FLAG IN RB5 ;**************************************************************** #INCLUDE ; #DEFINE TX PORTB,3 ; #DEFINE RX PORTB,0 ; #DEFINE LED PORTB,4 ; CONVERT FLAG #DEFINE LEDB PORTB,5 ; SERIAL TX FLAG TEMP EQU 0CH ; MAIN ORG 0 ; GOTO 5 ; ORG 5 ; START BSF STATUS,RP0 ; SET BANK 1 CLRF OPTION_REG ; SET CONFIG. CLRF INTCON ; NO INTERRUPS MOVLW B'00000000' ; MOVWF TRISA ; ALL PORTA IS INPUT MOVLW B'10110000' ; MOVWF TRISB ; RB7/RB4/RB5 = OUT, ALL OTHERS INP MOVLW B'00000000' ; MOVWF ADCON1 ; SELECT PORT A LIKE ANALOG INPUTS BCF STATUS,RP0 ; SET BANK 0 MLOOP CALL SERECV ; RECEIVE WORD MOVF RXREG,W ; SUBLW 61H ; "a" - RX WORD BTFSC STATUS,Z ; TEST FOR "a" GOTO AD0C ; GOTO CHANNEL 0 A/D MOVF RXREG,W ; SUBLW 62H ; "b" BTFSC STATUS,Z ; TEST FOR "b" GOTO AD1C ; GOTO CHANNEL 1 A/D MOVF RXREG,W ; SUBLW 64H ; "d" BTFSC STATUS,Z ; TEST FOR "h" GOTO AD2C ; GOTO CHANNEL 2 A/D MOVF RXREG,W ; SUBLW 68H ; "h" BTFSC STATUS,Z ; TEST FOR "h" GOTO AD3C ; GOTO CHANNEL 2 A/D MOVF RXREG,W ; SUBLW 70H ; "p" BTFSC STATUS,Z ; TEST FOR "p" GOTO ADALLC ; GOTO ALL CHANNELS GOTO MLOOP ; ERROR START AGAIN AD0C BCF LED ; TURN 0N LED CALL AD0 ; CHANNEL 0 CONVERT BSF LED ; TURN OFF LED GOTO MLOOP ; AD1C BCF LED ; TURN 0N LED CALL AD1 ; CHANNEL 1 CONVERT BSF LED ; TURN OFF LED GOTO MLOOP ; AD2C BCF LED ; TURN 0N LED CALL AD2 ; CHANNEL 2 CONVERT BSF LED ; TURN 0FF LED GOTO MLOOP ; AD3C BCF LED ; TURN 0N LED CALL AD3 ; CHANNEL 3 CONVERT BSF LED ; TURN 0FF LED GOTO MLOOP ; ADALLC CALL AD0 ; CALL AD1 ; CALL AD2 ; CALL AD3 ; GOTO MLOOP ; ;********************************************************** ; CHANNEL 0 A/D ;********************************************************** AD0 MOVLW B'01000001' ; MOVWF ADCON0 ; SELECT CH0, AD ON CALL SAMPDEL ; SAMPLING DELAY OF 15 uSEG BSF ADCON0,GO_DONE ; STAR A/D CONVERTION AD0L BTFSC ADCON0,GO_DONE ; A/D OVER ? GOTO AD0L ; NO WAIT MOVF ADRES,W ; MOVWF TXREG ; COPY A/D RESULT TO TXREG CALL SERSENT ; SENT A/D CHANNEL 0 RETURN ; ;********************************************************** ; CHANNEL 1 A/D ;********************************************************** AD1 MOVLW B'01001001' ; MOVWF ADCON0 ; SELECT CH1, AD ON CALL SAMPDEL ; SAMPLING DELAY OF 15 uSEG BSF ADCON0,GO_DONE ; STAR A/D CONVERTION AD1L BTFSC ADCON0,GO_DONE ; A/D OVER ? GOTO AD1L ; NO WAIT MOVF ADRES,W ; MOVWF TXREG ; COPY A/D RESULT TO TXREG CALL SERSENT ; SENT A/D CHANNEL 1 RETURN ; ;********************************************************** ; CHANNEL 2 A/D ;********************************************************** AD2 MOVLW B'01010001' ; MOVWF ADCON0 ; SELECT CH2, AD ON CALL SAMPDEL ; SAMPLING DELAY OF 15 uSEG BSF ADCON0,GO_DONE ; STAR A/D CONVERTION AD2L BTFSC ADCON0,GO_DONE ; A/D OVER ? GOTO AD2L ; NO WAIT MOVF ADRES,W ; MOVWF TXREG ; COPY A/D RESULT TO TXREG CALL SERSENT ; SENT A/D CHANNEL 2 RETURN ; ;********************************************************** ; CHANNEL 3 A/D ;********************************************************** AD3 BSF STATUS,RP0 ; SELECT BANK 1 MOVLW B'01011001' ; MOVWF ADCON0 ; SELECT CH3, AD ON CALL SAMPDEL ; SAMPLING DELAY OF 15 uSEG BSF ADCON0,GO_DONE ; STAR A/D CONVERTION AD3L BTFSC ADCON0,GO_DONE ; A/D OVER ? GOTO AD3L ; NO WAIT MOVF ADRES,W ; MOVWF TXREG ; COPY A/D RESULT TO TXREG CALL SERSENT ; SENT A/D CHANNEL 3 RETURN ; ;************************************************************ ; SAMPLING DELAY OF 15 uSEG ;************************************************************ SAMPDEL MOVLW 0CH ; LOAD 12 TO TEMP REG MOVWF TEMP ; SAMP DECFSZ TEMP ; GOTO SAMP ; RETURN ; ;************************************************************** ; ; Serial Subrutine ; ------------------ ; Use the Following Registers: ; ; 1- TXREG = Word to Sent = 2A H ; 2- RXREG = Recived Word = 2B H ; 3- XCOUNT = Count register = 2C H ; 4- SERDEL1 = Delay reg #1 = 2D H ; 5- SERDEL2 = Delay reg #2 = 2E H ; ; the Osc frec is 10 Mhz and 9600 Bps sent/rec ; ; the subrutines are called: SERSENT and SERRECV ; you need to put the word that you want to sent in TXREG ; and call SERSENT subrutine the same for RXREG and SERRECV ; ; you need to define the serial port --> #DEFINE TX PORTB,3 ; #DEFINE RX PORTB,0 ; ; ; - The rutines uses 2 stack levels ; ; - To calc the delay = 2 + SERDEL2*(2 + 3*SERDEL1) ; ; - To incluye this file: INCLUDE AND TAKE 43 MEMORY SPACES ;************************************************************************ TXREG EQU 2AH RXREG EQU 2BH XCOUNT EQU 2CH SERDEL1 EQU 2DH SERDEL2 EQU 2EH ;************************************************************************ SERSENT BCF LEDB ; TURN ON TX FLAG MOVLW 8 ; MOVWF XCOUNT ; LOAD XCOUNT WITH 8 BCF TX ; SENT START BIT X_NEXT CALL DELX1 ; CALL RELAY FOR 4800 BPS RRF TXREG ; BTFSC STATUS,C ; BSF TX ; BIT IS ONE BTFSS STATUS,C ; BCF TX ; BIT IS ZERO DECFSZ XCOUNT ; IF COUNT = 0, THEN TRANSMIT A STOP BIT GOTO X_NEXT ; TRANSMIT NEXT BIT X_STOP CALL DELX1 ; BSF TX ; CALL DELX1 ; SECOND STOP BYTE BSF LEDB ; TURN OFF TX FLAG RETURN ; RETURN TO MAIN LOOP ;*************************************************************************** ******** SERECV BTFSC RX ; TEST FOR START BIT GOTO B2CHECK ; START BIT NOT FOUND GOTO STFD ; B2CHECK MOVLW 01H ; MOVWF SERDEL2 ; CALL DELX2 ; START BIT DETECT, WAIT B/2 = 1/19200 BPS GOTO SERECV ; CHECK FOR START BIT AGAIN STFD MOVLW 8 ; MOVWF XCOUNT ; 8 DATA BITS CLRF RXREG ; R_NEXT CALL DELX1 ; DELAY FOR B = 1/9600 BPS BCF STATUS,C ; CLEAR CARRY BIT RRF RXREG ; BTFSC RX ; IS THE BIT ZERO OR ONE BSF RXREG,7 ; BIT IS ONE DECFSZ XCOUNT ; GOTO R_NEXT ; RETURN ; ;*************************************************************************** ********* DELX1 MOVLW 02H ; MOVWF SERDEL2 ; DELX2 MOVLW 2AH ; MOVWF SERDEL1 ; DELX DECFSZ SERDEL1 ; GOTO DELX ; DECFSZ SERDEL2 ; GOTO DELX2 ; RETURN ; ;*************************************************************************** ********* END