Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Ttl to Rs232 level shifter

Status
Not open for further replies.

Sheritronics

Newbie level 6
Joined
Feb 1, 2014
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
80
I have been working on serial communication from a month but didn't got any success in making the circuit of Rs232/TTL I already had make two circuits when i tested them they are giving me loop back that my circuit is working but after connecting it to my Pic16f877a the circuit start giving the garbage values on hyper terminal either on Proteus I am totally confused what to do I am using baud rate of 9600 any suggestions...
 

Attachments

  • Serial-shifter.png
    Serial-shifter.png
    24.5 KB · Views: 79

hello


Your hardware schematic seems OK
Did you try to reverse 2 & 3 pin PC side ?

Maybe the problem is PIC side ...
Show how you connect to the PIC pins..
and post you code to get help..
 

Pin 2 & 3 assignment is correct for PC male RS232 connector. I already checked this.

And there won't be garbage characters with RX/TX flipped.
 

Yeah I had tried loop back the circuit is working...... tnx to all. bt is their any issue of crystal oscillator with this circuit I am using 12MHz crystal
 

Hi,

Worth double checking the 232 chip your are using.

If its a Maxim 232 then it should be as you show with 1uf caps, but if its the Max 232 A then they are 0.1uf

As said just post your code so we can view /simulate your code and see if thats the problem.
 

Code:
 	org		0x00
 	#include	<p16f877a.inc>
	__CONFIG _HS_OSC &_WDT_OFF &_PWRTE_ON &_LVP_OFF
 
 	bsf	 	STATUS,5
 	movlw   0x24
 	movwf   TXSTA
 	movlw   D'77'
 	movwf   SPBRG
 	movlw   0x00
 	movwf   TRISC
 	bcf     STATUS,5
 	bsf     RCSTA,7
 
loop
    movlw 	A'S'
    call    test
    movlw   A'h'
    call    test
    movlw   A'e'
    call    test
    movlw   A'r'
    call    test
    movlw   A'i'
    call    test
    movlw   A't'
    call    test
    movlw   A'r'
    call    test
    movlw   A'o'
    call    test
    movlw   A'n'
    call    test
    movlw   A'i'
    call    test
    movlw   A'c'
    call    test
    movlw   A's'
    call    test
    movlw   A' '
    call    test
    movlw   A'P'
    call    test
    movlw   A'A'
    call    test
    movlw   A'F'
    call    test
    movlw   A'-'
    call    test
    movlw   A'K'
    call    test
    movlw   A'I'
    call    test
    movlw   A'E'
    call    test
    movlw   A'T'
    call    test
    call    DELAY_100MS
    goto    fin

test
	movwf   TXREG
again 	
	btfss   PIR1,4
    goto    again
    return

	#include    <delay.asm>
fin
     nop
	 end

DELAY EQU 0x20
DELAY_2 EQU 0x21
DELAY_1 EQU 0x22

DELAY_100MS:
	MOVLW D'255'
	MOVWF DELAY_2

DELAY_LOOP1_NEST:
	MOVLW D'255'
	MOVWF DELAY

DELAY_LOOP1:
	DECFSZ 	DELAY
	goto 	DELAY_LOOP1
 	DECFSZ 	DELAY_2
 	goto 	DELAY_LOOP1_NEST

 	return

DELAY_1S:

 	MOVLW 	D'250' ; Setting counter value of 150

 	MOVWF 	DELAY_1 ; Moving count value to DELAY

LOOP1: ; Producing the delay

 	MOVLW 	D'50' ;

 	MOVWF 	DELAY ;

LOOP2: ;

 	MOVLW 	D'45' ;

 	MOVWF 	DELAY_2 ;
LOOP3: 
 	DECFSZ 	DELAY_2;
 	GOTO 	LOOP3

 	DECFSZ 	DELAY;

 	GOTO 	LOOP2 ;


	DECFSZ 	DELAY_1 ; Decrement, skip next if DELAY=0

	GOTO 	LOOP1 ; Next instruction

 	RETURN
 

Is it a 12 MHz crystal?

