1. 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.
    Dismiss Notice

Help on writing an 8051 program

Discussion in 'Homework Help' started by emmawatson123, Oct 23, 2015.

  1. emmawatson123

    emmawatson123 New Member

    Joined:
    Oct 23, 2015
    Messages:
    3
    Likes:
    0
    hello guys

    can you help me on writing this program for my 8051 please

    Part 1:
    Write a program to continuously detect whether the addition of 2 numbers stored in memory locations MEM[30h] and MEM[38h] is greater than or equal to 100. The program should output the result of the addition on port0 and if the result is greater than or equal to 100 then turn off (clear) bit P1.0 otherwise turn on (set) P1.0

    Part 2:
    Write a program to calculate y where y = x2 + 3x + 2. Where x is between 0 and 9 and the look-up table for x2 is located at the ROM address (code space) of 200h. The value x is in memory location MEM[70h], and at the end of the program R2 should have y.
     
  2. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,904
    Likes:
    502
    Location:
    Cleveland, OH, USA
    ONLINE
    Sounds like homework. What have you done so far? I don't do 8051, only PIC.

    Part 1: Is the "100" hex, decimal or binary? Is the output to be serial or parallel?

    Part2: Again, is the radix decimal or hex? Why do you need a look-up table for x2? Won't a left rotate take care of that? Times 3 is a rotate plus an add. Of course a lookup table will also work.

    John
     
  3. emmawatson123

    emmawatson123 New Member

    Joined:
    Oct 23, 2015
    Messages:
    3
    Likes:
    0
    this is an homework that i have researched a lot to solve it but i couldn't

    part 1 : parallel
    part 2 : decimal
    look-up table for x2 because my teacher wanted that way
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,904
    Likes:
    502
    Location:
    Cleveland, OH, USA
    ONLINE

    For Part 1, you can play with the characteristics of d'100', for example both bits 5,6 must be set and/or bit 7 must be set. I woud suggest spending a little time working through those possibilities. Then, checkout PicList.com. Here is a link to finding a range: http://www.piclist.com/techref/microchip/rangechk.htm It is pretty obvious what that scheme does, but if you don't understand it and present it as your result, then you are just hurting yourself. For parallel reporting, just move the binary to the port. If the 100 is binary instead of decimal, then the question is trivial.

    For Part 2, reduce that algebraic equation to just 2 terms. Oops, forget that. On second thought, you must mean x^2 + 3x +2, right? The answers are all less than 255, so a single byte table will work. Your teacher must have shown how to set up a table read. A table with the whole answer would be the same length as one for just x^2. Can you do that instead?

    John
     
  6. emmawatson123

    emmawatson123 New Member

    Joined:
    Oct 23, 2015
    Messages:
    3
    Likes:
    0
    im afread i cant do it by my self

    since he didn't show us anything, he just have given us a book of 600 pages
    to read it and write this code
     
  7. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,904
    Likes:
    502
    Location:
    Cleveland, OH, USA
    ONLINE
    Come on. Try the part 1. Look at the PicList link and think about what is being done. That is how programmers think. Wtih an 8-bit byte, what value can you add to decimal 100 to always cause an overflow?

    Part 2: Sorry, but I suspect tables on the 8051 are done a little differently than on the PIC's and I don't want to confuse you with actual code. Basically, the values in a table are in sequential order. If x is "7", then the answer for x^2 (or the solution to the whole equation) will be located at the 8th position (assuming you start at 0), and so forth. You call the table and add that offset to return the result. That is how PIC does it, and I suspect the 8051 is similar.
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE
    The 8051 has ( like every micro ) math flags.... If you load mem[30h] into A and mem[31h] into register B and then add..

    deduct 100 from A and test the flags... C carry Z zero...
     

Share This Page