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.

Troubles with UART

Status
Not open for further replies.
You have a few things wrong,
You have a wend without a while.
You have an if without endif. (might be wrong here)

I would guess (I don't use basic on pics) it should be something like,
Code:
main
Usart_init(9600)
Usart_Write_Text (y)
loop:
if Usart_Data_Ready = 0 then
   ' do nothing
else
  i = Usart_Read ' Read the received data
  Usart_Write_Text (j)
  Usart_Write (i)
  PORTB = i
  delay_ms (3000)
end if
goto loop

Mike.

i have some question here
1. What is the use of line PORTB=i
2. i is a byte and suppose a string of character is going to pic from a computer will the pic be able to receive a string of cheracters at once or just it can receiving one char at a time.

help me please.
 
i have some question here
1. What is the use of line PORTB=i

It transfers the byte in 'i' to PortB.

2. i is a byte and suppose a string of character is going to pic from a computer will the pic be able to receive a string of cheracters at once or just it can receiving one char at a time.

Like everything else, including your PC, it can only receive one byte at a time - but only one byte at a time is sent. A string of characters is just one byte at a time, it's up to you what you do with them.
 
Thank you Nigel Goodwin for your reply
from question number 2 check the this program and help me on question below it.

1. program datatransmit
2. dim i as byte
3. dim y as char [40]
4. dim j as char [40]
5. y = "Please Choose a Number Between one and seven"
6. j = "Thank you for choosing"
7. TRISB = 0
8. main:
9. Usart_init(9600)
10. Usart_Write_Text (y)
11. loop:
12. if Usart_Data_Ready = 0 then
13. goto loop
14. Usart_Data_Ready = 1 then ' If data is received
15. i = Usart_Read ' Read the received data
16. Usart_Write_Text (j)
17. Usart_Write (i)
18. PORTB = i
19. delay_ms (3000)
20. goto main ' Send data via USART
21. end if
22. wend
23. end.

line 5 asign y as a string of characters, but when writing out he just say Usart_Write_Text (y) and all string of characters appears on the screen so why not to having a repeating job of taking each byte and send to a computer if any system write out or read one byte @ a time as per your replay.

Am sorry if the question is not interesting but your reply is very important to me.
 
Thanks for your reply but i still need some more help to understand the usart how it works this questions am asking are the one that during the study on PIC i didnt get them well so your relpy is interesting to me.

from the program above,
y is a string of characters so this line Usart_Write_Text (y) will send the string to Tx port am alright? although i don't know how the string will be moved byte by byte to that port

so here i get confused if am intended to receive a string to a PIC can i use the some method of writting this line i = Usart_Read where i has been declared as a string with capable size to hold this string received from Rx port.
 
Thank you Nigel Goodwin for your reply
from question number 2 check the this program and help me on question below it.



line 5 asign y as a string of characters, but when writing out he just say Usart_Write_Text (y) and all string of characters appears on the screen so why not to having a repeating job of taking each byte and send to a computer if any system write out or read one byte @ a time as per your replay.

Each character is sent sequentially, using a loop or a series of separate commands. It's your compiler which is hiding what is going on from you, try doing the same in assembler, and you will understand what's happening.

Check my tutorials 7.1 and 7.2 which show two different methods of sending a text 'string'.
 
Thanks again Nigel Goodwin
so with this compiler i hope it should work with receiving a string of character because it was able to transmit a sting i guess.
The aim here is to be able to send and receive AT command to a modem and receive an sms string from a modem, have u worked with sms controller Mr Nigel Goodwin, cos i was moving around AT command and i found when this AT+CMGR=0 command i sent to a modem it it will reply with this string +CMGR: 0,,26[CR][LF] 07910............ so i don't know how i can skip this +CMGR: 0,,26[CR][LF] and start to read the PDU string from a modem. Any comment on this please.
 
You need to consult the instructions for your compiler, it's not a PIC question, or an RS232 question, it's a question of your specific compiler.

Going back many decades to PC BASIC, there were routines to receive either a single character, or a string - you could also use the single character routine in a loop to receive a string. Once you've got your string in an array, you can process it to remove any parts you don't want.
 
Offline Assistance

Bojan

If you are still having ongoing problems then please PM me, as I am using the same MikroBasic compiler here together with their EasyPic5 Development board. I am happy to be of any assistance I can be.

Best regards,

Rupert
 
Thank you Nigel Goodwin for the tutorial,
from the tutorial i discovered that when working with usart delay time is very important but if the delay time is greater than that u specified for bit or for each 10 bits am i going to loose some data?
 
Thank you Nigel Goodwin for the tutorial,
from the tutorial i discovered that when working with usart delay time is very important but if the delay time is greater than that u specified for bit or for each 10 bits am i going to loose some data?

That's all taken of by your compiler, using either a software UART or the hardware one. But from previous discussions here, it all works fine as long as the timing is within +/-5% or so.
 
DECFSZ Bit_Cntr , f
sorry Nigel Goodwin from the above line what "f" stand for when decrementing register Bit_Cntr

again here
BTFSC STATUS , C
what C stand for and what its content
me i don't understand so your help please.

Am referencing from tutorial 7
 
Last edited:
DECFSZ Bit_Cntr , f
sorry Nigel Goodwin from the above line what "f" stand for when decrementing register Bit_Cntr

again here
BTFSC STATUS , C
what C stand for and what its content
me i don't understand so your help please.

Am referencing from tutorial 7

Read the datasheet - it's all explained in there, but 'f' stands for 'file register' and 'C' stands for Carry bit.
 
hallow Nigel Goodwin, Hi,

I need your help here am sorry if you get bored but i need your help to get things clear i went through every corner i dint get the meaning of " f " is it a register or not for example,

RRF Xmit_Byte , f
this instruction is transferring the lower bit to carry and the previous carry to 7th bit of Xmit_Byte i hope am correct
but ''f'' can be 0 or 1 to make sure the affected content of Xmit_Byte is stored to W when f=0 or to Xmit_Byte register when f=1 from above.
but the ''f'' was not assigned to any number and is used there can you tell me the content of ''f''.

BTFSS STATUS , C
also from this line above, i guess it is bit 0 or 1 is to be tested because C may contain 0 or 1 what was the intention of checking this bits.

Sorry again on my side i believe no matter which programming language is used to program, the programming itself is a trick of making something to happen with logics behind, so am interested with the tricks used so that i will be able to do programming in different approach sometime to make life easily. Please HELP don't get bored with ME!
 
hallow Nigel Goodwin, Hi,

I need your help here am sorry if you get bored but i need your help to get things clear i went through every corner i dint get the meaning of " f " is it a register or not for example,

RRF Xmit_Byte , f
this instruction is transferring the lower bit to carry and the previous carry to 7th bit of Xmit_Byte i hope am correct
but ''f'' can be 0 or 1 to make sure the affected content of Xmit_Byte is stored to W when f=0 or to Xmit_Byte register when f=1 from above.
but the ''f'' was not assigned to any number and is used there can you tell me the content of ''f''.

There are two destinations possible f or W, f writes the result back to the file register it came from, and W writes it to the W register.

Check the include file for the processor you're using, it lists the values of all the standard labels used - f (according to what you've said above) has the value '1' and W the value '0' - you use either f or W, depending where you want the result.

