Clewer,Brian wrote: > > Hi all, > Can anyone help me with my communications to my pc to and from my > 16c84? What I need is the timings in micro seconds of the data transfer > between the bits sent (9600, N 8 1). It will be a 3 wire link (Tx, Rx & > Gnd). I will need to poll for the data in the middle of each bit. > > Thanks for your help in advance, > Brian. I send in attach the code I devellop, it is not very well programmed because it was "develloped" same years ago! If you want interrupt driven rotines you will have to use portb (wake-up) and blow up (use) a timer to generate the delays! ; ------------------------------------------- ; pic defs - file:pic16c64.h ; ------------------------------- #define ResetVector 0000h #define IntVector 0004h #define TRUE 1 #define FALSE 0 CBLOCK 0x00 ; Banco 0 indf tmr0 pcl status fsr porta portb portc portd porte pclath intcon pir1 ENDC CBLOCK 0x0E tmr1l tmr1h t1con tmr2 t2con sspbuf sspcon ccpr1l ccpr1h ccp1con ENDC ; CBLOCK 0x81 ; option ; ENDC CBLOCK 0x85 ; Banco 1 trisa trisb trisc trisd trise ENDC CBLOCK 0x8C pie1 ENDC CBLOCK 0x8E ; Banco 1 pcon ENDC CBLOCK 0x92 ; Banco 1 pr2 sspadd sspstat ENDC #define c status,0 #define carry status,0 #define dc status,1 #define z status,2 #define zero status,2 #define rp0 status,5 #define rbif intcon,0 #define intf intcon,1 #define rtif intcon,2 #define rbie intcon,3 #define inte intcon,4 #define rtie intcon,5 #define peie intcon,6 #define gie intcon,7 #define tmr1if pir1,0 #define tmr2if pir1,1 #define ccp1if pir1,2 #define sspif pir1,3 #define pspif pir1,7 #define rtcc tmr0 #define tmr1on t1con,0 #define tmr1ie pie1,0 #define tmr2ie pie1,1 #define ccpie pie1,2 #define sspie pie1,3 #define pspie pie1,7 ;----------------------------------------------- ; File:Com232.h ; Definigues necessarias ao COM232.ASM ;----------------------------------------------- EBaudBit equ 168 ;1/9600 bps=104.166us =>(10+3*x)*200ns=104.166us EBaudSB equ 171 ;(8+3*x)*200ns=104.166us; RBaud equ 169 RBaud05 equ 64 CBLOCK 0x20 Cont Dados DelayCnt Aux ENDC #define Tx porta,0 #define Rx porta,1 #define RxSel porta,2 ; Selecgco de recepgco #define TxSel porta,3 ; Selecgco de transmissco #define CD porta,4 ; carrier detect #define TxPC porta,5 ; Tx e Rx para comunicagco com PC #define RxPC portc,7 ; ; --------------- ; communication rotines ; File: com232.asm ;---------------- ; Necessita de 3 registos : Cont,Dados e DelayCnt ; Invocar ConfigRS232 antes de chamar Enviar ou Receber ConfigRS232 bsf rp0 bcf TxPC bsf RxPC bcf rp0 clrf intcon bsf TxPC ; determina a chegada de mais mensagens bcf tmr1ie ; impede ints do timer 1 bcf tmr1if clrf tmr1h clrf tmr1l clrf t1con return EnviarPC bcf rp0 bcf c movlw 8 movwf Cont bcf TxPC ; Envia Start Bit call EDelaySB ; Espera tempo necessario ao Start Bit EnvSegPC rrf Dados,1 ; Envia 1: LSB btfsc carry ; Verifica se o bit i 1 ou 0 bsf TxPC btfss carry bcf TxPC call EDelayBit ; Espera pelo tempo de 1 bit decfsz Cont,1 ; N: de bits de dados goto EnvSegPC EnvStopPC nop ; acertar tempo 8' bit nop bsf TxPC ; Envia Stop Bit call EDelayBit ; Espera o tempo necess rio return EDelayBit movlw EBaudBit goto EsaveBaud EDelaySB movlw EBaudSB EsaveBaud movwf DelayCnt Erep decfsz DelayCnt,1 goto Erep return ReceberPC bcf rp0 bcf c clrf Dados movlw 8 movwf Cont Receber2PC btfss RxPC ; polling a espera de caracter btfsc RxPC ; start bit i zero goto Receber2PC RecStartPC bcf gie ; impede interrupgues call RDelay05 ; esperar tempo de 1/2 Bit btfsc RxPC ; verificar se e mesmo Start Bit ou goto Receber2PC ; se e ruido RecSegPC call RDelay ; esperar tempo de 1 Bit btfsc RxPC ; verificar se o bit recebido i 1 ou 0 bsf carry ; o bit recebido i 1 btfss RxPC ; verificar se o bit recebido i 1 ou 0 bcf carry ; o bit recebido i 0 rrf Dados,1 ; colocar o bit recebido no byte de dados decfsz Cont,1 goto RecSegPC RecStopPC call RDelay ; esperar tempo de 1 Bit pelo Stop Bit btfss RxPC ; verificar se e o Stop Bit goto ReceberPC ; nao e o Stop Bit. Ha erro! movf Dados,0 ; caracter recebido esta em W e em Dados bsf gie return RDelay05 movlw RBaud05 movwf DelayCnt goto Wait RDelay movlw RBaud movwf DelayCnt Wait decfsz DelayCnt,1 goto Wait return ; -------------------- ; Main loop ; -------------------- LIST p=16C64,r=DEC TITLE "RS-232 ECHO" EXPAND include "pic16c64.h" include "com232.h" ;******* Definigco dos parbmetros RS-232 ******** org ResetVector goto Main org IntVector retfie Main: IFDEF __16C74A ; for 16C74A - porta as I/O digital lines bsf rp0 movlw 7 movwf 09fh bcf rp0 ENDIF call ConfigRS232 ; Sends string "JMC" to PC movlw 'J' movwf Dados call EnviarPC movlw 'M' movwf Dados call EnviarPC movlw 'C' movwf Dados call EnviarPC movlw ' ' Loop: call ReceberPC ; receive from PC call EnviarPC ; echo to PC goto Loop include "com232.asm" end