Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Baud Rate assembly coding

Status
Not open for further replies.

Spadez

New Member
Hi.

I have my code working using this code off microchip:

Code:
        movlw .25              ; 
[COLOR="red"]	banksel SPBRG[/COLOR]
        movwf SPBRG
        movlw b'00100100'       ; brgh = high (2)
[COLOR="red"]	banksel TXSTA
[/COLOR]        movwf TXSTA             ; enable Async Transmission, set brgh

        bcf STATUS,RP0          ; RAM PAGE 0

        movlw b'10010000'       ; enable Async Reception
[COLOR="red"]	banksel RCSTA[/COLOR]
        movwf RCSTA
;
; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
[COLOR="red"]        clrf dataL
settle  decfsz dataL,F
        goto settle

	banksel RCREG
        movf RCREG,W
        movf RCREG,W
        movf RCREG,W            ; flush receive buffer[/COLOR]

	return

However, I need to use this supplied code:

Code:
movlw b'00100100'
movwf   TXSTA               ; setup 8 bit serial transmission, high baud rate
movlw   .25
movwf     SPBRG         ; set baudrate 9,600
bcf  STATUS,RP0 ; select Bank 0
movlw     b'10010000'
movwf       RCSTA           ; enable serial port, and continuous reception
 
return

Are these codes comparible to the point where I could simply drop the second in as a replacement for the first? For example, ive highlighed the lines in the first code which dont appear in the second code in red. Also, is the settling time needed?

Any input on this would be very helpful, thank you.
 
Last edited:
I don't think that the settling time is needed for the USART, but it's a good idea to have a settling time at the start of a program, to make sure the power has had time to stabilise.

Once you have turned on the USART, you should either regularly poll the receive flag or have a receive interrupt. It isn't a good idea to let the receive buffer fill up, so the delay after turning on the USART isn't a good idea. It's better to disable the USART then enable it, which will an overflow.

The
Code:
banksel RCSTA
is a macro that changes the status RP0 and RP1 so that RCSTA can be accessed.
I don't know which processor you are using, and different processors have the RCSTA, TXSTA, SPBRG etc in different banks, so you will have to look up to see where they are, which will tell you whether you need the change banks in the code.
 
Status
Not open for further replies.

Latest threads

Back
Top