BTFSS STATUS , C
also from this line above, i guess it is bit 0 or 1 is to be tested because C may contain 0 or 1 what was the intention of checking this bits.

As with every other processor, Carry is a status bit you can check to find the result of some kind of operation, the datasheet lists which instructions cause it to change

.

Sorry again on my side i believe no matter which programming language is used to program, the programming itself is a trick of making something to happen with logics behind, so am interested with the tricks used so that i will be able to do programming in different approach sometime to make life easily. Please HELP don't get bored with ME!
 
There are two destinations possible f or W, f writes the result back to the file register it came from, and W writes it to the W register.

Check the include file for the processor you're using, it lists the values of all the standard labels used - f (according to what you've said above) has the value '1' and W the value '0' - you use either f or W, depending where you want the result.



As with every other processor, Carry is a status bit you can check to find the result of some kind of operation, the datasheet lists which instructions cause it to change

Thank Nigel Goodwin,
am sorry to asking again the some qn it is because i didn't get it well,
Could you please tell me what was the intention of writing this lines especially those line that work with ''f'' and ''C'' flags just put comment by telling why u decided to write the line please my intention is to get concept with programming trick or technique you used to implement this lines like
answering why you decided to to move the lsb to carry flag and the previous carry bit/status bit to msb of Xmit_Byte register.

Ser_Loop RRF Xmit_Byte , f ;send one bit
BTFSS STATUS , C
BCF PORTB, 6
BTFSC STATUS , C
BSF PORTB, 6
CALL Bit_Delay
DECFSZ Bit_Cntr , f ;test if all done
GOTO Ser_Loop
BSF PORTB, 6
CALL Bit_Delay
RETURN
 
RRF is a 9 bit rotate instruction, it rotates the specified register (8 bits) and the Carry flag (9th bit) - this allows you to easily test the bits in sequence, by testing the Carry flag after each rotate.

It's a VERY, VERY common technique, used on probably every processor there is - certainly on all those I've used.

Processors with more complex instruction sets sometimes also allow rotation without going into Carry, so a pure 8 bit rotate - useless for this application though.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top