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.

Help on writing an 8051 program

Status
Not open for further replies.

emmawatson123

New Member
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.
 
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
 
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

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
 
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: 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
 
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: 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

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
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top