This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

8051 with zigbee

any ideas on how i can write a code to transmit an AT command from 8051 to zigbee serially? thanks in advance

Parents
  • sbit mybit=P1^5;
    


    "mybit" - that really isn't a variable name that tells any story about what it does.
    Later in the program you have:

     mybit=1; //toggle LED
    


    So why must a reader scan through all your code just to figure out that "mybit" is actually controlling a LED? And "toggle LED" still doesn't tell a reader if writing a '1' will turn on or turn off that LED.

    unsigned char code start_header='!';
    


    You used a #define for CR, but then you decided to use normal variables for some of your "constants" - are you saying that your program supports reprogrammable tokens for the framing of your messages?

    unsigned char x,i,j,k,z,u,h; //declare variables for checking use
    


    Is it easy to read code when you need to all the time figure out what's the difference between 'i', 'j' or maybe 'k'? Or what is currently stored in 'u'? Your comments seems to indicate that 'k' is "the values". Easy to see from the name?

    Every second you save with a short variable name like this you normally lose quite a number of minutes from being confused about the meaning of the variable.

    read[read_count]=zigbeerxd[read_count]; //read the data
    


    Seems strange that you have two different arrays but use the same index. So the raw data received from the UART is identically aligned with your currently processed command?

    if(read[read_count]==end_header) //check if data is '@'(end header)
    


    Why have a constant downgraded into a variable "end_header" if you still need to write a comment telling us that the variable is '@' and that '@' means "end header"? Does it make sense to try to write the same program twice - once as C code and once as C comments? Isn't it better to have C symbol names that tells the story and instead reserve the C comments for telling the reader why you need to do different things?

    Because of your formatting issues (while ignoring the 'well-named' variables, it's almost impossible to actually read the code. But you have a busy-loop delay() that you most probably can't tell how long delays it actually gives. Or what happens if you maybe change some compiler options or changes to a different version of the compiler. Busy-loops aren't a good way to implement delays. Wouldn't it be better with a delay_100us(2000) that could have a user know that each tick of the input parameter represented 0.1ms of delay so the reader could figure out that delay_100us(2000) would be a 200ms delay?

    By the way - you posted code without specifically telling what issues you have with the code and what you have done to try to overcome these issues.

Reply
  • sbit mybit=P1^5;
    


    "mybit" - that really isn't a variable name that tells any story about what it does.
    Later in the program you have:

     mybit=1; //toggle LED
    


    So why must a reader scan through all your code just to figure out that "mybit" is actually controlling a LED? And "toggle LED" still doesn't tell a reader if writing a '1' will turn on or turn off that LED.

    unsigned char code start_header='!';
    


    You used a #define for CR, but then you decided to use normal variables for some of your "constants" - are you saying that your program supports reprogrammable tokens for the framing of your messages?

    unsigned char x,i,j,k,z,u,h; //declare variables for checking use
    


    Is it easy to read code when you need to all the time figure out what's the difference between 'i', 'j' or maybe 'k'? Or what is currently stored in 'u'? Your comments seems to indicate that 'k' is "the values". Easy to see from the name?

    Every second you save with a short variable name like this you normally lose quite a number of minutes from being confused about the meaning of the variable.

    read[read_count]=zigbeerxd[read_count]; //read the data
    


    Seems strange that you have two different arrays but use the same index. So the raw data received from the UART is identically aligned with your currently processed command?

    if(read[read_count]==end_header) //check if data is '@'(end header)
    


    Why have a constant downgraded into a variable "end_header" if you still need to write a comment telling us that the variable is '@' and that '@' means "end header"? Does it make sense to try to write the same program twice - once as C code and once as C comments? Isn't it better to have C symbol names that tells the story and instead reserve the C comments for telling the reader why you need to do different things?

    Because of your formatting issues (while ignoring the 'well-named' variables, it's almost impossible to actually read the code. But you have a busy-loop delay() that you most probably can't tell how long delays it actually gives. Or what happens if you maybe change some compiler options or changes to a different version of the compiler. Busy-loops aren't a good way to implement delays. Wouldn't it be better with a delay_100us(2000) that could have a user know that each tick of the input parameter represented 0.1ms of delay so the reader could figure out that delay_100us(2000) would be a 200ms delay?

    By the way - you posted code without specifically telling what issues you have with the code and what you have done to try to overcome these issues.

Children
  • "you have a busy-loop delay() that you most probably can't tell how long delays it actually gives. Or what happens if you maybe change some compiler options or changes to a different version of the compiler."


    See: www.8052.com/.../162556

  • OK, thanks. but now i want to transmit a string of AT command using array from the 8051 micro controller to the computer and see through hyperterminal. i am able to transmit just a character like 'A'. But i'm not clear as to how to send a string of data using arrays. thank you in advance.

  • "But i'm not clear as to how to send a string of data"

    Well, a string is just a sequence of characters, isn't it?

    So you send the first, then the second, then the third, etc - until you reach the end.

    This is just basic indexing through an array. If you're not clear on that, then it's time to get back to the basic 'C' textbook

    blog.antronics.co.uk/.../

    Remember that the serial transmission is slow compared to the instruction execution - so you need to wait for the transmission of one character to finish before starting the next.

    Also, you need to wait for and correctly handle the response to each AT command before starting the next...

  • You do know how 'C' marks the end of a string - don't you?

  • What if i want to transmit a long string? Maybe around 40 to 50 characters. Do i still send a character one at a time? No right? If not the code will be very very long.

  • If you want to walk 10 kilometers do you then take one step at a time, or do you suddenly take 100 steps at the same time?

    You always have to send one character at a time.

    Program becomes very long? Why? Haven't you actually tried to search for the keywords "string" and "array" on Google? A loop that sends all characters in a string/array doesn't take more space because the string/array contains 50 characters instead of 1 character. It's only the assign of the string/array that will be come a longer line until the string is so long that you need to split it over multiple source code lines.

    const char string[] = "This is a long string of many characters to send."
    

  • Have you not heard of loops ??

    If not, then you really need to get (back) to that basic textbook!