Programming in C – Tips for Embedded Development.

Here I will highlight some features of C language commonly used in 8 bit embedded platforms like 8051, AVR and PICs. While programming microcontrollers in C most of the time we have to deal with registers. Most common tasks are setting and clearing bits in a register and check whether a bit is 0 or 1 in a given register. So here I will give detail on those topics, it will help you if you are new to embedded programming in C and if you get confused when you see some codes.



A Register

A register is simply a collection of some bits (mostly 8 bits in case of 8bit MCUs). Either each different bit in a register has some purpose or the register as a whole holds a value. Registers serves as connection between a CPU and a Peripheral device (like ADC or TIMER). By modifying the register the CPU is actually instructing the PERIPHERAL to do something or it is configuring it in some way. And by reading a register, the CPU can know the state of peripheral or read associated data.

microcontroller register

Fig.: CPU writing to Peripheral Register

 

microcontroller register

Fig.: CPU Reading from Peripheral Register

Binary Numbers in C

When you write a=110; in C it means you are setting the value of variable"a" to "one hundred and ten" (in decimal). Many time in embedded programming we are not interested in the value of a variable but the state of each bits in the variable. Like when you want to set the bits of a register (MYREG) to a bit pattern like 10010111 (binary). Then you cannot write MYREG=10010111. Because compiler will interpret 10010111 as decimal. To specify a binary number in C program you have to prefix it with 0b (zero followed by b). So if you write

MYREG=0b10010111;

it assigns the bit pattern 10010111 to the bits of Register MYREG.

HEX Numbers in C

In same way if you prefix a number by 0x (a zero followed by x) then compiler interpret it like a HEX number. So

MYREG=0x10; (10 in HEX is 16 in decimal)

MYREG=0xFF;(Set all bits to 11111111 or decimal 255)

Setting a BIT in Register

Here our aim is to set (set to logical 1) any given bit (say bit 5) of a given register (say MYREG). The syntax is

MYREG=MYREG | 0b00100000;

The above code will SET bit 5 to 1 leaving all other bits unchanged. What the above code does is that it ORs each Bit of MYREG with each bit of 0b00100000 and store the value back in MYREG. If you know how logical OR works then you will get it.

In short you can write the same code as

MYREG|=0b00100000;

Now lets come to practical usage. In practice each bit has got a name according to its work/function. Say our BIT (the 5th bit) has got name ENABLE, and what it does is clear by its name,when we set it to 1 it enables the peripheral and when cleared (0) it disables it. So the right way to set it is.

MYREG|=(1<<ENABLE);

The << is called left shift operator. It shifts the bits of LHS variable left by the amount on its RHS variable. If you write

b=1<<3;

then, 1 whose binary value is 00000001 is shifted 3 places to left which results in 00001000

So if ENABLE is defined as 5 (as enable is 5th bit) then

MYREG|=(1<<ENABLE);

will result in

MYREG|=(1<<5);

which again result in

MYREG|=(0b00100000);

Now a beginner would ask "What’s the Advantage ?". And once you know it you would realize that advantage is immense!

  1. Readability of code: MYREG|=(1<<ENABLE); gives a clue that we are enabling the peripheral while MYREG|=0b00100000; does not give any clue what it is doing, we have to go to data sheet and find out which bit actually ENABLEs the peripheral. While ENABLE=5 is already defined in header files by the developer of compiler by carefully studying the datasheets of device.
  2. Easier Portability: Suppose you use this code many times in your program (and your program is reasonably large and uses other register also) and you now want the same code to run on some other MCU model. The new MCU is of similar family but has slightly different bit scheme, say ENABLE is bit 2 instead of bit 5. Then you have to find all occurrence of MYREG|=(0b00100000); and change that to MYREG|=(0b00000100); But if you have used the other method then you simply need to inform the compiler (by its setting options) that you are going to use the other MCU and compiler will automatically get the definitions for the new device. And in this definition ENABLE=2 will already be defined by the compiler developer. So it will be lot easier.

Clearing a BIT in Register

For clearing a bit logical AND(symbol &) operator is used in place of logical OR (symbol |). The syntax is as follows

MYREG&=~(1<<ENABLE);

CLEARING A BIT IN C LANGUAGE

Fig.: How to clear (0) a bit in C language.

This will clear (i.e. set to value 0) a given bit (identified by name ENABLE) in a register called MYREG. This operation will not affect any other bits of register except ENABLE.

Let us see how it works with the help of following diagram.

how clearing a bit in C works?

Fig.: "Clearing a BIT" how it works?

So now you know how you can selectively clear any bit in any given register. If you want to clear more than one bit at a time you can write like this

//This will clear bits ENABLE,FAST_MODE and BUSY, leaving all other bits untouched
MYREG&=(~((1<<ENABLE)|(1<<FAST_MODE)|(1<<BUSY))); 

Similarly the syntax for setting(set to 1) multiple bits at a time is as follows

//This will set bits ENABLE,FAST_MODE and BUSY, leaving all other bits untouched
MYREG|=((1<<ENABLE)|(1<<FAST_MODE)|(1<<BUSY)); 

Testing The Status of a Bit.

Till now we were modifying the registers either setting or clearing bits. Now we will learn how can be know that a specific bit is 0 or 1. To Know if a bit is 0 or 1 we AND it with a AND MASK. Suppose if we want to check bit 5 of a register MYREG then the AND MASK would be 0b00100000. If we AND this value with the current value of MYREG then result will be non-zero only if the 5th bit in MYREG is ‘1’ else the result will be ‘0’.

The syntax would be like this.

if(MYREG & (1<<ENABLE))
{
	//ENABLE is '1' in MYREG
	...
}
else
{
	//ENABLE is '0' in MYREG
}

So now you know the basic operation on bits, they are widely used in firmware programming and will help you understand other codes on my web site. And Please don’t forget to post your comment regarding any doubts, or reporting errors in the above article, or simply to tell how you liked the stuff.

By
Avinash Gupta
me@avinashgupta.com

Facing problem with your embedded, electronics or robotics project? We are here to help!
Post a help request.

Avinash

Avinash Gupta is solely focused on free and high quality tutorial to make learning embedded system fun !

More Posts - Website

Follow Me:
FacebookLinkedInGoogle Plus

