Friday, 29 July 2011

8085 Instruction set - Branch Instructions

             The branching instructions alter the normal sequential program either conditionaly or unconditionally.

As formerly seen in my previous posts in this Series, we divided the Series into four parts:


     JMP :
          This instruction is used to jump from one set of programs to another set
                e.g:   In a 8 bit multiplication program, JN2 LOOP it means that if no zero results in previous arithmetic operation, it will jump to LOOP.
    CALL :
          This instruction is used to call the function.
                e.g:   CALL DIV,CALL SUB etc..
    RET :
          This instruction is used to return to the program after doing some manipulation for a program to succeed.

          Here we are going to discuss some instructions which we use with jump instruction.
The instructions are

        NZ Not Zero (Z = 0)
        Z    Zero (Z = 1)
        NC No Carry (C = 0)
        C    Carry (C = 1)
        PO Parity Odd (P = 0)
        PE Parity Even (P = 1)
        P   Plus (S = 0)
        M  Minus (S = 1)

        Jumps Calls Returns
        C CC RC (Carry)
        INC CNC RNC (No Carry)
        JZ CZ RZ (Zero)
        JNZ CNZ RNZ (Not Zero)
        JP CP RP (Plus)
        JM CM RM (Minus)
        JPE CPE RPE (Parity Even)
        JP0 CPO RPO (Parity Odd)
        Two other instructions can affect a branch by replacing the contents or the program counter:

        PCHL Move H & L to Program Counter
        RST    Special Restart Instruction Used with Interrupts

Stack I/O, and Machine Control Instructions:
    The following instructions affect the Stack and/or Stack Pointer:

        PUSH  Push Two bytes of Data onto the Stack
        POP     Pop Two Bytes of Data off the Stack
        XTHL Exchange Top of Stack with H & L
        SPHL  Move content of H & L to Stack Pointer

The I/0 instructions are as follows:
        IN     Initiate Input Operation
        OUT Initiate Output Operation

The Machine Control instructions are as follows:
        EI      Enable Interrupt System
        DI     Disable Interrupt System
        HLT Halt
        NOP No Operation

Thursday, 28 July 2011

Digital Voltmeter - Part I

Digital Voltmeter ( DVM ) is an Analog to digital    converter (A/D) with a
digital display

TYPES: (based on the type of ADC used)
          1. Dual Slope Type
          2. Ramp Type
          3. Integrating Type
          4. Successive Approximation Type


          Principle: Dual slope integrating type digital voltemeter has both +ve and -ve slope during integration there by it averages the errors (or) noise that are present in the environment.

          Operation: The start pulse resets the counter to zero, the flip flop gives zero output and keeps switch Si closed and Sr open by switch driver circuit .The integrator integrates in +v direction when zero crossing just exceeds zero. The gate is open allowing the counter to count the oscillator clock. When counter resets to maximum count for the next clock, the counter resets to zero forcing the flip flop output to '1'. In this case, switch Si is open and Sr is closed. Vr (reference voltage) is negative reference,now integrated by the integrator with negative slope and the voltage crosses zero,the zero crossing detector closes the gate, stopping the counter.

           The counts in the counter is proportional to 't2' ( time for integrating Vr (negative slope) towards zero ) and is in-turn proportional to input voltage.

An Expression for Input Voltage:

          Charging Equation:      Vout = -(1/RC) ∫ [ Vi * dt ]    ( interval 0 to t1)
                                                 Vout = -(1/RC)*Vi*t1
         Discharge Equation:     Vout = (1/RC) ∫ [ -Vr * dt ]   ( interval 0 to t2)
                                                 Vout = (-1/RC)*Vr*t2

         From above equations, we get
                                                Vi*t1 = Vr*t2
                                                    Vi = (t2/t1)*Vr
                                        since,  t1 = n1*T
                                            and t2 = n2*T
                                                    Vi = (n2/n1)*Vr

        Hence, Vi is directly proportional to n2.

Output Voltage
R, C
Resistor and Capacitor in the integrator
Reference Voltage
Total time of integration
Time of integration of input voltage
Time of integration of reference voltage
Maximum number of counts
Final count value

Coming up next:

* Integrating Type DVM
* Successive Approximation type DVM

8085 Data Transfer Instructions

       Here we are going to discuss about data transfer instructions which move data between register or memory locations.
       MOV :
           This instruction is used to move the data from accumulator or memory to some registers or vice versa.
      e.g: If [A] = 00 and [B] = 20
             after MOV A,B
             [A] = 20 and [B] = 20
      MVI :
          This instruction is used to move the data from accumulator or memory to some registers or vice versa using the immediate data
e.g: after MVI B , 09
       [B] = 09
          This instruction is used to load the accumulator directly from the memory.
e.g: assume [4200] = FE
       after LDA 4200 
       [A] = FE
      STA :
           This instruction is used to store the content of accumulator directly to a memory address
