Debug @ 9600 on 4Mhz 16F676


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563

    Default Debug @ 9600 on 4Mhz 16F676

    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 may be required for more than 4800bps.
    Regards

    Sougata

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    From Bruce,

    Serial Baudrate 115200
    http://www.picbasic.co.uk/forum/show...64&postcount=2
    <br>
    DT

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Thanks Darrel for the info.

    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.
    Regards

    Sougata

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Thanks Bruce

    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 ?

    Since I am using hyperterm I am restricted to 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.
    Regards

    Sougata

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Thanks Again

    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.
    Regards

    Sougata

Similar Threads

  1. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  2. debug not working with MPASM assempler
    By santamaria in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th March 2009, 07:51
  3. STATUS re-curtain W
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th February 2005, 15:21
  4. help
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th February 2005, 20:42
  5. Need once your help one please
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th February 2005, 20:33

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts