Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] Programming in C language for 8051 Micro Controller

Status
Not open for further replies.

jignesh doshi

Full Member level 2
Joined
Aug 11, 2011
Messages
131
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,112
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?
 

for writing programs in c for 8051 , you must have a basic exposure in C.
The examples in the compiler installation you are going to use for 8051 (Keil or sdcc) will give you the idea.
 
Logic is same as assembly language or is there any other formula that i will use and my work is easy?
It's much easier that writing assembler, arithmetic operations and I/O format conversions can be performed by C-compiler libraries. For the latter, you should read the compiler documentation.
 

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?

One of the benefits of using high level programming languages (like C) is that you can write code (somewhat) freely and let the compiler worry about the exact conversion to assembler.

I.E
Code:
A = B * C ;
May translate to different machine instructions when compiled for 8 , 16 or 32 bit devices.
But you, as a high level C programmer don't need to take care of it yourself - the compiler does it for you.
 
Thanks to all for your warm reply...

anyone have any documents or example programs that can help me to understand better...
 

ok thanks,

Then if i have to show this result then how can i show?
 

Convert that integer value to string and either use UART to display data (ascii) on serial terminal or use LCD.
 

Hi,

Then if i have to show this result then how can i show?
You first need a display, or a printer, or something else...

For a 7 segment display you should divide the result in bcd bins...
For an ASCII display or printer use the "print" command, or it's derivates...

Klaus
 

I can display on 20x4 LCD but i cant display addition of two 32 bit data using 8051 Microcontroller using C Language...
 

How about showing the code that you have written so far?
 

can any one resolve problem of below given code?

my power_hz pin is P1.0, when i will get pulse on this pin i will get pulse on this pin at that time i will start my timer and when i will get again at that time i will stop my timer, and timer is working as counter.



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void hz()
        {   
            long int c,d;
            unsigned char d1,d2,d3,d4,d5;
            TH2 = 0x00;
            TL2 = 0x00;
                while(power_hz = 0)
                    {
                    }
                while(power_hz = 1)
                    {
                    }       
            TR2 = 1;
                while(power_hz = 0)
                    {
                    }
                while(power_hz = 1)
                    {
                    }
                while(power_hz = 0)
                    {
                    }
                while(power_hz = 1)
                    {
                    }
                while(power_hz = 0)
                    {
                            }
                while(power_hz = 1)
                    {
                    }
            TR2 = 0;

 

Change

Code:
while(power_hz = 0)

to

Code:
while(power_hz == 0)

Similar changes needed for other if() conditions.
 
like as in assembly language djnz r0,$ is there any type of function that i can written in C language?

- - - Updated - - -

Thanks a lot....

my problem is some how resolve...

i will revert back after testing..
 

i want to take data of one subroutine to another subroutine, then how can i transfer that data?

can i use global variable?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top