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.

Whats wrong with this code..??

Status
Not open for further replies.

Electrix

Member
I tried this on my simulator, but the TRMT(TXSTA,1) is just no turning low. Hence my Transmit Shift Register is not getting filled up and no data is being sent out.

PIC 16F73
4Mhz.


list p=16f73 ;list directive to define processor
#include <p16f73.inc> ;processor specific definitions
errorlevel -302 ;suppress "not in bank 0" message

__CONFIG _CP_OFF
;Variables decleration

DataByte equ 0x21


;This code executes when a reset occurs.

ORG 0x000 ;place code at reset vector

ResetCode: clrf PCLATH ;select program memory page 0
goto Main ;go to beginning of program

Main
;Loading DataByte
movlw 0x10
movwf DataByte


BANKSEL SPBRG
movlw D'25'
movwf SPBRG
BANKSEL TXSTA
bsf TXSTA,BRGH
BANKSEL SPBRG
movlw D'25'
movwf SPBRG
BANKSEL TXSTA
bsf TXSTA,BRGH

BANKSEL TXSTA
movlw B'00100100'
movwf TXSTA
BANKSEL RCSTA
movlw B'10010000'
movwf RCSTA
BANKSEL TXSTA
movlw B'00100100'
movwf TXSTA
BANKSEL RCSTA
movlw B'10010000'
movwf RCSTA

BANKSEL PIR1
WaitTX: btfss PIR1,TXIF
goto WaitTX
BANKSEL PIR1


BANKSEL DataByte
movf DataByte,W
BANKSEL TXREG
movwf TXREG


end

 
Oops ! I apologize for my haste !

I forgot to decrease the UART Transmit/Receive Time. I had initally set to 1000 clock cyles on the simulr,.. and I didn't wait enough.
Now i've decreased this time and its working fine !!! :) :)

Nigel, I thought we need not wory abt the I/O settings, cause once we initialize the TXSTA register and set the Transmit Enable Bit , it takes care of it....atleast thats what happening now :roll:
 
Unless I'm missing it?, I can't see where you set the pin to be an output?, all I/O pins (rather sensibly) default to be inputs!.

Nigel, this is one of many PIC devices where the Data Sheets tell you to set the TRIS bits for the UART RX and TX pin to inputs...

Regards, Mike
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top