Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools Display Modes
Old 7th December 2006, 09:54 PM   #1 (permalink)
Default calculator program 8051

i want calculator program that it can do add,sub,div,mul
sirous is offline  
Old 7th December 2006, 10:31 PM   #2 (permalink)
Default

Quote:
Originally Posted by sirous
i want calculator program that it can do add,sub,div,mul
Did you mean the Simulator for the 8051?


Please check edSim-51: http://edsim51.com/
__________________
Microcontroller Programming Forums:
http://forum.mcuprogramming.com
Answer to your questions!
---

Microcontroller Programming Blog:
http://mcu-programming.blogspot.com
uC - News, Resources and Tutorials

Last edited by sci-3d; 8th December 2006 at 03:16 AM.
sci-3d is offline  
Old 7th December 2006, 10:41 PM   #3 (permalink)
Default

When is your assignment due?
phalanx is offline  
Old 9th December 2006, 12:29 PM   #4 (permalink)
Default

Quote:
Originally Posted by phalanx
When is your assignment due?
i want it for next week
sirous is offline  
Old 9th December 2006, 12:33 PM   #5 (permalink)
Default

Quote:
Originally Posted by sci-3d
Did you mean the Simulator for the 8051?


Please check edSim-51: http://edsim51.com/
yes
i want it can just do add,sub,mul and div
and it can calculate until one number after point
ex:
35/4=8.7
sirous is offline  
Old 9th December 2006, 12:35 PM   #6 (permalink)
Default

yes
for 8051
sirous is offline  
Old 9th December 2006, 12:42 PM   #7 (permalink)
Default

http://www.drpaulcarter.com/pcasm/

Well, start programming!!!! If it is due next week, then you have a week to learn assembly, and then make(and debug) a complete calculator program...
__________________
There is no "I" in "team", unless Apple makes it... Then it would be iTeam.
Marks256 is offline  
Old 9th December 2006, 01:43 PM   #8 (permalink)
Default

Also we don't mind helping but we won't do all the work for you.
__________________
I also post at the following sites:
http://www.stop-microsoft.org http://www.heated-debates.com
Screen name: Aloone_Jonez
And http://www.silicontronics.com, same screen name as here.

I do not answer private messages asking for help because no one else can: benefit from advice I may give or correct me if I'm wrong.

Please ask on the open forum if you have a question and I'll be happy to help,
if I know the answer.
Hero999 is offline  
Old 9th December 2006, 07:04 PM   #9 (permalink)
Default

http://www.pjrc.com/tech/8051/