I would start with a delay, otherwise the receiver might have problems if the sender resets into break state.

There seems to be no defined code to execute after one transmission sequence.
 

yeah I am using 12MHz crystal

- - - Updated - - -

Any modifications in the code you can made so plz suggest me I have to show this as a project task in my university as soon as possible
 

yeah I am using 12MHz crystal

- - - Updated - - -

Any modifications in the code you can made so plz suggest me I have to show this as a project task in my university as soon as possible


Hi,

Was going to give you the working code until I saw your updated message, uni project, - thats going cost lots :-D


Well it would, if it was not just for one simple omission you had made, you left out the TXSTA instruction.

As you can see it apart from that it works fine.

Code:
 	org		0x00
 	#include	<p16f877a.inc>
	__CONFIG _HS_OSC &_WDT_OFF &_PWRTE_ON &_LVP_OFF
 
 	bsf	 	STATUS,5
 	movlw   0x24
 	movwf   TXSTA
 	movlw   D'77'
 	movwf   SPBRG
 	movlw   0x00
 	movwf   TRISC
   	movlw   b'00100100'           
   	movwf   TXSTA               ;enable Async Transmission, set brgh

 	bcf     STATUS,5
 	bsf     RCSTA,7




 
loop
    movlw 	'S'
    call    test
    movlw   'h'
    call    test
    movlw   'e'
    call    test
    movlw   'r'
    call    test
    movlw   'i'
    call    test
    movlw   A't'
    call    test
    movlw   A'r'
    call    test
    movlw   A'o'
    call    test
    movlw   A'n'
    call    test
    movlw   A'i'
    call    test
    movlw   A'c'
    call    test
    movlw   A's'
    call    test
    movlw   A' '
    call    test
    movlw   A'P'
    call    test
    movlw   A'A'
    call    test
    movlw   A'F'
    call    test
    movlw   A'-'
    call    test
    movlw   A'K'
    call    test
    movlw   A'I'
    call    test
    movlw   A'E'
    call    test
    movlw   A'T'
    call    test
	movlw	0x0d
	call	test
	movlw	0x0a				
	call	test
    call    DELAY_100MS
    goto    fin

test
	movwf   TXREG
again 	
	btfss   PIR1,4
    goto    again
    return


fin
	call	DELAY_1S
	goto	loop
	 

DELAY EQU 0x20
DELAY_2 EQU 0x21
DELAY_1 EQU 0x22

DELAY_100MS:
	MOVLW D'255'
	MOVWF DELAY_2

DELAY_LOOP1_NEST:
	MOVLW D'255'
	MOVWF DELAY

DELAY_LOOP1:
	DECFSZ 	DELAY,F
	goto 	DELAY_LOOP1
 	DECFSZ 	DELAY_2,F
 	goto 	DELAY_LOOP1_NEST

 	return

DELAY_1S:

 	MOVLW 	D'250' ; Setting counter value of 150

 	MOVWF 	DELAY_1 ; Moving count value to DELAY

LOOP1: ; Producing the delay

 	MOVLW 	D'50' ;

 	MOVWF 	DELAY ;

LOOP2: ;

 	MOVLW 	D'45' ;

 	MOVWF 	DELAY_2 ;
LOOP3: 
 	DECFSZ 	DELAY_2,F;
 	GOTO 	LOOP3

 	DECFSZ 	DELAY,F;

 	GOTO 	LOOP2 ;


	DECFSZ 	DELAY_1,F ; Decrement, skip next if DELAY=0

	GOTO 	LOOP1 ; Next instruction

 	RETURN


	end
 

Attachments

  • 000084.jpg
    000084.jpg
    55 KB · Views: 69

Well it would, if it was not just for one simple omission you had made, you left out the TXSTA instruction.
Don't think that TXSTA must be set twice, but it doesn't hurt of course.
 

Don't think that TXSTA must be set twice, but it doesn't hurt of course.



ooops! :lol::lol:

Yes it does work ok without 2 TXSTA instructions !

So can only assume the default 9600 VT has been changed or the 877a Processors Clock Frequency has not been Edited to 12mhz ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top