Hello, *MAGIC* PIC_listers ! I'm trying for many days to make a Serial routine for a 16c84, it seems to work on MPLAB simulator, but in reality ... %-( I must say that i'v a LCD(HD44780) in my application, so i can see what i get ... First, i'v tryed to connect with a serie resistor straight to Tx(tested: 82k,200k,382k) and a common Ground; noisy results. Now, i'v wired it with a MAX232; noisy results too. I wanna do this in ISR (interrupt), like that I'm free of this in MAIN program. I thought about few methods to do this : - I could set TMR0 to 0xFF, triggered by RA4/T0CLK input to make a T0IF(timer overflow), etc... * Not good for my purpose, cause i need TMR0 for a base time. - I could set interrupt on PORTB change. * Not recommended.(I heared this, near here) - I could sample the Rx pin. * Good, but wasted time to sample each bit, as many it was super-sampled.(3,4 times ?) - And i could set RB0/INT for interrupt on transition, and calculate time between each of them. * This is my choice ... I want to implement a classic 8,N,1 @ 1200 (1bit start, 8bit data lsb/msb, no parity, 1bit stop, at 1200 baud.) May be i'm in wrong, for this case it's, start stop (hope ASCII drawing good.) 1______ _______________ _____ |_|_|_|_|_|_|_|_|_|_| 0 1 2 3 4 5 6 7 8 (1) set first for falling edge interrupt(INTEDG=0) (2) interrupt(INTF) - next INTF on rising edge(INTEDG=1) - at least(+/- 1.2% ?), 10*(1/1200)/second later must come a rising edge.(STOP bit) (3) interrupt(INTF) - next INTF on falling edge(INTEDG=0) - calculate time between (2) & (3), to count how many 1 bit - n*bit=time/(1/1200s), including at least START bit. - if n*bit=10, a byte received.(start+'11111111'+stop) (4) interrupt(INTF) - next INTF on rising edge(INTEDG=1) - calculate time between (3) & (4), to count how many 0 bit - n*bit=time/(1/1200s). - if n*bit>=10, error, STOP bit must be on rising edge ! (etc) until 10 bits counted, do/calculate, INTF rising/falling time. To calculate time(wrong ?): My ISR routineÓ is shared with TMR0 overflow, so each time TMR0 roll over, it reloaded with a pre-calculated value: (CLK/4)/prescaler/(256-value)= interrupt/s The wanted result(?) is 4 times the baud rate, ~4800 Hz 4194304/4 /1 /218= 4809 int/s, then Reload value = (256-218) = 38 ;*********************************************************************************** __CONFIG _XT_OSC & _CP_OFF & _WDT_OFF & _PWRTE_ON org 0h goto MAIN org 4h _Interrupt: push ; MACRO save W & STATUS btfsc INTCON, INTF ; test if transition on RB0/INT goto _RxINT ; an INTF occur, go to serial ; else it's a TMR0 overflow bcf INTCON, T0IF ; clear TMR0 overflow bit ; some code here movlw Reload ; The pre-calculated value = 38, cf upper text addwf TMR0, f ; to reload TMR0 + elapsed time >from T0IF incf RxTIMER ; this is for serial, +1 every 1/4800s ; cleared, on each transition in _RxINT ; to be divided by 4, to count bit @ 1200 bps pop ; MACRO restore W & STATUS retfie ; Exit ISR _RxINT: bcf INTCON, INTF ; clear INTF transition bit ; some code here pop ; MACRO restore W & STATUS retfie ; Exit ISR ;*********************************************************************************** - Do you estimate this method accurate ? - Is my vision of serial transmit good ? - What about TMR0 reload and interrupt latency ? - Do you think i could have noise from LCD, pin not tied(set to output), or serial(PC) ? - Or what ? (may be i'm a dude ?, hope not !) Please, switch my light ! *-*-*-*-*-*-*-*-*-*-*-*-*-*-* *Happy X_MAS lovely people !* *-*-*-*-*-*-*-*-*-*-*-*-*-*-* * life is a joke, but PICs are serious ...