e.g: If [A] = FF
       after STA 4200
       [4200] = FF

      LHLD :
           This instruction is used to load H&L registers directly from memory
e.g: If [4200] = FE and [4201] = 29
       after LHLD 4200
       [H] = 29 and [L] = FE

      SHLD :
           This instruction is used to store the H & L registers directly to memory.
e.g: If [H] = 29 and [L] = FE
       after SHLD 4200
       [4200] = FE and [4201] = 29

          Now we are going to see some data transfer instruction which deals with the register pair. To indicate the register pair we are using a term called ‘X’.
 LXI :
     This instruction is used to load the register pair with the immediate data.
            e.g:  after LXI H 4200
                    [H] = 42 and [L] = 00

     This instruction is used to load the accumulator with the data from address in register pair( 16 bit address).
            e.g: If [4432] = 3F and [A] = 00
                   [B]= 44 and [C]=32                      
                   after LDAX B
                   [A] = 3F

      This instructions is used to store the accumulator in address in register pair.
             e.g: If [A] = 32 and [D] = 40 and [E] = 00
                    after STAX D 
                    [4000] = 32.

      This instruction is used to exchange the data of H&L register pair with D&E register pair.
             e.g:  If [H] = 00, [L] = 01 and
                        [D] = 15 and [E] = 30
                     after XCHG 
                     [H] = 15 and [L] = 30
                     [D] = 00 and [E] = 01

      This instruction is used to exchange the top of stack with H&L.
             e.g: If [H] = 20 and [L] = 18 
                   assume that contents of stack is  
                  after XTHL                          
                  [H] = [01] and [L] = [09] and the contents of satck will be 

Numerical Methods Using MATLAB - Part 5

Graeffe's Root Squaring Method:
           This is a direct method and it is used to find the roots of a polynomial equation with real coefficients. Let us consider an equation of the form:

                         ax3 + bx^2 + cx + d = 0

To find the solution of the above equation, we fill up the following table:
Given Equation
First Squaring
b^2 - 2*a*c
c^2 - 2*b*d

              Thus, the table goes on. The number of squaring done depends on the required accuracy of the solution. The roots are calculated by using the final values of n1, n2, n3 and n4 as follows:


          From the above equations, the roots a1, a2, a3 can be calculated.The MATLAB code for solving a polynomial by the above method is given below:

Source Code: 
    % a function that uses Graeffe's method 
    % to calculate roots of Algebraic equation 
    function GraeffeFunc(co,gcount)
             % variable b contains the size of co
             % co  coeff/: vector
             [a b]=size(co);
             % initialize count to zero
             count = 0;
            % loop where elements of co vector are squared
            % step by step for further processing
            while count<gcount
                    for i=1:b
                         % for other coeff.
                         if i~=1 && i~=b
                              % for 1st and last coeff.
           % end of while
           % Finding the solution by operating on co1 vector values
           for i=2:b

          % displaying calculated values
    % end of program

Coming up next:
       * Solution of Simultaneous Linear Algebraic Equations

Wednesday, 27 July 2011

8085 Logical Instructions

        In my previous post we saw about arithmetic instructions of 8085uP. Now, we are going to discuss about some logical operations which we perform in registers, memory location and on flags.

As formerly seen in my previous post in this Series, we divided the Series into four parts:
       ANA :
         It logically AND with the accumulator. It means that the accumulator is multiplied with some register values.
         e.g: If [A] = 20 >> 0 0 1 0 0 0 0 0
                [B] = 30 >> 0 0 1 1 0 0 0 0
                After instruction >> [A] = 0 0 1 0 0 0 0 0
       ANI :
        It logically AND with the accumulator using the immediate data.
          e.g: For   [A] = FE  (i.e 1111 1110 )
                 after ANI 07        ; 07 = 0000 0111
                 [A] = 06     (i.e 0000 0110 )
       It logically OR with the accumulator. It means that the accumulator is added with the registers.
           e.g: If [A] = FE (i.e 1111 1110 )
                  and [B] = 31 (i.e 0011 0001 )
             after instruction  [A ] = FF (i.e 1111 1111 )
      ORI :
           As u guessed, it logically OR with the accumulator using the immediate data.
e.g: if [A] = 7D (i.e 0111 1101 )
      after ORI 17            ;17 = 1 0 0 0 0 1 1 1
      [A] = FF (i.e 1111 1111 )

      XRA :
          It logically EX-OR with the accumulator. It means that if any two numbers are same its output will be 0 else if not same output will be 1 