179 thoughts on “Programming in C – Tips for Embedded Development.

  • By AVR freak - Reply

    Nice introduction to embedded programming and registers! Maybe for beginners a little more detailed introduction to binary system and logical operations would be needed, otherwise very simple and clear.

    • By Avinash - Reply

      @AVR Freak

      Yes,a little more detailed introduction to binary system and logical operations would be needed. But I don’t wanted to go deep in C programming as I assumed user know C, so I left them. But I think I would make a new page for it.
      🙂
      Thanks for your kind suggestion!

      • By ed -

        I think it is great as it is. It is always tedious if one wants to go a bit deeper that many tutorials first hash up an introduction to the binary system again. I mean…. u are also not first teaching them English

      • By chandu -

        i want to learn about lpc2148 mc . can you tell me which books are helpful to me please

    • By vupta2 - Reply

      No, it’s perfect, more detailed will long stuff unrequiredly. It’s perfect. Abslute beginners, no C no nothing, must go to learn C then comeback.

  • By Anthony - Reply

    nice work

    • By Avinash - Reply

      @Anthony

      Thanks!!!

  • By Sandeep - Reply

    Very nice tips for Embedded C programming…Thanks a lot..

  • By Cy# - Reply

    Good job, thanks.

    Cy

  • By kiranreddy - Reply

    its good avinash.. thank u its lot useful to embedded programmers.. we wish to you produce good info like theses…

  • By shubhang - Reply

    Hi
    would like to learn AVR C programming in detail could you suggest me any site or books?

    thanks

  • By Chetan Naik - Reply

    Good Work…& Thanks…

  • By Lenin - Reply

    Good introduction, however it would be nice to point to IDEs like Micro C Pro for AVR,Micro basic pro for avr and bascom too. I found esier to deal with libraries in Micro C pro for AVR, but you know that depends on the programmer.

  • By Krishna Kumar Singh - Reply

    Thats a great see through for beginners. This shows the strength of Embedded C programming.
    And great work Mr. Avinash Gupta. Keep coming with such more stuffs in future.
    Good Luck for your futuristic scope.

    KK Singh
    BARC, Mumbai

  • By Vinod - Reply

    Very good explanation. Thanks

  • By Aditya Sharma - Reply

    Awesome… Hats off two you Mr. Avinash!!!

  • By Sachin Santhakumar - Reply

    You are are Great Avinash.
    I being from commerce line is able to understand everything. You have made it simple for me.
    Thanks a lot and please keep this up.
    People like we are dependent on people like you.

    Really Thanks a lot

  • By D Venkataraman - Reply

    Very simple and nicely explained aout setting a bit in register,clearing a bit in register and testing the status of a bit.

  • By Suhas - Reply

    Nice job.
    Keep up the good work.
    Your effort is greatly appreciated

  • By Alex - Reply

    Thank you so much for explaining this in such a clear way. I have been wondering what this notation means for ages!

  • By Businge elly - Reply

    Woow very nice and clear.i wish you could give me a very good site where i can go and learn this stuff

  • By michael - Reply

    I’m new to microcontroller programming. very helpful tutorial. Thanks a lot.

  • By anshu - Reply

    well…………… gud job… clearing basic concepts of programming….thanks keep it up

  • By Nihal - Reply

    Great start for a newcomer………….well done Mr.Avinash….KEEP IT UP!

  • By Fernando Machado - Reply

    Very nice job! Well done and free!

  • By vikram - Reply

    thanks extreme electronics. u r doing a nice work for the bignners

  • By Rabbit :P - Reply

    dude … tuts are awesome ..especially this one
    evrything is simple and sweet 😛 …continue with the same work and forgot to mention …learning a lot from all this stuff
    love your work
    cheers,
    your student in kind a way 😛
    wishing you a happy new year in advance

  • By Max - Reply

    I’ve been trying to learn i2c, SMBus, 2-wire, whatever you want to call it and have confronted code that has little documentation. TWSR. TWDR, what were they? I thought it might a secret club 🙂

    Now, Christmas Eve, you’ve just given a much cherished present to a stranger. THANK YOU! I look forward to diving back into i2c tomorrow with a fighting chance of getting it to work. I look forward to enjoying your site in the new year.

    • By Avinash - Reply

      @Max

      TWSR (Two Wire Status Register) TWDR (Two Wire Data Register) are the interface register between the TWI module and the AVR Core CPU nothing else !!!

      All peripherals have similar interface !

      Atmel datasheed gives very good documentation of the TWI module go see them

      Merry Christmas and a happy new year to all

  • By K.B. - Reply

    Great tutorial – simple, clear and quick, just what i was looking for. Thank You!

  • By suman - Reply

    thank you

  • By SATYA - Reply

    THIS TUTORIAL HAS HELPED ME IN MY UNDERGOING PROJECT.
    THANKS TO AVINASH.

  • By Norm - Reply

    Hi Avinash,

    To clear a bit, could i not just write:

    MYREG =(0<<ENABLE); //?????

    What are the differences/advantages of the method you described?

  • By burhan - Reply

    hi Avi,
    Great tutorial, as i am fresher in embedded programming, i carefully understand what you explain in your tutorial. thanks alot

  • By Jibu - Reply

    Nice tutorial

  • By sudarshan - Reply

    sir,
    I own a website http://www.superrobot.net.ms .I want to publish some of the contents found in your website in mine along with a link to your website.can i do it or not
    thank you

    • By Avinash - Reply

      @Sudarshan

      Direct Copying is NOT allowed. Please give links in place of DIRECT Copy. No use of publishing same contents at another place.

  • By chandan - Reply

    thanks a lot sir it helped a lot to understand the logic

  • By Dominic - Reply

    Thank you a lot it really helped me to catch up with the classes!!!!

  • By sanjay kumar singh - Reply

    thanks a lot sir, you have done a splendid job for a beginner like me…

  • By varun - Reply

    thanks a lot …. nice work done…

  • By varun amrita - Reply

    Good work….! Nice explanation regarding the basics..

  • By shoeb - Reply

    @Norm:

    [
    To clear a bit, could i not just write:
    MYREG =(0<<ENABLE); //?????
    ]

    It will not work

  • By Dennis Meade - Reply

    In general, all your tutorials are great. They are especially so for me. I’m a beginner as far as embedded electronics goes, so these tutorials are very useful to me.

    Any chance you will start selling your boards in the US or Canada? I would love to see them at robotshop.com.

    Dennis

    • By Avinash - Reply

      @Dennis

      Thanks!

  • By Sandro Benigno - Reply

    Thanks Avinash! Your tutorials are very well constructed. This site is my favorite place for learning about AVR programming.

  • By imran - Reply

    hi and hello avinash sir ,ur informations are very useful for me thank u very much for ur hard work ,i am a begginer for this embedded world ,i have pic, atmel proggramers but i dnt know how to start my embedded studies and proggram the microcontrollers but i know electronic hardware working pcb designing etc plz guide me to shine in this field from where i should be started ,

  • By suneel kumar - Reply

    good job….all d best

  • By sam - Reply

    a very good explanation, cleared a lot of doubts
    thanks 😀
    keep up the good work

  • By manipal - Reply

    very informative

  • By lokesh kumar k @ nitk - Reply

    nice work avinash,

  • By lokesh kumar k @ nitk - Reply

    thanks a lot.

  • By amit - Reply

    Thanks Dude :), i was searching for such type of article from many days

  • By DVRK Rao - Reply

    Very lucid tutorial.

  • By abhishek - Reply

    i got good knowledge by this article…..

  • Pingback: Interfacing Ultrasonic Rangefinder with AVR MCUs | eXtreme Electronics

  • By GyaanSeeker - Reply

    Its Really nice job since last 1yr I was looking for this stuff. It is having much more information for bit manipulation and it is required for every program. Even there are alternative to this bus mostly preferred and standard one is what you have explained.
    Its our tradition to thanks, one who gives us knowledge.
    so accept my nod(Pranaam)……….Guruji……
    where could get stuff for function pointer?

    • By Avinash - Reply

      @GyaanSeeker

      where could get stuff for function pointer?

      in a C text book! (What a hideout even Gyaan Seeker can’t Find it!)

  • By Manpreet - Reply

    Thanks Avinash…it will give me a gud start in programming….thanks for explaining it in a perfect way…..cheers!!!!!

  • By thanga bala - Reply

    sir, i got a very good knowledge in bit manupulation………
    explanation is nice sir
    thank you sir………

  • By pari - Reply

    GREAT WORK!!! THAT WAS SO SIMPLE AND CLEAR! REALLY HELPFUL!
    THANK YOU AVINASH.

  • By gun brown - Reply

    Thanks Avinash.
    I very like about your article that make beginner like me understand the basic.

  • By karthik ceg - Reply

    Excellent stuff from you. Great work!!!! Concepts are crystal clear

  • By Anbu Ali - Reply

    Excellent for a beginner…cant’ be better.

  • By Jorge Gonzalez - Reply

    Excellent!!! Just thanks! =)

  • By shoeb - Reply

    Very helpful tutorial. Concept is clear to clear and set a specific bit. How can toggle a specific bit?

    • By abc - Reply

      @Shoeb You can use xor operation to toggle a bit.

  • By Alok - Reply

    GREAT GREAT GREAT!!!!

  • By avr noob - Reply

    Awesome tutorials…Hats off to you Gupta Ji…

  • By Eeshaanee - Reply

    Awesome Tutorials….!!
    we were looking for this for so long and we finally get a detailed sensible level explanation..!
    Please introduce some keywords so that people find it easily on the google…!!
    we had much trouble..

  • By N Chandra Sekhar - Reply

    It’s really simple and good and very useful for beginners

  • By Srinivas - Reply

    Lucid explanation especially regarding setting and resetting of bits. Such explanation cannot be found in books and the reason given was very good

  • By kamalb008 - Reply

    hi..,
    Avinash sir,
    ur tutorial increases curiosity to learn mcu programming.
    NICE WORK..:D

    SIR..
    In b/w your tutorial you said DATA SHEET of a mcu…from data sheet what all the information that we need to gather for better programming mcu..??

  • By Seffin - Reply

    Thank you sir… it’s very help me… 🙂

  • By Manivannan - Reply

    Really thanks for your good explanation of this part. i need some more information after this can you do?

  • By krishna kanth - Reply

    great stuff…very clear and straight explanation….i really loved the last part of blog( testing status of bit)…..keep going..

  • By rajan - Reply

    hi Avinash..

    i have no words to say about this article..no one can be explain like this..hats of to you..am very proud to be say this..keep it up

  • By itaci - Reply

    good…. akhirnya aku tahu setelah rasa penasaran yang panjang…. thanks

  • By AMRIT - Reply

    great work…

    z really helpful for a begginer..

    • By Megha - Reply

      oh yea indeed… Dis site is helpful
      :p

  • By subhra - Reply

    ya i agree wid Amrit ……its cool n gud…
    btw amrit i didnt know dat u wer a geek n dats supercool
    it matches wid ur image

  • By subhra - Reply

    ya i agree wid amrit too … its cool n good…
    btw amrit i didnt know dat u are a geek n dats supercool
    superb dude

    • By SANDIP BARMAN - Reply

      THE DATA IS TOO GOOD BUT
      @SUBHRA AMRIT IS A BEGINNER BUT I AM COOL N A PRO IN ELECTRONICS..
      THANKS TO EXTREME ELECTRONICS ITS SUPERCOOL…

  • By QWERT - Reply

    wow…

  • By Nisarg - Reply

    nice i learnt good from it.thanks buddy

  • By Nidhi - Reply

    It is very good and helpful for beginners like me. Thanks a lot!!

  • By Jose Antony - Reply

    very very good tutorial—thx lot–

  • By rakesh kumar - Reply

    Thank u sir,

    Way u have given it’s very interactive and making interest to learn..

    Sir its a request kindly suggest how to read the datasheet while coding for microcontroller as software engineer what are the things we need to take care because sir if we go through the entire datasheet it is very very confusing sir please suggest …..wating for ur reply sir ……..

    With regards
    rakesh Kumar

    • By Pranav - Reply

      Just download the full datasheet from the manufacturer. Keep it for future reference. Whenever you feel stuck, just search for what you are trying to do in the datasheet. Most of the times it would be given clearly in steps.

  • By esi - Reply

    very nice

  • By Akshay Iyer - Reply

    dat was really nice of u 2 hav explained d basic stuff so perfectly, u get it fixed in ur heads in d second reading itself. 🙂

  • By Abhinav - Reply

    Excellent stuff.

  • By vishnu - Reply

    awesome…………

  • By Rupesh - Reply

    Great, this stuff help me in my project .
    Thank lots

  • By dj - Reply

    thnkx… It d best concept i evr read..

  • By amrit - Reply

    great for a beginner…….
    keep it up…..

  • By savindra kumar - Reply

    printf(“really helpful ,like it “);

  • By Sankaran K - Reply

    THANKS…..

  • By krishna - Reply

    Thanks for your good explanation.

  • By sayantan - Reply

    REally nice….thanks a lot

  • By john kabbi - Reply

    pure awesomeness !

  • By Abhinay Chaudhary - Reply

    awesome…

  • By Andrzej - Reply

    Super – your skills of explaining things are excellent. Maybe you will try to write a book. It’s really amazingly simple and easy-to-understand explanation. Thank you very much.
    Andrzej,

  • By Abhi - Reply

    Thanks,_it’s_easy_to_understand.
    Can_you_give_me_tips_on_atmega64_register
    (c_programming)

  • By Subhankar - Reply

    Thanks for your simple and lucid explaination about the C programming.Very easy for the beginner like me to understand.but one request from my side.can u please give some more guidelines about the C language which will enable person like me to write codes independently for any project made by me.I mean some more basic things that you would like to add regarding hardware coding.please sir.
    Thanks.:)

  • By Vaishak - Reply

    Helped me a lot in understanding the basics of avr c programming.

  • By Ravindra - Reply

    fentastic work….

  • By sudesh - Reply

    grt wrk…

  • By RONAK - Reply

    Nicely explained the basics of registers…..!!
    kudos ..

  • By Frank - Reply

    Thank you Avinash for the great intro article…i am a BEGINNER,i really need anyone who knows what a good pratical tutorila for Embedded C beginner??or any resources where you can learn industrial Embedded C??Thank you Friends..:)

  • By edigo - Reply

    thank you very much, it’s very clear and understable,.

  • By tushar - Reply

    Very much helped and cleared doubts…

  • By ranjit kumar - Reply

    a real awesome work done.
    thanks a lot.

  • By chintan pathak - Reply

    A very well-illustrated article.

    It was easy for me, a novice to understand.

    Maybe if you would provide references for your statements and further readings, that could make the tutorial more effective.

  • By AbdulRahman - Reply

    Realy, it was a very helpful tutorial.

    Thanks a lot

  • By saeed qureshi - Reply

    Thanks for guiding me

  • By Jayashan Costa - Reply

    Hi Avinash!
    Thank you very much for making all these tutorials. its very great of you.. cheers!
    Jayashan from Sri Lanka

  • By Naveen - Reply

    Great work done, I am basically a Embedded Hardware designer,so this tutorial was a good guide for me in understanding some basics of embedded C…

  • By roopa g - Reply

    HI, myself rupa, i am working on a DSP controller
    am i unable to convert a floating point to fixed point
    Please send me C codes for floating point which would help my project.

  • By Star Wars - Reply

    Thank You very much. This is a very good start for me.

  • By Sava Jeli? - Reply

    Very instructive. Thank You.

  • By Basu - Reply

    Great Work I have been searching for this type of tutor,

    Its really helpful ..
    Thanks a lot !!!!!!
    Keep it up!!

  • By priya dixit - Reply

    sir pls could you provide me with the code of avr microcontrollers used for rotating the rod (via dc motors) in one direction for 30 seconds and then again rotating it in opposite direction for 30 seconds
    thank you

    • By Avinash - Reply

      @Priya,

      Why don’t you make it your self? What is the problem?

      • By priya dixit -

        i would love to do that but am a beginner having no idea about programming in past i had referred some books and asked many faculties about my problems regarding the same but everything seems fruitless now..

      • By Avinash -

        @Priya,

        So if you are in this field then I better suggest you learn programming as it will come to your use in the future. So what is your experience level in C? How much do you know?

  • By priya dixit - Reply

    sir i have read your tutorials on avr they are really helpful though it took some time to understand each and everything but finally i was able to understand most of it and it would have been a more enriching experience if the pdf versions for all the tutorials are available anyways i enjoyed the parts i had read thank you for replying and all the wonderful tutorials

    • By Avinash - Reply

      Thank you !

    • By Avinash - Reply

      I tried to make PDFs in the beginning but the problem was that web article were constantly updated with new information and corrections made. And PDFs soon became obsolete. Thats why I dropped the idea.

  • By priya dixit - Reply

    thank you sir once again for replying
    i am familiar with the basic concepts of c(C++)
    but its my bad luck i couldn’t find any such tutorials of c like these avr tutorials of yours 🙂

    • By Avinash - Reply

      @Priya,

      To complete what you are trying to make you need the following info:-

      Basic details of AVR Studio 6 it is explained here
      https://extremeelectronics.co.in/lfrm8/Help/AS6.htm

      Then you need the basic info about i/o ports
      https://extremeelectronics.co.in/avr-tutorials/part-v-digital-io-in-avrs/

      Finally you need info about DC motor control for that you can refer to
      https://extremeelectronics.co.in/avr-tutorials/dc-motor-control/

      After reading all those I think you can easily implement the solution 🙂

      How much experience you have working with AVRs? Do you have some setup to do the experiment?

      • By priya dixit -

        thank you sir
        these links were helpful…
        i have all the basic knowledge of working with AVRs given in your tutorials..and had bought usb avr programmer, avr development board and atmega 16 microcontroller
        i and one of my friend( pursuing mechanical engineering) are trying to develop a book scanner for which i needed
        the programming code for rotating the rod (as mentioned earlier) the whole setup of the book scanner is as follows-
        we have 2 rods at right angle to each other(say one along the x axis and another one along the y axis) the rod along the y axis rotates 60 degree clockwise(cw) and anticlockwise(acw) direction with time delay of 10 seconds as the rod rotates cw and acw the glass panel(which is moulded in the shape of an open book) attached to the rod along the x axis moves up and down….now moving the rod in 60 degree cw for 10 seconds then moving it acw is the 1st mechanism we need to build…nextly we need some automatic setup to turn the pages of the books which are to be scanned (since as the glass panel moves up there is a provision to turn the pages manually or through some automatic setup so that the further pages can be scanned)this automatic setup for turning the pages is the 2nd mechanism we need to build..third we need an speed regulator to make the rod move slow and fast as and when needed..
        i request you if you could help us out in this..thank you once again and sorry for replying so late..

    • By Avinash - Reply

      @Priya,

      Okay, I will have a look at your description when I have some free time.

  • By Steve in Colorado - Reply

    This is probably the best bit shifting tutorial I have read. I have a much clearer idea now. I wish I had read this a month ago then I could have stopped pulling my hair out.

    • By Avinash - Reply

      @Steve

      Thanks!

  • By priya dixit - Reply

    thank you sir

  • By Basu - Reply

    Nice info.!! thanks a lot sir…

  • By Bala jeyanthi - Reply

    I want to know about the embedded C program codings. please send me sir

  • By Prasad - Reply

    As noticed tutorial quite complete the knowledge of any basic learner of Embeded System…

  • Pingback: Microcontroller Programming in C Language Tutorial | Building Robotics News

  • By sadasiba - Reply

    hii,
    i am sadasiba, i am highly interested in embedded c but i am not so strong in coding
    now i am learning embedded c, i have a question that no one is getting able to answer it or some of did not want to answer it, whom i asked yet
    and i could not leave that question out of my mind and the question is”why there is no match between hex code generated after compiling and the previous original c code,if i am taking the ASCII equivalent of both charter used in c code and hex code generated” .is there any fact regarding compiler designing?.please kindly give a reply i am waiting for your reply.

  • By waleed - Reply

    loved da way u thaught

  • By chintesh - Reply

    nice explanation

  • By Anmol Gulati - Reply

    Thanks alot sir ,that was really helpful

  • By Pawan - Reply

    Hey Avinash,

    Your tutorial turned out to be silver lining for me when I was in a confused state. I was browsing a lot to clear my doubts. I don’t know how I landed at your site but it cleared tons of my doubts and made me regain my lost interest in embedded systems. Thanks a ton for bringing up such wonderful tutorials.

  • By Mukta Sinha - Reply

    Nice explanation.

    Please send some notes on embedded C.

    Thanks.

  • By Nagaraj.T - Reply

    Sir i want to study more about Embedded c please guide me this stuff was very sourcefull and i am very thankfull to you

  • By Kishan - Reply

    Thank u very much !!! nice explanation !!

  • By Dixit - Reply

    really nice explanation….helpful to begginer…and i really appritiate you because u are not motivated by money for this stuff..

  • By Madhan - Reply

    HI,
    really nice explanation.i can easily understand.please give me a whole embedded system notes or links,like that …..please

  • By Gaci - Reply

    very good job yo!

  • By yashvardhan - Reply

    very nice tutorial buddy….keep it up (y)

  • By Akshay - Reply

    Thank you sir….!
    your artical will be helpfull for me…

    but, can you explain more about HEX….
    i am very unfamiliar with this word yet…

    plz reply me by mail….

  • By Mahmoud Elkhateeb - Reply

    Great tutorial and very heedful, thanks a lot

    BTW: I was asked questions that its answers are you article in two different job interviews.

  • By Selamawit - Reply

    gr8 introduction thanks!

  • By Andras - Reply

    Thanks a lot!

    It was really helpful!

  • By Fahim - Reply

    Dear Sir Avinash,
    Do you have a book written on “Microcontrollers” or “Embedded Programming”. Please give us details of your books. Thanks.

    • By Avinash - Reply

      @Fahim

      Sorry I have not 🙁

  • By imtiaz - Reply

    thanks a lot……….i was trying to understand that over 2 days.at last i found it here .thank you so much…………..

  • By Guru - Reply

    Very good and useful

    • By Avinash - Reply

      @Guru, thank you.

  • By rahul - Reply

    can we use a single micro controller board to program many ic s?

  • By vknr - Reply

    Thanks a lot,Excellent tutorial for setting, clearing a bit in register,got cleared why left Shift is used for setting a bit and why we can’t directly copy the value to register.
    you can write a Ebook on AVR Programming in C.

  • By manikanta - Reply

    Hi Avinash Gupta,

    I am new to embedded coding and I want to know how to set and read peripherals like I/0 ports , timers etc in c, do have any material means plz share me

    reply me by mail.

  • By shivkumar - Reply

    thank u very much sir….

  • By Taofeek - Reply

    I really appreciate your support to all beginners in Embedded C programming…..I have learnt a great deal. I
    will keep reading to learn more. Thanks a lot.

    • By Avinash - Reply

      @Taofeek,

      Thank you 🙂 I am pleased to know they are helpful!

  • By ritesh chaurasia - Reply

    thanx a lot,it’s exactly the article that I was searching for.It cleared all my doubts regarding setting of bits by << operator in embedded c,a very simple and to the point article

  • By siva c - Reply

    sir i have to learn a lot in electronics what should i do sir help me

  • By Manjeet Singh - Reply

    what are bit wise operator and how they are used in embedded c?

    • By Avinash - Reply

      @Manjeet Singh, purchase a book in C.

  • By saeb - Reply

    It was great & helpful.
    thanks

  • By Achi - Reply

    really helpful man… thanx…

    • By Avinash - Reply

      @Achi,

      Welcome

  • By Abhishek - Reply

    Great piece of information for beginners in Embedded world. Thanks!!

  • By tuyen - Reply

    it really helpful
    thanks

  • By Prasanna - Reply

    It’s really helpful to me thank you sir

  • By adil - Reply

    hi avinash long time remeber wud7elecs@gmail.com
    here ihave mix varible types of math:
    int pulse=0;
    #define sw portd.rd0
    void main(){
    trisc=0x00;
    portc=0;
    trisd.f0=1;
    if(sw==1)
    while(sw==1);
    pulse++;
    }
    if(pulse>=500)pulse=0;
    if(rd0_bit==1)pulse++;
    if(pulse==pulse=52){
    while(pulse==52);
    pulse=pulse *(52/60);
    pulse=0.8666667;
    }
    if(pulse>=0.8666667&&pulse<=125){
    portc.f4=1;
    }
    help me which is wrong ineed speed until become 52/60 then do something
    pulse=pulse *(52/60);
    pulse=0.8666667;

Leave a Reply

Your email address will not be published. Required fields are marked *


− 3 = one

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>