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.

UART simulation with pic simulator IDE

Status
Not open for further replies.

Anuradha1

Member level 2
Joined
Nov 11, 2009
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
India
Activity points
1,570
Hello all,

I am using PIC simulator IDE to simulate my assembly code written for pic16f877a with oscillator frequency 16MHz.

I am sending data to UART.

In my code i can adjust the delay between sequent transmission as follows.

movf WH,0
movwf TXREG ;Transmit to PC
call Delay
call Delay
movf WL,0
movwf TXREG ;Transmit to PC
call Delay
call Delay

The Delay loop I have written is given below.

Delay
decfsz CounterL,1
goto Delay
return


But when i simulate it doesnot transmit data to UART simulation interface according to the delay time i have given in the program.

I can increase the transmission rate by reducing tx delay time in "Change UART Transmit/Receive time" in option tab of the IDE window. When i reduce this time the simulator works nicely according to the time set there.

What i want to know is Can i adjust the delay of sequent transmissions in my code, so that it works according to the delay i need/ i give, not depending on the value set at "Change UART Transmit/Receive time" of simulator interface.

As i have seen simulator doesnot take the delays given in the code.

Also what is the minimum time duration I can have between two sequent transmissions from Uart?

Any information? advice regarding this matter is appreciated.

Thanks in advance.
 

It depends - if you want to deliberately add a delay between transmissions, say 1 or two seconds, look on Google for PIC delay generator programs. They will tell you how to configure loops to make delays lasting as long as you want.

It may be that you don't really want a delay, if you are trying to send characters as fast as possible and your delays are there just to allow time for the previous character to leave the UART, you are doing it wrong! Look at the UART section of the data sheet and you will see there is a bit that tells you when the TX register is empty. What you should do is check the bit says it is safe to load the TXREG then put the data in it. If the bit says it isn't empty you have to wait, either in a loop checking the bit or some other way, until it is safe to go ahead.

I'm not sure about your WH and WL variables, the code doesn't look right. Do you really want to save variables in address 0?

Brian.
 

Thanks for your reply betwixt. :)

I will look into the point you have highlighted.

In my code,
movf WL,0

Will move the value syored in WL to the working register W. This value in W is aent to the TX register in the subsequent line.

Bye.
 

Sorry, my mistake.

Instead of using '0', use the defined name in the include file. I think it will be 'f' for file and 'w' for working register as the definition. it makes the code easier to read. Similarly, the decfsz should use f or w.

Note that the first time you call your "Delay" routine it may not loop 256 times because you do not initialize "CounterL".

When posting code in Edaboard, please click the box above the message window labeled "Code" then insert the code and finally click the "Code" box again to return to normal. It tells the forum software not to change the formatting so we see it the same as it would be in your program editor.

Brian.
 

I was not aware of posting codes in edaboard.
Thanks Brian for mentioning that.
 

By code I meant a section of your program.

For example, the two sections below are identical, the first section is just pasted into this message, the second is pasted between code tags (box 5 in the line above the message entry window).

Just pasted:

;delay by programmed period (ABDelay * 100mS) before transmitting
AntiBounce
movf ABDelay,W ;retrieve the anti-bounce value
movwf DelayTimer ;number of times 100mS delay is repeated
ABLoop
call Delay100m
decfsz DelayTimer,F ;more loops needed?
goto ABLoop

;send the preamble of 0x55 followed by a three bit low then high
Preamble
banksel PORTA
bsf TxEn ;transmitter carrier on
bsf LED_A ;flash green LED while transmitting
bcf LED_B
movlw 0x28 ;bit counter
movwf ShiftCount
PreambleLoop
bsf TxPin ;TX pin high

Pasted between code tags:
Code:
    ;delay by programmed period (ABDelay * 100mS) before transmitting   
AntiBounce
    movf    ABDelay,W           ;retrieve the anti-bounce value
    movwf   DelayTimer          ;number of times 100mS delay is repeated
ABLoop
    call    Delay100m
    decfsz  DelayTimer,F        ;more loops needed?
    goto    ABLoop
    
    ;send the preamble of 0x55 followed by a three bit low then high
Preamble
    banksel PORTA
    bsf     TxEn                ;transmitter carrier on
    bsf     LED_A               ;flash green LED while transmitting
    bcf     LED_B
    movlw   0x28                ;bit counter
    movwf   ShiftCount
PreambleLoop
    bsf     TxPin               ;TX pin high

You can see how it makes the code much easier to read. Ignore the content of my program, it's just something I copied as an example.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top