e.g: If [A] = 7F                                (i.e 0111 1111 )
       and [B] = 32                              (i.e 0011 0010 )
                After instruction >> [A] = 4D (i.e 0100 1101 )
     It logically EX-OR with the accumulator using the immediate data.
         e.g: If[A] = FE           (i.e 1111 1110 )
                after  XRI 07  ; 07 = 0000 0111
                [A] = F9              (i.e 1111 1001 )

     It compares the content of 8 bit data with the contents of accumulator Some 2 instructions are there here they are,

                It compares the conetents with the contents of accumulator. This instruction is used to check whether the numbers are same or zero etc.
      It compares with the contents of accumulator using immediate data.They are mostly used in 8 bit and 16 bit multiplication or division programs etc..

     It means the that the contents of accumulator is rotated to left.
        e.g: [A] = 1 0 1 0 1 1
               after RLC
               [A] = 0 1 0 1 1 1

     It is as same as RLC but it is rotated to right side.
       e.g: [A] = 1 1 1 1 1 0
              after RRC
              [A] = 0 1 1 1 1 1

     It rotates each bit of accumulator to left with carry.
        e.g: If [C]=0 and [A]= 1 1 0 1 1 1 0 1
               after RAL
               [C] =1 and [A] = 1 0 1 1 1 0 1 0

     It is as similar to RAL But I will rotate in right side.
        e.g: If [C] =0 and [A] = 1 1 1 1 1 0
               after RAR
               [C]=0 and [A] = 0 1 1 1 1 1

      These instructions are used to complement the data. The names of instructions are self-explaining abbreviations 
          It complements the accumulator.
             e.g: If [A] = 0 0 0 1
                    after CMA 
                    [A] = 1 1 1 0

          It complements the carry
            e.g: [C] = 0
                   after CMC
                   [C] = 1

         It sets the carry.
         e.g: If [C] = 0 or 1
                after STC 
                [C] = 1

Friday, 22 July 2011

SIRC Part III - Encoding and Decoding

In this post, We examine sample codes for encoding and decoding using Arduino.
     The frequency of the carrier signal to be sent is 40 KHz. Hence, it takes 25 micro-seconds for one cycle. Each cycle consists of ON and OFF time. The duty cycle denotes the ratio between ON time and Time Period. The duty cycle recommended by SIRC protocol is 1/4 or 1/3. Here we use a duty cycle of 25% (1/4). Hence, the number of cycles required to complete each type of bit is listed below:
              Start bit: ( 2400(uS)/25(uS) ) = 96 cycles
               '1' bit : ( 1200/25 ) = 48 cycles
               '0' bit : ( 600/25 ) = 24 cycles
A sample program for encoding the signal is given below:

void setup()
           pinMode(14,OUTPUT);      // IR LED is connected to pin14
int sum=0;
void transmit(int command)
        // Here we dont add the start bit to the array
        //Array arr[] represents just the data bits
        // We create the start pulse manually using pulse(int) function
        // We declare an array containing all the data bits (arr[])
        // i--> index variable
        int arr[12],i=0;
        // Here we convert the decimal value of command to binary value,
        // And store it in the array arr[]
        // From LSB to MSB

        // Now we have converted the decimal to binary
        // But we need to fill the empty digits to '0'
       for( i ; i<7 ; i++ )


              //Adding the address bits
              // For testing purpose, we use TV, address for TV is 10000 (5 bit data)
              // Now value of i is 7
              // Which represents the 8th position
             // Now value of i is 8
             // Which represents the 9th position (9,10,11,12)--> 4 iterations

            for( i ; i<12 ; i++ )
                  // Last 5 bits now look like 10000 which denotes address of TV
                  //Manually pulsing the start bit (2400 uS)
                  pulse(96);              //96*25=2400;
                 //Pulsing all the data bits
                 for(i=0;i<12;i++) {
                       if(arr[i]) {
                       } else {
               //The total time of one set of data (one frame) is 45 mS (ie) 45000 uS                  

// The pulse function for pulsing bits
// 25% duty cycle
// followed by 600 uS space
void pulse(int dur)
               for(int j=0;j<dur;j++) {

void loop()

          Decoding is relatively easier than encoding. A sample coding which is self-explanatory is given below:

void setup()
          Serial.begin(9600);       //Setting Baud Rate
          pinMode(15,INPUT);    //IR TSOP receiver is connected to PIN 15                   

int remote()
            // i--> index variable
            // arr[]--> array that stores digital word
            // val--> stores the decimal format of arr[]
            int i=0,arr[8],val=0;
            //Checking the start bit
            if(pulseIn(15,0)>2000) {
                  //Storing the digital word in arr[]
                  for(i=0; i<7 ; i++,arr[i] = pulseIn(15,0)) ;
                  //Converting digital word into decimal value
                  //Storing it in val
                    for(i=0;i<7;i++) {
                           if(arr[i]>1000) {
           return val;
void loop()
            int checkVal=remote();

Coming up next:

          * Practical model

          * Building a project ( An Universal Remote)


Twitter Delicious Facebook Digg Stumbleupon Favorites More