The circuit
is based around the PIC16F84 which is loaded with my version of rs232.hex. The PIC simply outputs the binary
asynchronous value comming from the PC’s serial port. The program on the PC simply sends a series of values
(corresponding to F,B, L or R on the RC transmitter) or a combination of
such. The circuit is connected to the
rs232 port on the PC and to the RC box.
The RC box is hacked on its switches so the computer shots commands to
it.
Circuit Schematics.
This is the
rs232.asm listing to compile and load into the PIC16F84
;Programa para interface RS232 <-> Paralelo 8 bits
;
processor 16f84
include <p16f84.inc>
__config _XT_OSC & _WDT_OFF &
_PWRTE_ON
;Variables usadas
XMIT_BYTE equ H'0C' ;Contiene
el byte a transmitir
RCV_BYTE equ H'0D' ;Contiene
el byte recivido
BIT_CNTR equ H'0E' ;Cuenta
los bits para RS232
DELAY_CNTR equ H'0F' ;Cuenta
el delay
;Constantes
RX equ H'00' ;Bit
0 del PORTA (entrada serial)
TX equ H'01' ;Bit
1 del PORTA (salida serial)
;Inicializacion
org 0 ;Inicia
en direccion 0
bsf STATUS,RP0 ;Selecciona
regs. Banco 1
movlw B'11111101' ;Configura
puerto A
movwf TRISA
movlw B'00000000' ;Configura
puerto B
movwf TRISB
bcf STATUS,RP0 ;Selecciona
regs. Banco 0
movlw B'00000000' ;Salidas
apagadas
movwf PORTB
bsf PORTA,TX ;Pon
TX en HIGH, estado de espera
MAIN:
movlw H'0F' ;pon
el valor 15 en W
call XMIT_RS232 ;Mandalo
serialmente
call RCV_RS232 ;Recive
el valor seriado
movwf PORTB ;ponlo
en las salidas (PUERTO B)
goto MAIN ;recicla
;************************* SUBRUTINAS
***********************************
XMIT_RS232:
movwf XMIT_BYTE ;Mueve
el contenido de W a XMIT_BYTE
movlw H'08'
movwf BIT_CNTR ;Pon
8 en el contador de BIT_CNTR
bcf PORTA,TX ;Pon
TX en LOW, Start Bit
call BIT_DELAY ;Haz un retrazo
SER_LOOP:
rrf XMIT_BYTE,F ;Rota
XMIT_BYTE y guardalo en el mismo
btfss STATUS,C ;Si
el bit es 0?
bcf PORTA,TX ;pon
TX en LOW
btfsc STATUS,C ;Si
el bit es 1?
bsf PORTA,TX ;pon
TX en HIGH
call BIT_DELAY ;Haz
un retrazo
decfsz BIT_CNTR,F ;Se
han enviado ya 8 bits?
goto SER_LOOP ;No,
recicla
bsf PORTA,TX ;Si,
pon TX en HIGH, en espera
call BIT_DELAY ;Haz
un retrazo
return
RCV_RS232:
btfsc PORTA,RX ;Espera
por el Start Bit
goto RCV_RS232 ;Mientras,
recicla
call START_DELAY ;Haz
un medio retrazo
btfsc PORTA,RX ;Verifica
que aun se esta en Start Bit
goto RCV_RS232 ;Si,
recicla
movlw H'08' ;Pon
8 en el BIT_CNTR
movwf BIT_CNTR
clrf RCV_BYTE ;Limpia el registro de recepcion RCV_BYTE
NEXT_RCVBIT:
call BIT_DELAY ;Haz un retrazo
btfss PORTA,RX ;Es RX HIGH?
bcf STATUS,C ;No, pon el bit en 0 (Carry)
btfsc PORTA,RX ;Es RX LOW?
bsf STATUS,C ;No, pon el bit en 1 (Carry)
rrf RCV_BYTE,F ;Rota RCV_BYTE y acumula el bit ahi mismo
decfsz BIT_CNTR,F ;Se
han leido ya los 8 bits?
goto NEXT_RCVBIT ;No,
recicla
call BIT_DELAY ;Haz
un retrazo
movf RCV_BYTE,W ;Guarda
RCV_BYTE en W
return
START_DELAY:
movlw H'0C'
movwf DELAY_CNTR
START_WAIT:
nop
decfsz DELAY_CNTR,F
goto START_WAIT
return
BIT_DELAY:
movlw H'18'
movwf DELAY_CNTR
BIT_WAIT:
nop
decfsz DELAY_CNTR,F
goto BIT_WAIT
return
end
These are a
few pictures of the setup:
|
|
|
|