mcu note

Embed Size (px)

Citation preview

  • 7/31/2019 mcu note

    1/70

    Read Modify Write ProblemPIC Specifics >

    LED blinking program for Pic microcontrollerHere is the program for Pic microcontroller PIC16F877Ato blink a LED connected to B3 of PORTC,

    This program works for Mplab. or using HiTECH PRO Lite compiler.

    PICClite code may be

    #include#include "delay.h"#define _XTAL_FREQ 4000000

    _CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);

    void main()

    {TRISC=0;while (1){PORTC = 8;DelayMs(250);DelayMs(250);PORTC = 0;DelayMs(250);DelayMs(250);

    }

    }

    in PIC_Clite , "delay.h" has to be included because its MACRO, but in PRO its inbuilt

    #include#define _XTAL_FREQ 4000000

    _CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);

    void main()

    {TRISC=0;while (1){PORTC = 8;

    __delay_ms(100);_delay_ms(100); // use this delay to test the code __delay_ms(100);_delay_ms(100);

    http://jntuimplab.blogspot.com/2010/02/led-blinking-program-for-pic.htmlhttp://jntuimplab.blogspot.com/2010/02/led-blinking-program-for-pic.html
  • 7/31/2019 mcu note

    2/70

    PORTC = 0; __delay_ms(100);_delay_ms(100); __delay_ms(100);_delay_ms(100);}

    }i didnt use _delay(100000); because whn Xtal Freq is high(20Mz) the delay changes & you will not beable to see the LEDs blinking. ensure that watchdog timer is disabled in _CONFIG, hope it works..

    A microprocessor Program to convert BCD pack and Unpack number for8085.Please find the Below program to Pack the two unpacked BCD numbers stored in memory locations4200H and 4201H and store result in memory location 4300H. Assume the least significant digit is storedat 4200H.

    Here is the Sample problem:(4200H) = 04(4201H) = 09

    Result = (4300H) = 94

    Source program for the above logic

    LDA 4201H : Get the Most significant BCD digitRLCRLCRLCRLC : Adjust the position of the second digit (09 is changed to 90)ANI FOH : Make least significant BCD digit zeroMOV C, A : store the partial resultLDA 4200H : Get the lower BCD digitADD C : Add lower BCD digitSTA 4300H : Store the resultHLT : Terminate program execution

    0 comments

    http://jntuimplab.blogspot.com/2010/02/microprocessor-program-to-convert-bcd.htmlhttp://jntuimplab.blogspot.com/2010/02/microprocessor-program-to-convert-bcd.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6988274256548042187http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6988274256548042187http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=6988274256548042187http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6988274256548042187http://jntuimplab.blogspot.com/2010/02/microprocessor-program-to-convert-bcd.htmlhttp://jntuimplab.blogspot.com/2010/02/microprocessor-program-to-convert-bcd.html
  • 7/31/2019 mcu note

    3/70

  • 7/31/2019 mcu note

    4/70

    CODE:

    MOV SI,2000MOV CX,0000

    MOV CL,[SI]MOV AX,0000MOV BX,00INC SIMOV [SI], ALDEC CXINC SIMOV [SI],BLDEC CXAGAIN ADD AL,BLMOV [SI+01],AL

    MOV BL,[SI]INC SILOOP AGAININT A5

    ----code ends

    2 comments

    Labels: Assembly Language , fibonacci series , Program

    D E C 2 , 2 0 0 8

    program to find the product of numbers in an arrayThis program is to find the product of numbers in an array:

    We initalize the registers, then we move the size of the array to a counter and reduce its size bu one.SI is incremented to point to the 1st number of the array and move the 1st number into accumularot.

    The 2nd number is moved into BL,, we multiply both the numbers abd this is continued till the numbersin the list, exhaust and finally the result is stored in AX.

    Code:

    MOV SI, 2000MOV DI,4000MOV AX,OMOV BX,0MOV CX,0

    http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=586946364633987238http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=586946364633987238http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/fibonacci%20serieshttp://jntuimplab.blogspot.com/search/label/fibonacci%20serieshttp://jntuimplab.blogspot.com/search/label/fibonacci%20serieshttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/2008/12/program-to-find-product-of-numbers-in.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=586946364633987238http://jntuimplab.blogspot.com/2008/12/program-to-find-product-of-numbers-in.htmlhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/fibonacci%20serieshttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=586946364633987238
  • 7/31/2019 mcu note

    5/70

    MOV CL,[SI]SUB CL,[SI]INC SIMOV AL,[SI]AGAIN: INC SI

    MOV BL, [SI]MUL BLLOOP AGAINMOV [DI],AXINT A5

    Thus the program for product of numbers in an array can be executed using the above code.

    0 comments

    Labels: array , Assembly Language , product of numbers

    N O V 2 8 , 2 0 0 8

    Assembly program for a real time clockFollowing is the Assembly language program for a real time clock

    Code:

    LCALL 061DAGAIN MOV DPTR, #2845REPEAT DEC82 ; Decrement DPL

    MOVX A,@DPTRMOV R3,AMOV R5,#02LCALL 059EMOV A,20LCALL 2006MOVA,82CJNE A,#42; REPEAT (ED)MOVA,#OD ; OD = ASCII FOR ENTERLCALL 2006LJMP; AGAIN ( 6003 )

    To change the RTC

    2844-hrs2843-minutes2842-seconds

    0 comments

    http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6512930863595148130http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6512930863595148130http://jntuimplab.blogspot.com/search/label/arrayhttp://jntuimplab.blogspot.com/search/label/arrayhttp://jntuimplab.blogspot.com/search/label/arrayhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/product%20of%20numbershttp://jntuimplab.blogspot.com/search/label/product%20of%20numbershttp://jntuimplab.blogspot.com/search/label/product%20of%20numbershttp://jntuimplab.blogspot.com/2008/11/assembly-program-for-real-time-clock.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=4382393414261145733http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=4382393414261145733http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=4382393414261145733http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=6512930863595148130http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=4382393414261145733http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=6512930863595148130http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=4382393414261145733http://jntuimplab.blogspot.com/2008/11/assembly-program-for-real-time-clock.htmlhttp://jntuimplab.blogspot.com/search/label/product%20of%20numbershttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/arrayhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6512930863595148130
  • 7/31/2019 mcu note

    6/70

    Labels: 8086 , Assembly Language , c program , real time clock

    O C T 2 4 , 2 0 0 8

    Program to interface DAC using 8255 and generate ramp waveform

    Program to interface DAC using 8255 and generate ramp waveform

    The following is the assembly language using DAC to interface with 8255 and generate a ramp on CRO.Here in the code, we use two jump instructions JMP and JZ in order to form the ramp wave. The jumpinstructions used in the program are iterated to repeat cycles of a ramp wave.

    Code:

    MOV DX,8807 : DX is loaded with control word register address of 8255MOV AL,80OUT DX,AL : Contents of AL are transferred to portA of 8255

    MOV DX,8801 : DX is loaded with Port A address of 8255Ramp MOV AL,00Begin OUT DX,AL ; Contents of AL are transferred to portA of 8255INC ALCMP AL,FFJZ RampJMP Begin ; Repeat the same

    Thus we programed in assembly language to interface DAC using 8255 to generate a ramp wave.

    Related links Ebooks for micro processors and micro controllers

    0 comments

    Labels: 8255 , Assembly Language , ramp , waveform generation

    O C T 2 1 , 2 0 0 8

    Program to interface DAC using 8255 and generate square waveform

    http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/c%20programhttp://jntuimplab.blogspot.com/search/label/c%20programhttp://jntuimplab.blogspot.com/search/label/c%20programhttp://jntuimplab.blogspot.com/search/label/real%20time%20clockhttp://jntuimplab.blogspot.com/search/label/real%20time%20clockhttp://jntuimplab.blogspot.com/search/label/real%20time%20clockhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-dac-using-8255-and_24.htmlhttp://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6279374798341916124http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6279374798341916124http://jntuimplab.blogspot.com/search/label/8255http://jntuimplab.blogspot.com/search/label/8255http://jntuimplab.blogspot.com/search/label/8255http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/ramphttp://jntuimplab.blogspot.com/search/label/ramphttp://jntuimplab.blogspot.com/search/label/ramphttp://jntuimplab.blogspot.com/search/label/waveform%20generationhttp://jntuimplab.blogspot.com/search/label/waveform%20generationhttp://jntuimplab.blogspot.com/search/label/waveform%20generationhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-dac-using-8255-and.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=6279374798341916124http://jntuimplab.blogspot.com/2008/10/program-to-interface-dac-using-8255-and.htmlhttp://jntuimplab.blogspot.com/search/label/waveform%20generationhttp://jntuimplab.blogspot.com/search/label/ramphttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8255http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6279374798341916124http://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-dac-using-8255-and_24.htmlhttp://jntuimplab.blogspot.com/search/label/real%20time%20clockhttp://jntuimplab.blogspot.com/search/label/c%20programhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086
  • 7/31/2019 mcu note

    7/70

    Program to interface DAC using 8255 and generate square waveform

    The following is the assembly language using DAC to interface with 8255 and generate a square waveon CRO. Here in the code, we use two delay elements one for the rising part of the wave and the otherdelay element to reach zero i.e decrement. Certain value chosen is delayed or sustained for a timeperiod to form the square wave. The two loops used in the program are iterated to repeat cycles of asquare wave.

    Code:

    MOV DX,8807 : DX is loaded with control word register address of 8255MOV AL,80OUT DX,AL : Contents of AL are transferred to portA of 8255MOV DX,8801 : DX is loaded with Port A address of 8255Begin MOV AL,00OUT DX,AL ; Contents of AL are transferred to portA of 8255MOV CX,00FFDelay1 Loop Delay1MOV AL,FFOUT DX,AL : Contents of AL are transferred to portA of 8255MOV CX,00FF : CX is loaded with 00FFHDelay2 Loop Delay2 : Repeat until CX=0

    JMP Begin ; Repeat the same

    The expected square wave can be observed as in the figure shown. Thus we programed in assemblylanguage to interface DAC using 8255 to generate a square waveform.

    Related links Ebooks for micro processors and micro controllers

    http://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://1.bp.blogspot.com/_cdJYq16p3_g/SP3qzao8kGI/AAAAAAAAANo/DlPPqVG6Nd4/s1600-h/SquareWave.jpghttp://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.html
  • 7/31/2019 mcu note

    8/70

    0 comments

    Labels: 8086 , 8255 , Assembly Language , generate square waveform , square wave

    Assembly language program to find square root of 8-bit numberFollowing is the assembly language program to find square root of 8-bit number.In this program we initially load the index registers with specified values. We load the value of thenumber into SI Register. Then using a few logical steps as mentioned in the code i.e JMP insctructionswe find the square root of a 8-bit number.

    Code:MOV SI,2000MOV DI,4000MOV CX,0001MOV BX,0000MOV AL,[SI] ; Load AL with the value given as at SIUP SUB AL,CLJL down ; jump to down labelINC BLADD CL,02 ; add 2 to contents of CL registerJMP UP ; jump to up labelDOWN MOV[DI],BLINT A5

    Thus by implementing the above code we can find the square root of 8-bit number

    Related posts square root of hexa decimal number Ebooks

    You might be also interested in:

    :: Find Square Root of a hexadecimal number in assembly language :: common intreview questions on 8086 :: Assembly Language Source Codes

    1 comments

    Labels: 8086 , Assembly Language , square root

    O C T 1 5 , 2 0 0 8

    Program to interface stepper motor with 8086 and rotate with anti clockwise direction in full stepping

    http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=1196352619714349631http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=1196352619714349631http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8255http://jntuimplab.blogspot.com/search/label/8255http://jntuimplab.blogspot.com/search/label/8255http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/generate%20square%20waveformhttp://jntuimplab.blogspot.com/search/label/generate%20square%20waveformhttp://jntuimplab.blogspot.com/search/label/square%20wavehttp://jntuimplab.blogspot.com/search/label/square%20wavehttp://jntuimplab.blogspot.com/search/label/square%20wavehttp://jntuimplab.blogspot.com/2008/10/assembly-language-program-to-find.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=7457389787386407784http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=7457389787386407784http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/square%20roothttp://jntuimplab.blogspot.com/search/label/square%20roothttp://jntuimplab.blogspot.com/search/label/square%20roothttp://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=7457389787386407784http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=1196352619714349631http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=7457389787386407784http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=1196352619714349631http://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://jntuimplab.blogspot.com/search/label/square%20roothttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=7457389787386407784http://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/09/ebooks-on-microprocessors-and.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/10/assembly-language-program-to-find.htmlhttp://jntuimplab.blogspot.com/search/label/square%20wavehttp://jntuimplab.blogspot.com/search/label/generate%20square%20waveformhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8255http://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=1196352619714349631
  • 7/31/2019 mcu note

    9/70

    The following program is to interface stepper motor with 8086 and rotate with anti clock wise directionin full stepping. The purpose of this is to observe and control the stepping action of the motor usingassembly language code. The code is also practically illustrated with two live demonstrations on howspeed of the motor varies if one of the instruction codes is changed to a new value.

    Code:

    MOV DX,8807 : Load DX with control word register address of 8255MOV AL,80 : load control word 80 into ALOUT DX,AL: Contents of AL are loaded into control word register of 8255MOV DX,8801: Load PortA address of 8255 into DXMOV AL,33: Load value 33 into ALAgain OUT DX,AL: Contents of AL are loaded into control word register of 8255MOV CX,0100: set counter to delayLoop AgainROL AL,1 : Rotate left by 1

    JMP Again : Unconditional jump to label again

    Following is the practical illsutration of the output for the above given code.

    The instruction MOV CX,0100 can be changed to a new value in order to vary the speed.So, for instance lets say MOV CX,7000. Following is the video demonstration of how the speed varies if the value is changed in the above instruction

    Thus by changing the instruction the speed of the stepper motor can be varied according withinterfacing it to an 8086 microprocessor for full stepping

    Related posts:Interfacing a stepper motor with an AVR Microprocessor

    Interfacing a stepper motor with pic micro controller

    Interfacing a stepper motor to 8086 using 8255

    0 comments

    Labels: 8086 , Assembly Language , interface stepper motor

    S E P 2 8 , 2 0 0 8

    program to find factorial of given numbersfollowing is the assembly language program to find factorial of given numbers

    http://jntuimplab.blogspot.com/2008/09/driving-stepper-motor-with-avr.htmlhttp://jntuimplab.blogspot.com/2008/09/driving-stepper-motor-with-avr.htmlhttp://jntuimplab.blogspot.com/2008/07/interfacing-stepper-motor-with-pic.htmlhttp://jntuimplab.blogspot.com/2008/07/interfacing-stepper-motor-with-pic.htmlhttp://jntuimplab.blogspot.com/2008/07/interfacing-stepper-motor-with-pic.htmlhttp://jntuimplab.blogspot.com/2008/07/interfacing-stepper-motor-with-pic.htmlhttp://jntuimplab.blogspot.com/2008/01/interfacing-stepper-motor-to-8086-using.htmlhttp://jntuimplab.blogspot.com/2008/01/interfacing-stepper-motor-to-8086-using.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=884898271608359413http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=884898271608359413http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/interface%20stepper%20motorhttp://jntuimplab.blogspot.com/search/label/interface%20stepper%20motorhttp://jntuimplab.blogspot.com/search/label/interface%20stepper%20motorhttp://jntuimplab.blogspot.com/2008/09/program-to-find-factorial-of-given_28.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=884898271608359413http://jntuimplab.blogspot.com/2008/09/program-to-find-factorial-of-given_28.htmlhttp://jntuimplab.blogspot.com/search/label/interface%20stepper%20motorhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=884898271608359413http://jntuimplab.blogspot.com/2008/01/interfacing-stepper-motor-to-8086-using.htmlhttp://jntuimplab.blogspot.com/2008/07/interfacing-stepper-motor-with-pic.htmlhttp://jntuimplab.blogspot.com/2008/07/interfacing-stepper-motor-with-pic.htmlhttp://jntuimplab.blogspot.com/2008/09/driving-stepper-motor-with-avr.html
  • 7/31/2019 mcu note

    10/70

    MOV SI , 2000MOV DI,2002MOV CX,[SI]MOV AX,CX ; Move contents of CX to contents of AX registerDEC CX ; Decrement CX

    UP: MUL CXDEC CX ; Decrement CXJNZ; UP ; Jump if not zeroMOV [DI], AX ; Load the values of AX into location given by DIINT A5; Halt the program

    You might be also interested in:

    :: Troubleshooting a simple 8086 microprocessor based microcomputer :: centigrade (celsius) to fahrenheit calculation for 8086 Assembly Language :: Data transfer instructions of 8086 microprocessor

    0 comments

    Labels: 8086 , Assembly Language , factorial

    S E P 2 6 , 2 0 0 8

    Program to find arithmetic mean of n numbersProgram to find arithmetic mean of n numbers

    CLC ; clear carry flagMOV SI , 2000MOV DI, 2050MOV CX, 0000 ; Load CX register with the value given by 0000MOV AX,0000MOV CL,[SI]MOV DL,CLA1: INC SI ; Increment SI contentsADD AL,[SI] ; ADD AL with the value given by that at SI and store in ALLOOP AI ( 1011) ; Repeat until CX=0DIV BL; Divide AX With the value given by BLMOV [DI],AX ; Load the value in AX into as location at DIINT A5 ; HALT

    Thus with the above code the arithmetic mean of n numbers can found accordingly.

    sample input: 0000:2000 array size0000:20001 array elements

    http://jntuimplab.blogspot.com/2008/03/troubleshooting-simple-8086.htmlhttp://jntuimplab.blogspot.com/2008/03/troubleshooting-simple-8086.htmlhttp://jntuimplab.blogspot.com/2008/03/troubleshooting-simple-8086.htmlhttp://jntuimplab.blogspot.com/2008/03/centigrade-celsius-to-fahrenheit.htmlhttp://jntuimplab.blogspot.com/2008/03/centigrade-celsius-to-fahrenheit.htmlhttp://jntuimplab.blogspot.com/2008/03/centigrade-celsius-to-fahrenheit.htmlhttp://jntuimplab.blogspot.com/2008/04/data-transfer-instructions-of-8086.htmlhttp://jntuimplab.blogspot.com/2008/04/data-transfer-instructions-of-8086.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=66501482847322294http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=66501482847322294http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/factorialhttp://jntuimplab.blogspot.com/search/label/factorialhttp://jntuimplab.blogspot.com/search/label/factorialhttp://jntuimplab.blogspot.com/2008/09/program-to-find-arithmetic-mean-of-n.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=66501482847322294http://jntuimplab.blogspot.com/2008/09/program-to-find-arithmetic-mean-of-n.htmlhttp://jntuimplab.blogspot.com/search/label/factorialhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=66501482847322294http://jntuimplab.blogspot.com/2008/04/data-transfer-instructions-of-8086.htmlhttp://jntuimplab.blogspot.com/2008/03/centigrade-celsius-to-fahrenheit.htmlhttp://jntuimplab.blogspot.com/2008/03/troubleshooting-simple-8086.html
  • 7/31/2019 mcu note

    11/70

    from 2001 location

    Output 0000:2050 Result

    You might be also interested in:

    : :Interfacing pic microcontroller with LCD : : Serial Port interfacing with atmega :: TCP/IP on PIC 18 series

    0 comments

    Labels: 8086 , arithmetic mean , Assembly Language

    S E P 2 4 , 2 0 0 8

    assembly language program to reverse a given stringFollowing is the assembly language program to reverse a given string.

    MOV AX @ DATA ; AX IS INITIALIZED WITH DATAMOV DS AX ; AX IS MOVED INTO DSMOV CX 0005H ; CX IS INITIALIZED TO 5LEA SI A1 ; SI IS HAVING LEAD E.A OF A1LEA DI A2; DI IS HAVING LEAD E.A OF A2ADD SI 0004AGAIN: MOV AL[SI]

    MOV [DI]AL ; AL IS MOVED INTO DIDEC SIINC DILOOP AGAININT 3 ; INTERRUPTEND

    Using the above code if an Input for instance ' ad-cole': 0006 is given then the output will be shown asDS: 0011: 1610A0: 0010 : 65, 64 , 63 , 62 , 61 05 e d c b a

    You might be also interested in:

    :: Find Square Root of a hexadecimal number in assembly language :: common intreview questions on 8086 :: Assembly Language Source Codes

    0 comments

    http://jntuimplab.blogspot.com/2008/05/interfacing-pic-microcontroller-with.htmlhttp://jntuimplab.blogspot.com/2008/05/interfacing-pic-microcontroller-with.htmlhttp://jntuimplab.blogspot.com/2008/05/interfacing-pic-microcontroller-with.htmlhttp://jntuimplab.blogspot.com/2008/05/serial-port-interfacing-with-atmega.htmlhttp://jntuimplab.blogspot.com/2008/05/serial-port-interfacing-with-atmega.htmlhttp://jntuimplab.blogspot.com/2008/05/serial-port-interfacing-with-atmega.htmlhttp://jntuimplab.blogspot.com/2008/05/serial-port-interfacing-with-atmega.htmlhttp://jntuimplab.blogspot.com/2008/05/tcpip-on-pic-18-series.htmlhttp://jntuimplab.blogspot.com/2008/05/tcpip-on-pic-18-series.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=665151610180137680http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=665151610180137680http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/arithmetic%20meanhttp://jntuimplab.blogspot.com/search/label/arithmetic%20meanhttp://jntuimplab.blogspot.com/search/label/arithmetic%20meanhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/2008/09/assembly-language-program-to-reverse.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6424673010410396416http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6424673010410396416http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=6424673010410396416http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=665151610180137680http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=6424673010410396416http://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=665151610180137680http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=6424673010410396416http://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/09/assembly-language-program-to-reverse.htmlhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/arithmetic%20meanhttp://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=665151610180137680http://jntuimplab.blogspot.com/2008/05/tcpip-on-pic-18-series.htmlhttp://jntuimplab.blogspot.com/2008/05/serial-port-interfacing-with-atmega.htmlhttp://jntuimplab.blogspot.com/2008/05/interfacing-pic-microcontroller-with.html
  • 7/31/2019 mcu note

    12/70

    Labels: 8086 , Assembly Language , reverse , string

    S E P 2 3 , 2 0 0 8

    stack program for push and pop

    following is the assembly language program for push and pop operations in a stack.

    code segmentmain:mov sp,1000h initialize SP to point to stackmov ax,1234hmov bx,5678hmov cx,9abcdhpush axpush cxpop ax

    pop axpop bxpop cxmov bx,0200hmov w[bxx],1234h; address 0200 holds 1234push [0200h]push[bx]mov bx,0210hpop [bx]pop[0212h]imp main ; demo againcode ends

    This program establishes the stack at 0100h and puts some random numbers in registers AX , BX , CX.AX is pushed on the stack that stores it at SS:OFFFh(MSB) and SS:0FFEh{LSB}. BX and CX are stored insimilar manner with the attendant decrement of SP bt 2 for each push. The contents of the stack arethen popped from the stack, in reverse order.

    You might be also interested in:

    :: Find Square Root of a hexadecimal number in assembly language :: common intreview questions on 8086 :: Assembly Language Source Codes

    0 comments

    Labels: 8086 , Assembly Language , pop , push , stack

    http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/reversehttp://jntuimplab.blogspot.com/search/label/reversehttp://jntuimplab.blogspot.com/search/label/reversehttp://jntuimplab.blogspot.com/search/label/stringhttp://jntuimplab.blogspot.com/search/label/stringhttp://jntuimplab.blogspot.com/search/label/stringhttp://jntuimplab.blogspot.com/2008/09/stack-program-for-push-and-pop.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=5334713381102951307http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=5334713381102951307http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/pophttp://jntuimplab.blogspot.com/search/label/pophttp://jntuimplab.blogspot.com/search/label/pophttp://jntuimplab.blogspot.com/search/label/pushhttp://jntuimplab.blogspot.com/search/label/pushhttp://jntuimplab.blogspot.com/search/label/pushhttp://jntuimplab.blogspot.com/search/label/stackhttp://jntuimplab.blogspot.com/search/label/stackhttp://jntuimplab.blogspot.com/search/label/stackhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=5334713381102951307http://jntuimplab.blogspot.com/search/label/stackhttp://jntuimplab.blogspot.com/search/label/pushhttp://jntuimplab.blogspot.com/search/label/pophttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=5334713381102951307http://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/09/stack-program-for-push-and-pop.htmlhttp://jntuimplab.blogspot.com/search/label/stringhttp://jntuimplab.blogspot.com/search/label/reversehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086
  • 7/31/2019 mcu note

    13/70

    S E P 1 3 , 2 0 0 8

    Moving a bock of data from one location to another using assembly languageFollowing is the program code for Moving a bock of data from one location to another using assemblylanguage . The size is initally stored in SI register and then SI is incremented to accept input

    number(s). Then the number is moved to AX and then to DI register. DI is incremented to store furthernumbers in the list. This is looped and the loop ends when counter becomes zero.

    MOV SI,2000MOV DI,4000MOV CL,[SI]INC SI : LABELMOV AX,[SI]MOV [DI], AXINC DILOOP LABEL

    INT A5

    You might be also interested in:

    :: Interfacing Analog-to-Digital converter to 8086 using 8255 :: Find Square Root of a hexadecimal number in assembly language :: common intreview questions on 8086 :: Assembly Language Source Codes

    0 comments

    Labels: Assembly Language , moving block of data

    A U G 3 0 , 2 0 0 8

    check wether given 16 bit number is palindrome or notPalindrome program taking 16 bits.

    taking C7H,EBH as given data i have done the programwhich is equivalant to 1101011111101011

    ORG 2000HLXI H,2100H ;DATAS ARE STORED AT LOCATIONS 2100H,21001HMOV A,MMVI C,07H

    LOOP: RRCCALL SBR ;SBR IS SUBROUTINEDCR C

    http://jntuimplab.blogspot.com/2008/09/moving-bock-of-data-from-one-location.htmlhttp://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=3574098350650152403http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=3574098350650152403http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/moving%20block%20of%20datahttp://jntuimplab.blogspot.com/search/label/moving%20block%20of%20datahttp://jntuimplab.blogspot.com/search/label/moving%20block%20of%20datahttp://jntuimplab.blogspot.com/2008/08/check-wether-given-16-bit-number-is.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=3574098350650152403http://jntuimplab.blogspot.com/2008/08/check-wether-given-16-bit-number-is.htmlhttp://jntuimplab.blogspot.com/search/label/moving%20block%20of%20datahttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=3574098350650152403http://jntuimplab.blogspot.com/2008/02/assembly-language-source-codes.htmlhttp://jntuimplab.blogspot.com/2008/01/common-intreview-questions-on-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/experiment-6.htmlhttp://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/2008/09/moving-bock-of-data-from-one-location.html
  • 7/31/2019 mcu note

    14/70

    JNZ LOOP

    ANI 01HADD DINX H

    CMP MLXI H,2400H ;1 IS STORED AT MEM-LOC 2400H IF PALIIN ELSE 0JZ PALINMVI M,00HJMP FIN

    PALIN: MVI M,01HFIN: HLT

    SBR: MOV B,AMOV A,D

    JNC BYPAS ;IF CARRY IS NOT 1 IS NOT AADEDADI 01HBYPAS: RLCMOV D,AMOV A,BRET

    ORG 2100HDB 00C7H,00EBH ;DATA BYTE

    END

    here EBH is reversed and compared with C7H, if they are equal then plain else not palin

    You might be also interested in:

    :: Temperature Control system using 8086 :: Traffic light control system using 8086 :: Assembly Language Program to serve NMI :: Interfacing Stepper Motor to 8086 using 8255

    0 comments

    Labels: Assembly Language , Program

    J U L 2 2 , 2 0 0 8

    8086 program to find GCD of two 2 numbers

    http://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/traffic-light-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/traffic-light-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/traffic-light-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/02/language-program-to-be-executed-when.htmlhttp://jntuimplab.blogspot.com/2008/02/language-program-to-be-executed-when.htmlhttp://jntuimplab.blogspot.com/2008/02/language-program-to-be-executed-when.htmlhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=8078088687969995850http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=8078088687969995850http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/2008/07/8086-program-to-find-gcd-of-two-2.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=8078088687969995850http://jntuimplab.blogspot.com/2008/07/8086-program-to-find-gcd-of-two-2.htmlhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=8078088687969995850http://jntuimplab.blogspot.com/2008/10/program-to-interface-stepper-motor-with.htmlhttp://jntuimplab.blogspot.com/2008/02/language-program-to-be-executed-when.htmlhttp://jntuimplab.blogspot.com/2008/02/traffic-light-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.html
  • 7/31/2019 mcu note

    15/70

    Euclid (a Greek mathematicians and philosopher of about 300 BC) describes this algorithm inPropositions 1 and 2 of Book 7 of The Elements, although it was probably known to the Babylonian andEgyptian mathematicians of 3000-4000 BC also.If we try it with an two numbers, the final non-zero remainder is the greatest number that is an exactdivisor of both our original numbers (the greatest common divisor)

    Here is the program

    mov ax,4000hmov ds,axmov si,0000hmov al,num1 ;num1 is first no.mov cl,num2 ;num2 is second no.mov ah,00h

    cmp al,clja nextxchg al,clnext: mov bl,cldiv clcmp ah,00hje downmov al,clmov cl,ahmov ah,00hjmp nextdown mov result,bl ;result is the mem.loc.;where gcd is to be storedhlt

    You might be also interested in:

    :: options available for int 21h instruction :: Answers of Microprocessor(8085) & Electronics FAQ :: The 8085 Microprocessor Architecture Microprocessors & Interfacin g

    0 comments

    Labels: 8086 , Assembly Language , Program

    J U L 6 , 2 0 0 8

    decimal addition program for 8086This program will add two decimal numbers

    http://jntuimplab.blogspot.com/2008/05/options-available-for-int-21h.htmlhttp://jntuimplab.blogspot.com/2008/05/options-available-for-int-21h.htmlhttp://jntuimplab.blogspot.com/2008/05/answers-of-microprocessor8085.htmlhttp://jntuimplab.blogspot.com/2008/05/answers-of-microprocessor8085.htmlhttp://jntuimplab.blogspot.com/2008/05/8085-microprocessor-architecture.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=98871412929425091http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=98871412929425091http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/2008/07/decimal-addition-program-for-8086.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=98871412929425091http://jntuimplab.blogspot.com/2008/07/decimal-addition-program-for-8086.htmlhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=98871412929425091http://jntuimplab.blogspot.com/2008/05/8085-microprocessor-architecture.htmlhttp://jntuimplab.blogspot.com/2008/05/answers-of-microprocessor8085.htmlhttp://jntuimplab.blogspot.com/2008/05/options-available-for-int-21h.html
  • 7/31/2019 mcu note

    16/70

    LXI H,2200HMOV A,MINX HADD MDAA

    STA 2300HHLT

    DAA will convert HEX to valid BCD numbernow the program can be easily understood

    You might be also interested in:

    :: 8051 or PIC microcontroller which is better :: Effective addresses

    :: Floating Point Initializations

    0 comments

    Labels: 8086 , Assembly Language , Program

    J U N 3 0 , 2 0 0 8

    A subroutine program in assembly languageA subroutine based program in assembly language.

    this is the MAIN PROGRAM

    LXI SP 2400HLXI H,2000HLXI B,1020HCALL SUBHLT

    this is the subroutineSUB: PUSH BPUSH HLXI B,4080HLXI H,4090HDAD BSHLD 2200HPOPHPOPBRET

    http://jntuimplab.blogspot.com/2008/05/8051-or-pic-microcontroller-which-is.htmlhttp://jntuimplab.blogspot.com/2008/05/8051-or-pic-microcontroller-which-is.htmlhttp://jntuimplab.blogspot.com/2008/05/effective-addresses.htmlhttp://jntuimplab.blogspot.com/2008/05/effective-addresses.htmlhttp://jntuimplab.blogspot.com/2008/05/floating-point-initializations.htmlhttp://jntuimplab.blogspot.com/2008/05/floating-point-initializations.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=7430399703014498124http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=7430399703014498124http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/8086http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/2008/06/subroutine-program-in-assembly-language.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=7430399703014498124http://jntuimplab.blogspot.com/2008/06/subroutine-program-in-assembly-language.htmlhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/8086http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=7430399703014498124http://jntuimplab.blogspot.com/2008/05/floating-point-initializations.htmlhttp://jntuimplab.blogspot.com/2008/05/effective-addresses.htmlhttp://jntuimplab.blogspot.com/2008/05/8051-or-pic-microcontroller-which-is.html
  • 7/31/2019 mcu note

    17/70

  • 7/31/2019 mcu note

    18/70

    00000000 of 800400001000 of 800500000100 of 800600000000 of 800700000001 of 8008

    7. Add the values present in 8001 to 8008 n store it in the register C. Hence in register C, we have thevalue AD after rotating B5)8. Get the 1st value from 3000 n store it in accumulator (register A)9. Subtract A and C registers10. If the numbers are palindrome, 01h gets stored in memory 400011. If the numbers r not palindrome, 02h is stored in memory 400112. end

    the programLabel Mnemonics

    MVI H, 08hMVI L, 01hMVI C, 08hLDA 3001rotate: RARJC oneJNC zeroone: MVI M, 01hJMP nextZero: MVI M, 00hNext: INC LDCR CJNZ rotateMVI L, 00hInc: INC LMOV D, LMOV A, LSUI 09hJZ fini

    MOV A, MHey: RRCDCR DJZ incJNZ heyFini: MVI L, 00hMVI C, 00hOther: INC L

  • 7/31/2019 mcu note

    19/70

    MOV A, MMOV B, AINC LMOV A, MADD B

    ADD CMOV C, AMOV A, LSUI 08hJNZ otherMVI H, 30hMVI L, 00hMOV A,MSUB CJZ palinJNZ nopalin

    Palin: MVI A, 01hSTA 4000JMP overNopalin: MVI A, 02hSTA 4001Over: HLT

    You might be also interested in:

    :: Assembly Language Programs to compute an expression :: Interfacing Analog-to-Digital converter to 8086 using 8255 :: Interfacing Digital-To-Analog converter to 8086 using 8255 :: Temperature Control system using 8086

    1 comments

    Labels: Assembly Language , Program

    J U N 2 6 , 2 0 0 8

    seperate the digits of hexa decimal number assembly language programseperate the digits of a hexa decimal numbers and store in different locations

    first get the packed BCD number and mask the lower nibble then move to the required position in thenumber and adjust the higher BCD digit as a lower digit then store the partial result now get theorignal BCD number and mask the higher nibble store the result and stop the program

    LDA 2200HANI F0HRRC

    http://jntuimplab.blogspot.com/search/label/post-edit.g?blogID=2125838028922862032&postID=1563160507769635560http://jntuimplab.blogspot.com/search/label/post-edit.g?blogID=2125838028922862032&postID=1563160507769635560http://jntuimplab.blogspot.com/search/label/post-edit.g?blogID=2125838028922862032&postID=1563160507769635560http://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/interfacing-digital-to-analog-converter.htmlhttp://jntuimplab.blogspot.com/2008/01/interfacing-digital-to-analog-converter.htmlhttp://jntuimplab.blogspot.com/2008/01/interfacing-digital-to-analog-converter.htmlhttp://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.htmlhttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=8297873043992368396http://www.blogger.com/comment.g?blogID=2125838028922862032&postID=8297873043992368396http://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/2008/06/seperate-digits-of-hexa-decimal-number.htmlhttp://www.blogger.com/email-post.g?blogID=2125838028922862032&postID=8297873043992368396http://jntuimplab.blogspot.com/2008/06/seperate-digits-of-hexa-decimal-number.htmlhttp://jntuimplab.blogspot.com/search/label/Programhttp://jntuimplab.blogspot.com/search/label/Assembly%20Languagehttp://www.blogger.com/comment.g?blogID=2125838028922862032&postID=8297873043992368396http://jntuimplab.blogspot.com/2008/01/temperature-control-system-using-8086.htmlhttp://jntuimplab.blogspot.com/2008/01/interfacing-digital-to-analog-converter.htmlhttp://jntuimplab.blogspot.com/2008/01/analog-to-digital-converter-with-8086.htmlhttp://jntuimplab.blogspot.com/search/label/post-edit.g?blogID=2125838028922862032&postID=1563160507769635560
  • 7/31/2019 mcu note

    20/70

    RRCRRCRRCSTA 2300HLDA 2200H

    ANI 0FHSTA 2301HHLT

    You might be also interested in

    Read Modify Write Problem

    PIC16Fxxx family of MCUs

    The Microchip mid-range PIC microcontrollers use a sequence known as Read-Modify-Write (RMW) when changing an output state (1 or 0) on a pin. This can cause unexpected behaviorunder certain circumstances.

    When your program changes the state on a specific pin, for example RB0 in PORTB, the PICmicrocontroller first READs all 8 bits of the PORTB register which represents the states of all 8pins in PORTB (RB7-RB0).The PIC microcontroller then stores this data in the MCU. The bit associated with RB that you'vecommanded to MODIFY is changed, and then the PIC microcontroller WRITEs all 8 bits(RB7-RB0) back to the PORTB register.

    During the first reading of the PORT register, you will be reading the actual state of the physicalpin.The problem arises when an output pin is loaded in such a way that its logic state is affected bythe load. Instances of such loads are LEDs without current-limiting resistors or loads with highcapacitance or inductance.

  • 7/31/2019 mcu note

    21/70

    For example, if a capacitor is attached between pin and ground, it will take a short while tocharge when the pin is set to 1.On the other hand, if the capacitor is discharged, it acts like a short circuit, forcing the pin to '0'state, and, therefore, a read of the PORT register will return 0, even though we wrote a 1 to it.

    Lets analyze the following example :PORTB.B0 = 1;PORTB.B1 = 1;

    Assume that the PORTB is initially set to zero, and that all pins are set to output. Let's say weconnect a discharged capacitor to RB0 pin.

    The first line, PORTB.B0 = 1; will be decoded like in this way :

    READ PORTB is read : STOREData is stored inside a temporary

    internal register in the PIC :

    Actual voltage levels on MCU pins are relevant.

    MODIFY Data is modified to set the RB0 bit : WRITEPORTB is written with the modifieddata. The output driver for RB0 turnson, and the capacitor starts to charge :

    The second line, PORTB.B1 = 1; will be decoded like in this way :

    READ PORTB is read : STORE

    Because the capacitor is still charging,the voltage at RB0 is still low and readsas a '0' (since we are reading from thepins directly, not from the PORTBregister) :

    Actual voltage levels on MCU pins are relevant.

    MODIFY Data is modified to set the bit : WRITEPORTB is written with the new data.The output driver for RB1 turns on, butthe driver for RB0 turns back off :

  • 7/31/2019 mcu note

    22/70

    To correct the problem in the code, insert a delay after each PORTB.Bx = 1 line, or modify theentire PORTB register in a single line PORTB = 0b00000011 .

    PIC18Fxxxx family of MCUs

    On a PIC18Fxxxx device, this problem can be avoided by using LATx register when writing toports, rather than using PORTx registers.Writing to a LATx register is equivalent to writing to a PORTx register, but readings fromLATx registers return the data value held in the port latch, regardless of the state of theactual pin .

    For example, lets analyze the following example :

    LATB.B0 = 1;LATB.B1 = 1;

    The first line, LATB.B0 = 1; will be decoded like in this way :

    READ LATB is read : STORE Data is stored inside a temporaryinternal register in the PIC :

    Actual voltage levels on MCU pins are no longer relevant when using LATx foroutput.

    MODIFY Data is modified to set the RB0 bit : WRITELATB is written with the modifieddata. The output driver for RB0 turnson, and the capacitor starts to charge :

    The second line, LATB.B1 = 1; will be decoded like in this way :

    READ LATB is read : STORESince the voltage levels on MCU pinsare no longer relevant, we get theexpected value :

    Actual voltage levels on MCU pins are no longer relevant when using LATx foroutput.

    MODIFY Data is modified to set the bit :WRITE

    LATB is written with the new data.The output driver for RB1 turns on, andthe output driver for RB0 remains

  • 7/31/2019 mcu note

    23/70

  • 7/31/2019 mcu note

    24/70

  • 7/31/2019 mcu note

    25/70

    parses as:

    int i;

    Note that the mikroC PRO for PIC does not support a nonportable token pasting strategy using

    /**/ . For more information on token pasting, refer to the Preprocessor Operators .

    C++ comments

    The mikroC PRO for PIC allows single-line comments using two adjacent slashes ( // ). Thecomment can start in any position and extends until the next new line.

    The following code

    int i; // this is a comment int j;

    parses as:

    int i;int j;

    Nested comments

    ANSI C doesnt allow nested comments. The attempt to nest a comment like this

    /* int /* declaration */ i; */

    fails, because the scope of the first /* ends at the first */ . This gives us

    i; */

    which would generate a syntax error.

    Copyright (c) 2002-2010 mikroElektronika. All rights reserved.What do you think about this topic ? Send us feedback! Integer Constants

    mikroC PRO for PIC Language Reference > Lexical Elements > Tokens > Constants >

    Integer Constants

    Integer constants can be decimal (base 10), hexadecimal (base 16), binary (base 2), or octal (base8). In the absence of any overriding suffixes, the data type of an integer constant is derived fromits value.

    http://www.mikroe.com/en/support/http://www.mikroe.com/en/support/http://www.mikroe.com/en/support/http://www.mikroe.com/en/support/
  • 7/31/2019 mcu note

    26/70

    Long and Unsigned Suffixes

    The suffix L (or l ) attached to any constant forces that constant to be represented as a long .Similarly, the suffix U (or u ) forces a constant to be unsigned . Both L and U suffixes can be usedwith the same constant in any order or case: ul , Lu , UL, etc.

    In the absence of any suffix ( U, u , L, or l ), a constant i s assigned the smallest of the followingtypes that can accommodate its value: short , unsigned short , int , unsigned int , long int ,unsigned long int .

    Otherwise:

    If a constant has the U suffix, its data type will be the first of the following that canaccommodate its value: unsigned short , unsigned int , unsigned long int .

    If a constant has the L suffix, its data type will be the first of the following that canaccommodate its value: long int , unsigned long int .

    If a constant has both L and U suffixes, ( LU or UL), its data type will be unsigned long int .

    Decimal

    Decimal constants from -2147483648 to 4294967295 are allowed. Constants exceeding these bounds will produce an Out of range error. Decimal constants must not use an initial zero. Aninteger constant that has an initial zero is interpreted as an octal constant. Thus,

    int i = 10; /* decimal 10 */ int i = 010; /* decimal 8 */ int i = 0; /* decimal 0 = octal 0 */

    In the absence of any overriding suffixes, the data type of a decimal constant is derived from itsvalue, as shown below:

    Value Assigned to Constant Assumed Type

    < -2147483648 Error: Out of range!

    -2147483648 -32769 long

    -32768 -129 int

    -128 127 short

    128 255 unsigned short

    256 32767 int

  • 7/31/2019 mcu note

    27/70

    Value Assigned to Constant Assumed Type

    32768 65535 unsigned int

    65536 2147483647 long

    2147483648 4294967295 unsigned long

    > 4294967295 Error: Out of range!

    Hexadecimal

    All constants starting with 0x (or 0X) are taken to be hexadecimal. In the absence of anyoverriding suffixes, the data type of an hexadecimal constant is derived from its value, accordingto the rules presented above. For example, 0xC367 will be treated as unsigned int .

    Binary

    All constants starting with 0b (or 0B) are taken to be binary. In the absence of any overridingsuffixes, the data type of an binary constant is derived from its value, according to the rulespresented above. For example, 0b11101 will be treated as short .

    Octal

    All constants with an initial zero are taken to be octal. If an octal constant contains the illegaldigits 8 or 9, an error is reported. In the absence of any overriding suffixes, the data type of anoctal constant is derived from its value, according to the rules presented above. For example,0777 will be treated as int .

    Copyright (c) 2002-2010 mikroElektronika. All rights reserved.What do you think about this topic ? Send us feedback!

    Floating Point ConstantsmikroC PRO for PIC Language Reference > Lexical Elements > Tokens > Constants >

    Floating Point Constants

    A floating-point constant consists of:

    Decimal integer Decimal point Decimal fraction e or E and a signed integer exponent (optional) Type suffix: f or F or l or L (optional)

    http://www.mikroe.com/en/support/http://www.mikroe.com/en/support/http://www.mikroe.com/en/support/http://www.mikroe.com/en/support/
  • 7/31/2019 mcu note

    28/70

    Either decimal integer or decimal fraction (but not both) can be omitted. Either decimal point orletter e (or E) with a signed integer exponent (but not both) can be omitted. These rules allowconventional and scientific (exponent) notations.

    Negative floating constants are taken as positive constants with an unary operator minus (-)

    prefixed.

    The mikroC PRO for PIC limits floating-point constants to the range 1.17549435082 * 10 -38 ..6.80564774407 * 10 38 .

    Here are some examples:

    0. // = 0.0 -1.23 // = -1.23 23.45e6 // = 23.45 * 10^6 2e-5 // = 2.0 * 10^-5 3E+10 // = 3.0 * 10^10

    .09E34 // = 0.09 * 10^34

    The mikroC PRO for PIC floating-point constants are of the type double . Note that the mikroCPRO for PICs implementation of ANSI Standard considers float and double (together with thelong double variant) to be the same type.

    Character Constants

    mikroC PRO for PIC Language Reference > Lexical Elements > Tokens > Constants >

    Character ConstantsA character constant is one or more characters enclosed in single quotes, such as 'A' , '+' , or'\n' . In the mikroC PRO for PIC, single-character constants are of the unsigned int type.Multi-character constants are referred to as string constants or string literals . For moreinformation refer to String Constants .

    Escape Sequences

    A backslash character ( \ ) is used to introduce an escape sequence, which allows a visualrepresentation of certain nongraphic characters. One of the most common escape constants is the

    newline character ( \n ).

    A backslash is used with octal or hexadecimal numbers to represent an ASCII symbol or controlcode corresponding to that value; for example, '\x3F' for the question mark. Any value withinlegal range for data type char ( 0 to 0xFF for the mikroC PRO for PIC) can be used. Largernumbers will generate the compiler error Out of range .

  • 7/31/2019 mcu note

    29/70

  • 7/31/2019 mcu note

    30/70

  • 7/31/2019 mcu note

    31/70

    The "Name" is preceded by two tabs; The Address is preceded by one tab. The line is followedby two new lines. The \" provides interior double quotes. The escape character sequence \\ istranslated into \ by the compiler.

    Adjacent string literals separated only by whitespace are concatenated during the parsing phase.

    For example:"This is " "just"

    " an example."

    is equivalent to

    "This is just an example."

    Line Continuation with Backslash

    You can also use the backslash ( \ ) as a continuation character to extend a string constant acrossline boundaries:

    "This is really \a one-line string."

    Enumeration Constants

    mikroC PRO for PIC Language Reference > Lexical Elements > Tokens > Constants >

    Enumeration Constants

    Enumeration constants are identifiers defined in enum type declarations. The identifiers areusually chosen as mnemonics to contribute to legibility. Enumeration size is calculated accordingto the enumerators (enumeration elements). They can be used in any expression where integerconstants are valid.

    For example:

    enum weekdays { SUN = 0, MON, TUE, WED, THU, FRI, SAT };

    The identifiers (enumerators) used must be unique within the scope of the enum declaration.Negative initializers are allowed. See Enumerations for details about enum declarations.

    Pointer ConstantsmikroC PRO for PIC Language Reference > Lexical Elements > Tokens > Constants >

    Pointer Constants

  • 7/31/2019 mcu note

    32/70

  • 7/31/2019 mcu note

    33/70

  • 7/31/2019 mcu note

    34/70

    i = ci; // Assign const-int to int *cp = ci; // Assign const-int to

    // object-pointed-at-by-a-const-pointer ++pci; // Increment a pointer-to-const pci = cpc; // Assign a const-pointer-to-a-const to a

    // pointer-to-const

    The following assignments are illegal:

    ci = 0; // NO--cannot assign to a const-int ci--; // NO--cannot change a const-int *pci = 3; // NO--cannot assign to an object

    // pointed at by pointer-to-const. cp = &ci; // NO--cannot assign to a const-pointer,

    // even if value would be unchanged. cpc++; // NO--cannot change const-pointer pi = pci; // NO--if this assignment were allowed,

    // you would be able to assign to *pci // (a const value) by assigning to *pi.

    Similar rules are applayed to the volatile modifier. Note that both const and volatile canappear as modifiers to the same identifier.

    Notes :

    Pointer to constant space (Flash memory) is allocated in RAM. Due to the previous note, it is not possible to define an extern const . Constants of a simple type are not allocated in the Flash memory nor in RAM, but

    changed in the compile time, and therefore, address of a such constant can not be

    obtained. PIC16 Enhanced family has 16-bit FSRs, FSRxL and FSRxH, capable of accessing entireRAM and Flash memory.This makes pointers to constants and pointers to variables compatible.

    Constant Expressions

    A constant expressions can be evaluated during translation rather that runtime and accordinglymay be used in any place that a constant may be.

    Constant expressions can consist only of the following:

    literals, enumeration constants, simple constants (no constant arrays or structures), sizeof operators.

  • 7/31/2019 mcu note

    35/70

    Constant expressions cannot contain any of the following operators, unless the operators arecontained within the operand of a sizeof operator: assignment, comma, decrement, functioncall, increment.

    Each constant expression can evaluate to a constant that is in the range of representable values

    for its type.

    Constant expression can be used anywhere a constant is legal.

    Keywords

    Keywords are words reserved for special purposes and must not be used as normal identifier names.

    Beside standard C keywords, all relevant SFR are defined as global variables and representreserved words that cannot be redefined (for example: TMR0, PCL, etc). Probe the Code Assistant for specific letters ( Ctrl +Space in Editor) or refer to Predefined Globals and Constants .

    Here is an alphabetical listing of keywords in C:

    absolute asm at auto bit bool break case catch char class code const continue data default delete do double else enum explicit extern false float for

  • 7/31/2019 mcu note

    36/70

    friend goto if inline int

    io long mutable namespace operator org pascal private protected public register

    return rx sfr short signed sizeof static struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile while

    Also, the mikroC PRO for PIC includes a number of predefined identifiers used in libraries. Youcould replace them by your own definitions, if you want to develop your own libraries. For moreinformation, see mikroC PRO for PIC Libraries .

    Identifiers

  • 7/31/2019 mcu note

    37/70

  • 7/31/2019 mcu note

    38/70

    , Comma ; Semicolon : Colon * Asterisk = Equal sign

    # Pound sign

    Most of these punctuators also function as operators.

    Brackets

    Brackets [ ] indicate single and multidimensional array subscripts:

    char ch, str[] = "mikro";

    int mat[3][4]; /* 3 x 4 matrix */ ch = str[3]; /* 4th element */

    Parentheses

    Parentheses ( ) are used to group expressions, isolate conditional expressions, and indicatefunction calls and function parameters:

    d = c * (a + b); /* override normal precedence */

    if (d == z) ++x; /* essential with conditional statement */ func(); /* function call, no args */ void func2( int n); /* function declaration with parameters */

    Parentheses are recommended in macro definitions to avoid potential precedence problemsduring an expansion:

    #define CUBE(x) ((x) * (x) * (x))

    For more information, refer to Operators Precedence And Associativity and Expressions .

    Braces

    Braces { } indicate the start and end of a compound statement:

    if (d == z) {++x;func();

    }

    Closing brace serves as a terminator for the compound statement, so a semicolon is not requiredafter } , except in structure declarations. Sometimes, the semicolon can be illegal, as in

  • 7/31/2019 mcu note

    39/70

  • 7/31/2019 mcu note

    40/70

    Asterisk ( * ) in a variable declaration denotes the creation of a pointer to a type:

    char *char_ptr; /* a pointer to char is declared */

    Pointers with multiple levels of indirection can be declared by indicating a pertinent number of asterisks:

    int **int_ptr; /* a pointer to an array of integers */ double ***double_ptr; /* a pointer to a matrix of doubles */

    You can also use asterisk as an operator to either dereference a pointer or as multiplicationoperator:

    i = *int_ptr;a = b * 3.14;

    For more information, see the Pointers .

    Equal Sign

    Equal sign ( =) separates variable declarations from initialization lists:

    int test[5] = { 1, 2, 3, 4, 5 };int x = 5;

    Equal sign is also used as an assignment operator in expressions:

    int a, b, c;a = b + c;

    For more information, see Assignment Operators .

    Pound Sign (Preprocessor Directive)

    Pound sign ( # ) indicates a preprocessor directive when it occurs as the first nonwhitespacecharacter on a line. It signifies a compiler action, not necessarily associated with a codegeneration. See the Preprocessor Directives for more information.

    # and ## are also used as operators to perform token replacement and merging during thepreprocessor scanning phase. See the Preprocessor Operators .

    Objects

    An object is a specific region of memory that can hold a fixed or variable value (or set of values).This use of a term object is different from the same term, used in object-oriented languages,which is more general. Our definiton of the word would encompass functions, variables,symbolic constants, user-defined data types, and labels.

  • 7/31/2019 mcu note

    41/70

    Each value has an associated name and type (also known as a data type). The name is used toaccess the object and can be a simple identifier or complex expression that uniquely refers theobject.

    Objects and Declarations

    Declarations establish a necessary mapping between identifiers and objects. Each declarationassociates an identifier with a data type.

    Associating identifiers with objects requires each identifier to have at least two attributes: storageclass and type (sometimes referred to as data type). The mikroC PRO for PIC compiler deducesthese attributes from implicit or explicit declarations in the source code. Usually, only the type isexplicitly specified and the storage class specifier assumes the automatic value auto .

    Generally speaking, an identifier cannot be legally used in a program before its declaration pointin the source code. Legal exceptions to this rule (known as forward references) are labels, calls to

    undeclared functions, and struct or union tags.

    The range of objects that can be declared includes:

    Variables Functions Types Arrays of other types Structure, union, and enumeration tags Structure members Union members

    Enumeration constants Statement labels Preprocessor macros

    The recursive nature of the declarator syntax allows complex declarators. Youll probably wantto use typedefs to improve legibility if constructing complex objects.

    Lvalues

    Lvalue is an object locator: an expression that designates an object. An example of lvalueexpression is *P , where P is any expression evaluating to a non-null pointer. A modifiable lvalue

    is an identifier or expression that relates to an object that can be accessed and legally changed inmemory. A const pointer to a constant, for example, is not a modifiable lvalue. A pointer to aconstant can be changed (but its dereferenced value cannot).

    Historically, l stood for left , meaning that lvalue could legally stand on the left (the receivingend) of an assignment statement. Now only modifiable lvalues can legally stand to the left of anassignment operator. For example, if a and b are nonconstant integer identifiers with properly

  • 7/31/2019 mcu note

    42/70

    allocated memory storage, they are both modifiable lvalues, and assignments such as a = 1 andb = a + b are legal.

    Rvalues

    The expression a + b is not lvalue: a + b = a is illegal because the expression on the left is notrelated to an object. Such expressions are sometimes called rvalues (short for right values).

    Copyright

    Scope and Visibility

    Scope

    The scope of an identifier is a part of the program in which the identifier can be used to access itsobject. There are different categories of scope: block (or local), function, function prototype, andfile. These categories depend on how and where identifiers are declared.

    Block : The scope of an identifier with block (or local) scope starts at the declarationpoint and ends at the end of the block containing the declaration (such block is known asthe enclosing block). Parameter declarations with a function definition also have block scope, limited to the scope of the function body.

    File : File scope identifiers, also known as globals , are declared outside of all blocks; theirscope is from the point of declaration to the end of the source file.

    Function : The only identifiers having function scope are statement labels. Label namescan be used with goto statements anywhere in the function in which the label is declared.Labels are declared implicitly by writing label_name: followed by a statement. Labelnames must be unique within a function.

    Function prototype : Identifiers declared within the list of parameter declarations in afunction prototype (not as a part of a function definition) have a function prototype scope.This scope ends at the end of the function prototype.

    Visibility

    The visibility of an identifier is a region of the program source code from which an identifiersassociated object can be legally accessed.

    Scope and visibility usually coincide, though there are circumstances under which an objectbecomes temporarily hidden by the appearance of a duplicate identifier: the object still exists butthe original identifier cannot be used to access it until the scope of the duplicate identifier ends.

    Technically, visibility cannot exceed a scope, but a scope can exceed visibility. See thefollowing example:

    void f ( int i) {int j; // auto by default

  • 7/31/2019 mcu note

    43/70

    j = 3; // int i and j are in scope and visible

    { // nested block double j; // j is local name in the nested block j = 0.1; // i and double j are visible;

    // int j = 3 in scope but hidden }

    // double j out of scope j += 1; // int j visible and = 4

    }// i and j are both out of scope

    Name Spaces

    Name space is a scope within which an identifier must be unique. The mikroC PRO for PIC usesfour distinct categories of identifiers:

    1. goto label names - must be unique within the function in which they are declared.2. Structure, union, and enumeration tags - must be unique within the block in which they

    are defined. Tags declared outside of any function must be unique.3. Structure and union member names - must be unique within the structure or union in

    which they are defined. There is no restriction on the type or offset of members with thesame member name in different structures.

    4. Variables, typedefs, functions, and enumeration members - must be unique within thescope in which they are defined. Externally declared identifiers must be unique amongexternally declared variables.

    Duplicate names are legal for different name spaces regardless of the scope rules.

    For example:

    int blue = 73;

    { // open a block enum colors { black, red, green, blue, violet, white } c;/* enumerator blue = 3 now hides outer declaration of int blue */

    struct colors { int i, j; }; // ILLEGAL: colors duplicate tag double red = 2; // ILLEGAL: redefinition of red

    }

    blue = 37; // back in int blue scope

    Duration

    mikroC PRO for PIC Language Reference > Concepts >

    Duration

  • 7/31/2019 mcu note

    44/70

    Duration, closely related to a storage class , defines a period during which the declared identifiershave real, physical objects allocated in memory. We also distinguish between compile-time andrun-time objects. Variables, for instance, unlike typedefs and types, have real memory allocatedduring run time. There are two kinds of duration: static and local .

    Static DurationMemory is allocated to objects with static duration as soon as execution is underway; this storageallocation lasts until the program terminates. Static duration objects usually reside in fixed datasegments allocated according to the memory specifier in force. All globals have static duration.All functions, wherever defined, are objects with static duration. Other variables can be givenstatic duration by using the explicit static or extern storage class specifiers.

    In the mikroC PRO for PIC, static duration objects are not initialized to zero (or null) in theabsence of any explicit initializer.

    Dont mix static duration with file or global scope. An object can have static duratio n and localscope see the example below.

    Local Duration

    Local duration objects are also known as automatic objects. They are created on the stack (or in aregister) when an enclosing block or a function is entered. They are deallocated when theprogram exits that block or function. Local duration objects must be explicitly initialized;otherwise, their contents are unpredictable.

    The storage class specifier auto can be used when declaring local duration variables, but it is

    usually redundant, because auto is default for variables declared within a block.

    An object with local duration also has local scope because it does not exist outside of itsenclosing block. On the other hand, a local scope object can have static duration. For example:

    void f() {/* local duration variable; init a upon every call to f */ int a = 1;/* static duration variable; init b only upon first call to f */ static int b = 1;/* checkpoint! */ a++;b++;

    }

    void main() {/* At checkpoint, we will have: */ f(); // a=1, b=1, after first call, f(); // a=1, b=2, after second call, f(); // a=1, b=3, after third call,

    // etc.}

  • 7/31/2019 mcu note

    45/70

    Arithmetic Types

    mikroC PRO for PIC Language Reference > Types > Fundamental Types >

    Arithmetic TypesThe arithmetic type specifiers are built up from the following keywords: void , char , int , float and double , together with the prefixes short , long , signed and unsigned . From thesekeywords you can build both integral and floating-point types.

    Integral Types

    The types char and int , together with their variants, are considered to be integral data types.Variants are created by using one of the prefix modifiers short , long , signed and unsigned .

    In the table below is an overview of the integral types keywords in parentheses can be (andoften are) omitted.

    The modifiers signed and unsigned can be applied to both char and int . In the absence of theunsigned prefix, signed is automatically assumed for integral types. The only exception ischar , which is unsigned by default. The keywords signed and unsigned , when used on theirown, mean signed int and unsigned int , respectively.

    The modifiers short and long can only be applied to int . The keywords short and long , usedon their own, mean short int and long int , respectively.

    Type Size in bytes Range

    bit 1 bit 0 or 1

    sbit 1 bit 0 or 1

    (unsigned) char 1 0 .. 255

    signed char 1 - 128 .. 127

    (signed) short (int) 1 - 128 .. 127

    unsigned short (int) 1 0 .. 255

    (signed) int 2 -32768 .. 32767

    unsigned (int) 2 0 .. 65535

  • 7/31/2019 mcu note

    46/70

    Type Size in bytes Range

    (signed) long (int) 4 -2147483648 .. 2147483647

    unsigned long (int) 4 0 .. 4294967295

    Floating-point Types

    The types float and double , together with the long double variant, are considered to befloating- point types. The mikroC PRO for PICs implementation of an ANSI Standard considersall three to be the same type.

    Floating point in the mikroC PRO for PIC is implemented using the Microchip AN575 32-bitformat (IEEE 754 compliant).

    An overview of the floating-point types is shown in the table below:

    Type Size in

    bytes Range

    float 4 -1.5 * 10 45 .. +3.4 * 10 38

    double 4 -1.5 * 10 45 .. +3.4 * 10 38

    long double 4 -1.5 * 10 45 .. +3.4 * 10 38

    Enumerations

    An enumeration data type is used for representing an abstract, discreet set of values withappropriate symbolic names.

    Enumeration Declaration

    Enumeration is declared like this:

    enum tag { enumeration-list };

    Here, tag is an optional name of the enumeration; enumeration-list is a comma-delimited listof discreet values, enumerators (or enumeration constants). Each enumerator is assigned a fixedintegral value. In the absence of explicit initializers, the first enumerator is set to zero, and thevalue of each succeeding enumerator is set to a value of its predecessor increased by one.

  • 7/31/2019 mcu note

    47/70

    Variables of the enum type are declared the same as variables of any other type. For example, thefollowing declaration:

    enum colors { black, red, green, blue, violet, white } c;

    establishes a unique integral type, enum colors , variable c of this type, and set of enumeratorswith constant integer values (black = 0, red = 1, ...). In the mikroC PRO for PIC, a variable of anenumerated type can be assigned any value of the type int no type checking beyond that isenforced. That is:

    c = red; // OK c = 1; // Also OK, means the same

    With explicit integral initializers, you can set one or more enumerators to specific values. Theinitializer can be any expression yielding a positive or negative integer value (after possibleinteger promotions). Any subsequent names without initializers will be increased by one. Thesevalues are usually unique, but duplicates are legal.

    The order of constants can be explicitly re-arranged. For example:

    enum colors { black, // value 0 red, // value 1 green, // value 2 blue=6, // value 6 violet, // value 7 white=4 }; // value 4

    Initializer expression can include previously declared enumerators. For example, in the followingdeclaration:

    enum memory_sizes { bit = 1, nibble = 4 * bit, byte = 2 * nibble,kilobyte = 1024 * byte };

    nibble would acquire the value 4, byte the value 8, and kilobyte the value 8192.

    Anonymous Enum Type

    In our previous declaration, the identifier colors is an optional enumeration tag that can be usedin subsequent declarations of enumeration variables of the enum colors type:

    enum colors bg, border; /* declare variables bg and border */

    Like with struct and union declarations, you can omit the tag if no further variables of this enum type are required:

    /* Anonymous enum type: */ enum { black, red, green, blue, violet, white } color;

  • 7/31/2019 mcu note

    48/70

    Enumeration Scope

    Enumeration tags share the same name space as structure and union tags. Enumerators share thesame name space as ordinary variable identifiers:

    int blue = 73;{ // open a block

    enum colors { black, red, green, blue, violet, white } c;/* enumerator blue = 3 now hides outer declaration of int blue */

    struct colors { int i, j; }; // ILLEGAL: colors duplicate tag double red = 2; // ILLEGAL: redefinition of red

    }

    blue = 37; // back in int blue scope

    Void Type

    void is a special type indicating the absence of any value. There are no objects of void ; instead,void is used for deriving more complex types.

    Void Functions

    Use the void keyword as a function return type if the function does not return a value.

    void print_temp( char temp) {Lcd_Out_Cp("Temperature:");Lcd_Out_Cp(temp);

    Lcd_Chr_Cp(223); // degree character Lcd_Chr_Cp('C');}

    Use void as a function heading if the function does not take any parameters. Alternatively, youcan just write empty parentheses:

    main( void ) { // same as main() ...

    }

    Generic Pointers

    Pointers can be declared as void , which means that they can point to any type. These pointersare sometimes called generic .

    Arrays

  • 7/31/2019 mcu note

    49/70

    Array is the simplest and most commonly used structured type. A variable of array type isactually an array of objects of the same type. These objects represent elements of an array andare identified by their position in array. An array consists of a contiguous region of storageexactly large enough to hold all of its elements.

    Array DeclarationArray declaration is similar to variable declaration, with the brackets added after identifer:

    type array_name [ constant-expression ]

    This declares an array named as array_name and composed of elements of type . The type canbe any scalar type (except void ), user-defined type, pointer, enumeration, or another array.Result of constant-expression within the brackets determines a number of elements in array.If an expression is given in an array declarator, it must evaluate to a positive constant integer.The value is a number of elements in an array.

    Each of the elements of an array is indexed from 0 to the number of elements minus one. If anumber of elements is n , elements of array can be approached as variables array_name [0] ..array_name [n-1] of type .

    Here are a few examples of array declaration:

    #define MAX = 50int vector_one[10]; /* declares an array of 10 integers */ float vector_two[MAX]; /* declares an array of 50 floats */ float vector_three[MAX - 20]; /* declares an array of 30 floats */

    Array Initialization

    An array can be initialized in declaration by assigning it a comma-delimited sequence of valueswithin braces. When initializing an array in declaration, you can omit the number of elements itwill be automatically determined according to the number of elements assigned. For example:

    /* Declare an array which holds number of days in each month: */ int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

    /* This declaration is identical to the previous one */ int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};

    If you specify both the length and starting values, the number of starting values must not exceedthe specified length. The opposite is possible, in this case the trailing excess elements will beassigned to some encountered runtime values from memory.

    In case of array of char , you can use a shorter string literal notation. For example:

    /* The two declarations are identical: */ const char msg1[] = {'T', 'e', 's', 't', '\0'};

  • 7/31/2019 mcu note

    50/70

  • 7/31/2019 mcu note

    51/70

    Pointers are special o bjects for holding (or pointing to ) memory addresses. In the mikroC PROfor PIC, address of an object in memory can be obtained by means of an unary operator &. Toreach the pointed object, we use an indirection operator ( * ) on a pointer.

    A pointer of ty pe pointer to object of type holds the address of (that is, points to) an object of

    type . Since pointers are objects, you can have a pointer pointing to a pointer (and so on). Otherobjects commonly pointed to include arrays, structures, and unions.

    A pointer to a function is best thought of as an address, usually in a code segment, where thatfunctio