• 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.

code help for 8051

Status
Not open for further replies.

iwineuro2008

New Member
hi friends,
i am making a project of rotating the stepper motor according to the difference in actual value(from sensor) compared to the user set value(from key pad). the keypad consists of two pushbuttons (+ & -) and i have used two 7 segment displays to show the user set value as shown in schematic below.i am using a 8051 family micro controller. i need to increment the display every time + button is pressed and decrement when - is pressed .

also need to compare the adc value with the user set value and know if difference is positive or negative.my range for display is 0 to 100% whereas my adc is 8 bit i.e. 0-255 combinations.how to compare these two??
 

Attachments

sapan_1127

New Member
actually i dont seem to understand what u are asking.. maybe the more experienced and well versed users will help you out..
 

Papabravo

Well-Known Member
You convert the A2D reading from a range of 0-255 into a range of 0-100. How you do this is with simple arithmetic. These problems are what we used to call "ratio and proprotion"
Code:
x/256 = y/100       ; SO
y = (100 * x)/256
You can also use 255 in the denominator if getting the value 100 for full scale is important, and you can truncate the result of the division or use the ceiling or floor functions to round the result, but you need to have a better understanding of your requirements.
 
Last edited:

rushi53

Member
hi friends,
i am making a project of rotating the stepper motor according to the difference in actual value(from sensor) compared to the user set value(from key pad). the keypad consists of two pushbuttons (+ & -) and i have used two 7 segment displays to show the user set value as shown in schematic below.i am using a 8051 family micro controller. i need to increment the display every time + button is pressed and decrement when - is pressed .

also need to compare the adc value with the user set value and know if difference is positive or negative.my range for display is 0 to 100% whereas my adc is 8 bit i.e. 0-255 combinations.how to compare these two??

give a range
like 0 to 25 of ADC = 0% to 10%
like 25 to 50 of ADC = 10% to 20%
like 50 to 75 of ADC = 20% to 30%
like 75 to 100 of ADC = 30% to 40%
like 100 to 125 of ADC = 40% to 50%
like 125 to 150 of ADC = 50% to 60%

and so on...

please let me know if you need some more info...
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top