scroll down towards the bottom. There is a bunch of sample code at the bottom. There is also a pretty cool development board, too(didn't look at it much, though).
__________________
There is no "I" in "team", unless Apple makes it... Then it would be iTeam.
Marks256 is offline  
Old 13th December 2006, 08:01 AM   #10 (permalink)
Default a sample file from proteus which u want

/************************************************** *****************************
************ LABCENTER ELECTRONICS ************
************ Proteus VSM Sample Design Code ************
************ Integer Calculator ( 2K Code Limit) ************
************************************************** *****************************/

#include <intrins.h>
#include <reg51.h>
#include "calc.h"

//Variables
static data LONG lvalue;
static data LONG rvalue;
static data CHAR currtoken;
static data CHAR lasttoken;
static data CHAR lastpress;
static xdata CHAR outputbuffer[MAX_DISPLAY_CHAR];

VOID main (VOID)
//Initialise our variables and call the
//Assembly routine to initialise the LCD display.
{ lvalue = 0;
rvalue = 0;
currtoken = '=';
lasttoken = '0';
initialise(); // Initialize the LCD
calc_output(OK);
calc_evaluate();
}

VOID calc_evaluate()
{ CHAR data key;
INT data i;
CHAR xdata number[MAX_DISPLAY_CHAR];
CHAR xdata *bufferptr;

// Clear the buffer before we start.
for (i = 0; i <= MAX_DISPLAY_CHAR; i++)
{ number[i] = ' ';
}
bufferptr = number;

for (;
{ key = calc_getkey();
if (calc_testkey(key))
// Key test positive for digit so we read it into the
// buffer and then write the buffer to the screen/LCD.
// Size limit the number of digits - allow for termination
// and possible negative results.
{ if (bufferptr != &number[MAX_DISPLAY_CHAR - 2])
{ *bufferptr = key;
calc_display(number);
bufferptr++;
}
}

else
// Key is an operator so pass it to the function handlers.
// If we are just after startup or cancel then assign to lvalue
// otherwise assign to rvalue.
{
//Assign the value.
if (lasttoken == '0')
{ lvalue = calc_asciidec (number);}
else
{ rvalue = calc_asciidec (number);}

//Clear the number buffer.
bufferptr = number;
for (i = 0;i <= MAX_DISPLAY_CHAR; i++)
{ number[i] = ' '; }

//Process the Operator.
currtoken = key;
if (currtoken == 'C')
{ calc_opfunctions(currtoken); }
else
{ calc_opfunctions(lasttoken); }

// Clear the outputbuffer for reuse on next operation.
for (i = 0;i <= MAX_DISPLAY_CHAR;i++)
{ outputbuffer[i] = ' ';}

bufferptr = number;
// Handle the equals operation here for brevity.
// All we need do is preserve the previous operator in
// lasttoken.
if (currtoken != 0x3D) lasttoken = currtoken;

}
lastpress = key;
}
}

VOID calc_opfunctions (CHAR token)
// Handle the operations. Lvalue holds the result and we test for
// consecutive operator presses.
{ CHAR data result;
switch(token)
// Add.
{ case '+' : if ((currtoken == '=' ) || ((lastpress >= 0x30) && (lastpress <=0x39)))
{ lvalue += rvalue;
result = calc_chkerror(lvalue);
}
else
{ result = SLEEP; } break;
// Subtract.
case '-' : if ((currtoken == '=' ) || ((lastpress >= 0x30) && (lastpress <=0x39)))
{ lvalue -= rvalue;
result = calc_chkerror(lvalue);
}
else
{ result = SLEEP;} break;
// Multiply.
case '*' : if ((currtoken == '=' ) || ((lastpress >= 0x30) && (lastpress <=0x39)))
{ lvalue *= rvalue;
result = calc_chkerror(lvalue);
}
else
{ result = SLEEP;} break;
// Divide.
case '/' : if ((currtoken == '=' ) || ((lastpress >= 0x30) && (lastpress <=0x39)))
{ if (rvalue)
{ lvalue /= rvalue;
result = calc_chkerror(lvalue);
}
else
{ result = ERROR;}
}
else
{ result = SLEEP;} break;
// Cancel.
case 'C' : lvalue = 0;
rvalue = 0;
currtoken = '0';
lasttoken = '0';
result = OK; break;

default : result = SLEEP;

}
calc_output(result);
}


/************************************************** **********************
***** Utility Routines *****
***************************/

INT calc_chkerror (LONG num)
// Check upper and lower bounds for the display.
// i.e. 99999999 and -99999999.
{ if ((num >= -9999999) && (num <= 9999999))
return OK;
else
return ERROR;
}


VOID calc_output (INT status)
// Output according to the status of the operation.
// *Sleep* is used for the first op press after a full cancel
// or on startup.
{ switch (status)
{ case OK : calc_display(calc_decascii(lvalue)); break;
case SLEEP : break;
case ERROR : calc_display("Exception "); break;
default : calc_display("Exception "); break;
}
}


LONG calc_asciidec (CHAR *buffer)
// Convert the ASCII string into the floating point number.
{ LONG data value;
LONG data digit;
value = 0;
while (*buffer != ' ')
{ digit = *buffer - 48;
value = value*10 + digit;
buffer++;
}
return value;
}

CHAR *calc_decascii (LONG num)
// A rather messy function to convert a floating
// point number into an ASCII string.
{ LONG data temp = num;
CHAR xdata *arrayptr = &outputbuffer[MAX_DISPLAY_CHAR];
LONG data divisor = 10;
LONG data result;
CHAR data remainder,asciival;
INT data i;

// If the result of the calculation is zero
// insert a zero in the buffer and finish.
if (!temp)
{ *arrayptr = 48;
goto done;
}
// Handle Negative Numbers.
if (temp < 0)
{ outputbuffer[0] = '-';
temp -= 2*temp;
}

for (i=0 ; i < sizeof(outputbuffer) ; i++)
{ remainder = temp % divisor;
result = temp / divisor;

// If we run off the end of the number insert a space into
// the buffer.
if ((!remainder) && (!result))
{ *arrayptr = ' ';}

// We're in business - store the digit offsetting
// by 48 decimal to account for the ascii value.
else
{ asciival = remainder + 48;
*arrayptr = asciival;
}

temp /= 10;
// Save a place for a negative sign.
if (arrayptr != &outputbuffer[1]) arrayptr--;
}
done: return outputbuffer;
}


CHAR calc_testkey (CHAR key)
// Test whether the key is a digit or an operator. Return 1 for digit, 0 for op.
{ if ((key >= 0x30) && (key <= 0x39))
{ return 1;}
else
{ return 0;}
}

/************************************************** **********************
***** I/O Routines *****
***********************/

CHAR calc_getkey (VOID)
// Use the input routine from the *Keypad_Read* assembly file to
// Scan for a key and return ASCII value of the Key pressed.
{ CHAR data mykey;
do mykey = input();
while (mykey == 0);
return mykey;
}

VOID calc_display (CHAR buf[MAX_DISPLAY_CHAR])
// Use the Output and Clearscreen routines from the
// *LCD_Write* assembly file to output ASCII values to the LCD.
{ INT data i = 0;
clearscreen();
for (i ; i <= MAX_DISPLAY_CHAR ; i++)
{ if (buf[i] != ' ')
{ output(buf[i]); }
}
}
masud58 is offline  
Old 13th December 2006, 09:10 PM   #11 (permalink)
Default

And you couldn't have linked to the original source because....?
__________________
There is no "I" in "team", unless Apple makes it... Then it would be iTeam.
Marks256 is offline  
Old 15th December 2006, 07:49 PM   #12 (permalink)
Default

thanks a lot masud
sirous is offline  
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Title Starter Forum Replies Latest
hyperterminal communication w/ 8051 spyghost Micro Controllers 8 22nd May 2008 10:54 AM
8051 Microcontroller (Urgent Help) UAE_Engineer Micro Controllers 5 22nd March 2007 11:13 AM
Could I get away with this? (8051 + AM29F010B) mstechca Micro Controllers 0 9th March 2006 02:05 AM
interfacing 16*16 matrix display with 8051 pmphilip Micro Controllers 0 1st February 2005 03:47 AM
8051 "data" storage within program memory - how? L0D|Mr_B Micro Controllers 1 11th January 2004 02:56 PM



All times are GMT. The time now is 01:38 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker