That post was in error, but there was no way to change it. You can get up
to 19200 bps with a 4MHz osc with PBP's DEBUG.
Someone mentioned the error, but it wouldn't allow me to change it.
However, you definitely can get up to 115200 bps with a 4MHz osc, but you'll
need to use assembler. Try this;
Code:processor 16F876a #include <P16F876a.inc> errorlevel -302 ; suppress "not in bank 0" message ; Defines #define TxPin PORTC,6 ;define serial TX pin #define bank1 banksel 0x80 ;select bank 1 #define bank0 banksel 0x00 ;select bank 0 ; variable allocations cblock 0x20 ;start at RAM location 20h Counter ;bit counter TxByte ;holds byte to transmit MsgPtr ;message character pointer offset CharCnt ;number of characters in text message dlyLSD ;for delay loop endc org 0x00 ;reset vector goto Main org 0x05 ;required for MCS loader Main call Init ;init port MsgLoop movlw .17 ;17 characters in the message movwf CharCnt ;load character count movlw .0 ;pointer offset to 1st char in table movwf MsgPtr ;load character pointer NextChar movf MsgPtr,w ;load char pointer into W reg call Message ;fetch character from table call TxRoutine ;send it incf MsgPtr,f ;increment char pointer decfsz CharCnt,f ;decrement char count, skip if done goto NextChar ;not finished, then fetch next char call Delay_50uS ;short delay between messages goto MsgLoop ;continuous loop Message ;prints Hello World....!<CR> addwf PCL,f ;load character offset retlw 'H' ;return with ASCII character in W reg retlw 'e' retlw 'l' retlw 'l' retlw 'o' retlw ' ' retlw 'W' retlw 'o' retlw 'r' retlw 'l' retlw 'd' retlw '.' retlw '.' retlw '.' retlw '.' retlw '!' retlw '\r' ;carriage return tagged onto end of message TxRoutine movwf TxByte ;load byte to send into TxByte movlw .8 ;preload bit counter with 8 movwf Counter StartBit bcf TxPin ;true mode / low for START bit goto $+.1 ; 2uS goto $+.1 ; 2uS nop TxLoop rrf TxByte,f ;rotate into carry / send LSB first btfsc STATUS,C ;if bit = 1 then goto SetBit ;send a 1 bcf TxPin ;else send a 0 goto $+.1 ;2uS decfsz Counter,f ;decrement bit count goto TxLoop ;if not 0, then continue goto StopBit+.2 ;else send stop bit SetBit bsf TxPin ;send 1 nop decfsz Counter,f goto TxLoop StopBit nop goto $+.1 ;2uS goto $+.1 ;2uS bsf TxPin ;begin stop bit period goto $+.1 ;2uS goto $+.1 ;2uS return ;2uS rest of program handles the rest Init bank0 movlw b'01000000' ;TX pin idles high (true mode) movwf PORTC ;set port latches bank1 ;bank 1 movlw b'10000000' ;RX in, rest outs movwf TRISC ;set port directions bank0 ;back to bank 0 return Delay_50uS ;call + delay + return = 50uS movlw .15 ;at 4MHz movwf dlyLSD decfsz dlyLSD, f goto $ - .1 return end




Bookmarks