Discussion in "Project Help" started by    jigneshdoshi    Dec 11, 2015.
Fri Dec 11 2015, 12:42 pm
#1
Hello all,

Greetings for the day...!!!

still today i write program in assembly language for 8051 Micro Controller but Now i want to write program in C language and i have basic knowledge of C language.

my problem is if i want to do addition, multiplication, hex to decimal conversion, etc.. for more then 8 bits then how can i write.

Logic is same as assembly language or is there any other formula that i will use and my work is easy?
Sun Dec 13 2015, 04:12 am
#2
In C, you work with variables, which can be 8 bit ,16 bit ,or more.
Multiplying two 16 bit values is as easy as
   // unsigned  integers  are usually 16 bit for 8 bit micros
unsigned int  value1 = 1000;
unsigned int value2 = 60;
unsigned int result=0;

                result=value1 * value2;


I'm not sure what you mean by "hex to decimal conversion".
You can use printf() to print numbers but it uses a lot of code.



Thu Dec 17 2015, 10:32 am
#3
How can i do addition of two 32-bit number?
Fri Dec 18 2015, 06:31 am
#4
Just use a 32 bit variable size.
Check with your compiler reference.
For Keil it is a unsigned long int or a signed long int
depending on what you are doing.
Unsigned long handle bigger numbers but signed long
handles negative values.
unsigned long int  value1 = 200000;
unsigned long int value2 = 100000;
unsigned long int result=0;
 
                result=value1 + value2;

Of course the result may not fit into a 32 bit variable, so you would
need to make result 64bit , but not all compilers have 64 bit variables.


[ Edited Fri Dec 18 2015, 06:42 am ]
Fri Dec 18 2015, 10:30 am
#5
Thanks for your reply...

and then if i want to display it on 20x4 Alphanumeric LCD then how can i do?
Mon Dec 21 2015, 08:04 am
#6


Thanks for your reply...
and then if i want to display it on 20x4 Alphanumeric LCD then how can i do?

jigneshdoshi


Take a look at our LCD tutorial, it gives examples in c and asm.
Then write a routine to print to the LCD.

You can write your own code to turn a number into an
ASCII string or use sprintf(), if your compiler has it.
Not all do.
sprintf() creates an ASCII string in a buffer, you just copy it
to the LCD display.



Sat Feb 20 2016, 02:35 pm
#7
What is the meaning of using 2 in below code?

is it compulsory to write down this in interrupt routine?

void timer0 (void) interrupt 1 using 2 {
if (++interruptcnt == 4000) { /* count to 4000 */
second++; /* second counter */
interruptcnt = 0; /* clear int counter */
}
Mon Feb 22 2016, 04:51 am
#8


What is the meaning of using 2 in below code?

void timer0 (void) interrupt 1 using 2 {
if (++interruptcnt == 4000) { /* count to 4000 */
second++; /* second counter */
interruptcnt = 0; /* clear int counter */
}

jigneshdoshi


I believe the 8051 has two sets of registers
R0,R1,R2 etc
"using 2" tells the compiler to use set 2 for this interrupt
instead of the default, set 1.
I suppose in some cases it will save a couple of microseconds.

Normally I doubt it matters.
Try with "using 1" or nothing, let us know if it makes
a difference.

Tue Feb 23 2016, 05:29 pm
#9
ok thanks,

Now i want to take data from interrupt subroutine to main function or other subroutine then how can i take?
Wed Feb 24 2016, 03:59 pm
#10
You can use global variables (or buffers etc.) which gets filled in interrupt routine and a flag which indicates that new data has come. You can check state of flag and use the new data.

//example
char x;
volatile char new_data = 0;
void isr_code()
{
    x = 123;
    new_data = 1;
}

// in main function
void main()
{
    //... other piece of code
    if (new_data) {
        new_data = 0;
        //... use the new updated x
    }
}
 jigneshdoshi like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am