PDA

View Full Version : Debug @ 9600 on 4Mhz 16F676



sougata
- 11th March 2007, 12:25
Hi,

I am working with a project on a 16f676. It is running on its internal 4MHz RC oscillator. It is using extensive interrutps. (Tmr0, Tmr1, INTF, Comparator). All of the interrupt routines are in ASM. Almost all pins are used. For debugging prupose I need to view a few registers. Only option is to use debug on one of the LED indicator.

Now my question is what is the Maximum Baud Rate usable ? PBP manual says that for SEROUT2 oscillators greater than 4MHz :confused: may be required for more than 4800bps.

Darrel Taylor
- 11th March 2007, 15:26
From Bruce,

Serial Baudrate 115200
http://www.picbasic.co.uk/forum/showpost.php?p=10664&postcount=2
<br>

sougata
- 11th March 2007, 16:47
Hi,

Thank you very much Darrel. I have already successfully used it at 9600. This gives me enough courage and confidence to use it at 115200.

Bruce
- 11th March 2007, 16:56
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;


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

sougata
- 12th March 2007, 01:26
Hi,

Thank you Bruce for your ASM routine. This would make my life a lot more easier. Since I have interrupts running around I was worried that if my serial transmission gets interrupted too often then I would have large timing error. Now with your ASM routine I can stuff it in inside my INT Handler since I am already having a timebase running.

One more question :o ?

Since I am using hyperterm I am restricted to :confused: ASCII transmission. For example say I need to watch a variable. Using DEBUG with the # modifier sends an "ASCII" representation. This increases the tx overhead. Is there anyway I can view the Binary value of the Tx Data. All I need is an automatically linefeed display of the incoming byte on my PC.

Bruce
- 12th March 2007, 13:06
Hi Sougata,

I'm not sure how to do that with HyperTerm. Displaying a single byte value in
binary sends an ASCII 1 or 0 byte-per-bit. You would probably need to write
your own serial terminal program for something like that.

sougata
- 12th March 2007, 14:51
Hi,

I am not that experienced on the PC side programming but then again your site provides excellent startup pointers. http://www.rentron.com/VisualBasic.htm

So thanks again for the insight.