Saturday, August 27, 2011

WAP for 8051 to transfer letter 'A' serially continuously


START : MOV A, #'A' ; ASSIGN A WITH SERIAL DATA
; P1.1 IS USED
MOV R7, #08H ; COUNTER OF 8 AS ACCUMULATOR OF 8 BIT
BACK : RRC A ; ROTATE BITS THROUGH CY
MOV P1.1, C ; TRANSFER CONTENTS OF CARRY TO PORT PIN
DJNZ R7, BACK ;
SJMP START ;
END

A Switch is connected to P1.7. WAp to check status of switch and perform the following


; A Switch is connected to P1.7.  WAp to check status of switch and ;perform the following
; 1 if switch = 0, send letter 'N' to P2
; 2 if switch = 1, send letter 'Y' to P2


START : JNB P1.7, ONN ;
MOV P2, #'y' ;
SJMP START ;
ONN :   MOV P2, #'n' ;
SJMP START ;
END

WAP in 8051 to perform the following


; WAP to perform the following
; 1. keep monitoring P1.2 until it becomes high
; 2. when P1.2 becomes high write value 45h on P0
; 3. Sent a high to low pulse to P2.3


HERE : JNB P1.2, HERE ;
MOV P0, #45H ;
SETB P2.3 ;
CLRB P2.3 ;
SJMP HERE ;
END

WAP in 8051 to sort a block of data in ascending or descending order


; PROGRAM STARTS HERE


MOV R6, #07H ; EXTERNAL COUNTER
START : MOV R7, #07H ; INTERNAL COUNTER
MOV R0, #30H ; INTERNAL MEMORY ADDRESS
MOV A, #00H ; CLEAR ACCUMULATOR
; CY = 0 A>VAL
; CY = 1 A<VAL
BACK :   MOV A, @R0 ;
INC R0 ;
CJNE A, @R0, CARRY ;
SJMP DECREMENTC ;
CARRY : JC DECREMENTC ;
MOV B, @R0 ;
MOV @R0, A ;
DEC R0 ;
MOV A, B ;
MOV @R0, A ;
DECREMENTC : INC R0 ;
DJNZ R7, BACK ;
DJNZ R6, START ;
END

WAP in 8051 to transfer block of data from internal memory location to external memory location


; PROGRAMM STARTS HERE
MOV R0, #30H ; STORE MEMORY LOCATION
MOV A, #00H ; CLEAR ACCUMULATOR
MOV R7, #07H ; COUNTER
MOV DPTR, #0200H; EXTERNAL ADDRESS
BACK :  MOV A, @R0 ; MOVE FROM INTERNAL TO ACCUMULATOR
MOVX @DPTR, A ; MOVE FROM ACCUMULATOR TO EXTERNAL ADDRESS
INC R0 ; INCREMENT INTERNAL ADDRESS
INC DPTR ; INCREMENT EXTERNAL ADDRESS
DJNZ R7, BACK ; COUNT THE LOOP
END

WAP in 8051 to add block of data stored in internal/external memory location


; FOR INTERNAL MEMORY
MOV R0, #30H ; STORE INTERNAL MEMORY ADDRESS IN RO
MOV A, #00H ; CLEAR ACCUMULATOR
MOV R7, #07H ; COUNTER REGISTER
BACK : ADD A,@R0 ;
INC R0 ; NEXT VALUE
DJNZ R7, BACK ;
END




; FOR EXTERNAL MEMORY
MOV DPTR, #0200H; STORE EXTERNAL MEMORY ADDRESS IN R0
MOV A, #00H ; CLEAR ACCUMULATOR
MOV R7, #00H ; SUM REGISTER
MOV R6, #07 ; COUNTER REGISTER
BACK : MOVX A, @DPTR ;
ADD A, R7 ;
MOV R7, A ;
INC DPTR ;
DJNZ R6, BACK ;
END

Saturday, August 13, 2011

GENERALIZATION OF FARADAYS EXPERIMENTS WITH CONCENTRIC SPHERES

The results of Faraday experiments with concentric spheres can be summed up as an experimental law by stating that the electric flux passing through any imaginary sphere placed between two conducting sphere is equal to the charge enclosed within the surface of imaginary sphere. This enclosed charge is distributed either on the surface of the imaginary sphere or is located at a point at the center of the imaginary sphere.


However since 1 C of charge produces 1 C of electric flux, the inner conductor might just well have been a cube or a pot shaped conductor, but still the charge on the outer sphere will be the same. Of Course the flux density would change from its symmetrical distribution to an unknown configuration, but +Q C on any inner conductor will induced a –Q C of charge on surrounding sphere. Going a step further replacing outer sphere with a cylindrical conductor and inner sphere with a pot shaped conductor with charge Q. Producing Flux = Q C the induced charge in the cylindrical conductor will be –Q C. How Fascinating right??


This generalization lead to many developments one of them is discussed later in the next post. All the experiments performed by faraday on electromagnetism is a must read for every engineer. He gave us modern electromagnetics which is used almost in every hardware. I would try to post all his experiments, conclusions and generalization details on the site but self reading is the best reading.


The post here under category Electromagnetics is taken from my college blog. They are updated here first by me then brought to this site again by me.

Assume that the lower three bits of P1 are connected to three switches. Write a program to send the following ASCII characters to P2 based on the status of the switches.


;
; SWITCH STATUS AS FOLLOWS
; 000 ‘0’
; 001 ‘1’
; 010 ‘2’
; 011 ‘3’
; 100 ‘4’
; 101 ‘5’
; 110 ‘6’
; 111 ‘7’
;
;
; WE WILL DEFINE BYTE LATER IN THE PROGRAM 


ORG 0000H ;
MOV DPTR, 300H ;
MOV A, P1 ; GET STATUS OF P1
ANL A, 07H ; MASK ALL BUT LOWER 3 BITS
MOV A, @A+DPTR  ; GET CORRESPONDING VALUE
MOV P2, A ; MOVE VALUE TO P2 DISPLAY IT




ORG 0300H  ;
DB '0','1','2','3','4','5','6','7';
END

Single bit operation with Carry


Instruction
Function
SETB C
Make CY = 1
CLR C
Clear CY bit
CPL C
Complement CY bit
MOV b, C
Copy carry status to bit
MOV C, b
Copy bit location status to carry
JNC TARGET
Jump to target when CY = 0
JC TARGET
Jump to target when CY = 1
ANL C, bit
AND CY with bit and save it on CY
ANL C, /bit
AND CY with inverted bit and save it on CY
ORL C, bit
OR CY with bit and save it on CY
ORL C, /bit
OR CY with inverted bit and save it on CY

Write a program to bring in a byte of data serially one bit at a time via pin P2.7 and save it in register R2. The byte comes in with the LSB first.

; INITIALIZE A COUNTER REGISTER
MOV R0,#08h       ;
LOOP: MOV C,P2.7  ; BRING IN BIT
RRC A             ;
DJNZ R0,LOOP      ; LOOP TILL ALL 8 BITS ARE IN
END 
; END OF PROGRAM

Electric Field Intensity

Consider a fixed charge Q1. Let us move a second charge say test charge Qt around the Q1. We observe that the test charge Qt experiences force everywhere around Q1. It is experiencing a force field. Force on it will be given by coulombs law as:

But still question arises what is Electric Field?? Before defining electric field let us modify above equation a bit.
Let us write the above equation as force/charge equation:

This quantity that is force/charge describes a vector quantity. This vector quantity is called Electric Field Intensity.So Electric field intesity is defined as the vector force on an unit positive test charge by a fixed charge Q1. Or it can also be defined as force per unit charge.
So to sum it up we can Electric field intensity as:

So it becomes.

Expressing Electric field in cartesian Coordinate:

Expressing Electric Field in Spderical Co-ordinates:
First for considering spherical co ordinate we must see that fixed charge has spherical symmetry at its location like at origin(0,0,0) for that we can either use spherical co-ordinate directly in equation as:

Where Er and r spherical co-ordinates values or we can convert them in cartesian coordinate which will give us the equation as below:
We will have r = R = xi + yj +zk ar = aR = (xi + yj + zk)/√(x^2+y^2+z^2 )

If more charges are added in the surrounding of Q1 then electric field will be sum of individual acting alone. As shown in equation given below:



Before ending the topic let us do a small quick example.
Example: See the figure below. We need to find out Electric field at P(1,1,1) caused by 4 identical 3nC charges located at P1(1,1,0), P2(-1,1,0), P3(-1,-1,0) and P4(1,-1,0).


Electric Field Example
Example of Electric field
[caption id="" align="alignnone" width="615" caption="Example of Electric Field"][/caption]


Answer: As r = i + j + k and r1 = i+j therefore r – r1 = k. Therefore |r – r1| = 1.
Similaraly r – r2 = 2i + k. therefore |r – r2| = √5
Similaraly r – r3 = 2i + 2j + k. therefore |r – r3| = 3
Similaraly r – r4 = 2j + k. therefore |r – r4| = √5
And as




Therefore simplifying we get E =
E = 6.82i + 6.83j + 32.8k V/m ans.

The Coulombs Law

Columbs law state that the force between two small objects seperated in a vaccum by distance much greater that the size of each object is proportional to the product of charges on them and inversely proportional to square of distance between them.

where Q1 and Q2 are positive or negative charge quantity measured in columbs and R is the distance between them measured in meters. Here k is proportionality constant given as:

Again another constant € is called permittivity of free space. Measured in Farad per meter(F/m).

The above quantity is not dimensionless. For coulombs law dimensions are C2/N.m2 . This means Farad has units C2/N.m .This makes are coulombs law as:



VECTOR FORM OF COULOMBS LAW:


[caption id="" align="alignnone" width="349" caption="Vector form of Coulombs law"]Vector form of Coulombs law[/caption]


Let us say charges Q1 and Q2 are like charges distance of each from origin be r1 and r2 respectively. As F2 is in direction of R12. The vector R12 is cleary
R12 = r2 – r1.
Therefore the vector form of coulombs law is:

Where a12 is a unit vector in direction of R12 or we can say:



Let us finish this topic with an example.
Example: let umm. There be 2 charges say Q1 = 3 x 10^(-4) C located at say M(1,2,3) and Q2 = 10^(-4) C located at say L(2,0,5). We require to find force exerted by Q2 on Q1.
Answer: Let F2 = force exerted by Q2 on Q1.
Vector R12 = r2 – r1 = (2 - 1)i + (0 – 2)j + (5 – 3)k = i – 2j + 2k
This gives us |R12| = 3
Which again gives as unit vector

Therefore our F2



F2 = 10i – 20j + 20k N ans.
Therefore we found out F2 that is force of Q2 on Q1. Similary we can find F1 that is force of Q1 on Q2. Interestingly as both charges are like charges. We will find out that



Coulombs law is linear. We can see that multiplying Q1 by some factor n. We find that the force between the 2 charges also get multiplied by factor n.
Another thing is that the force on the charge in presence of the other charges is sum of forces on that charge due to each of the other charges acting alone.

Monday, August 8, 2011

Assembly language program for sum of data in Array

; ADDING DATA IN ARRAY
; IN SIMPLE TERMS SUM OF ARRAY
; STORING ARRAY IN ROM
ORG 300H        ;
DB 1,4,5,6,7    ;
; ARRAY OF 5
ORG 0000H       ;
; INITIALIZE DATA POINTER
MOV DPTR, #0300H;
; FIRST COUNTER
MOV R7, #05H    ;
; RESETING A
MOV A, #00H     ;
; COUNTER REGISTER FOR ROM ACCESS
MOV R0, #00H    ;
; SUM VARIABLE
MOV R6,#00H     ; 
LOOP:
MOV A, R0       ;
MOVC A,@A+DPTR  ;
ADD A, R6       ;
MOV R6,A        ;
INC R0          ;
DJNZ R7, LOOP   ;
END

Assembly program for Simple 2 16bit number addition using registers

; 16 BIT ADDITION
ORG 0000H      ;
; SAY R7 HAS LOWER BYTE 34
; R6 HAS HIGHER BYTE 24
; MAKING NUMBER 2434
MOV R7, #34H   ;
MOV R6, #24H   ;
; ANOTHER NUMBER SAY 3345
; WITH R5 LOWER BYTE 45
; R4 HIGHER BYTE 33
MOV R5,#45H    ;
MOV R4, #33H   ;
; NOW ADDING
MOV A, R5      ;
; ADDING LOWER BYTE
ADD A , R7     ;
MOV R3, A      ;
; R3 BEING LOWER BYTE OF ANSWER
MOV A, R6      ;
; NOW ADD WITH CARRY
ADDC A, R4     ;
MOV R2,A       ;
END

Moving block of data from ROM to RAM

; MOVING BLOCK OF DATA
ORG 0000H       ;
; NEED TO TAKE DATA FROM ROM TO RAM
; FROM 300 TO 302 TO 30 TO 32
; DEFINING DATA POINTER
MOV DPTR, #0300H;
; RESETING A
MOV R2, #00H    ; COUNTER REGISTER
MOV R0, #30H    ;
MOV A, #00H     ;
; AS 3 DATAS SO LOOP OF 3
MOV R7, #03H    ;
LOOP:
MOV A, R2       ;
MOVC A, @A+DPTR ;
MOV @R1,A       ;
MOV R1,A        ;
INC R2          ;
INC R1          ;
DJNZ R7, LOOP   ;
; STORING DATA AT ROM
; SAY FROM 300 TO 302
ORG 300H        ;
DB 'ABC'        ;
END

Friday, August 5, 2011

8085 Interrupts Summary Tables


Interrupt Name
Maskable
Masking Method
Vectored
Memory
Triggering Method
INTR
Yes
DI / EI
No
No
Level Sensitive
RST 5.5 / RST 6.5
Yes
DI / EI
SIM
Yes
No
Level Sensitive
RST 7.5
Yes
DI / EI
SIM
Yes
Yes
Edge Sensitive
TRAP
No
None
Yes
No
Level & Edge Sensitive

In a semester student has to take 4 courses. The marks of student out off say 30 are stored in RAM location 30h. Find average marks and output it in port1.




MOV R1, #04 ; R1 NUMBER OF COURSES FOR COUNTING
MOV B, #O4 ; B AGAIN NUMBER OF COURSES FOR DIVISION
MOV R0, #30H ; RAM STARTING ADDRESS
MOV A, #0 ;
LOOP: ADD A, @R0 ; WHERE @R0 REFERS TO DATA AT LOCATION 30H
INC R0 ;
DJNZ R1, LOOP ; REPEAT ADDITION UNTIL R1 = 0
DIV AB ; CAUSE ONLY DIVISION OPERATION AVAILABLE
MOV P1, A ; IGNORE REMAINDER AND OUTPUT PORT 1 THE AVERAGE

END ; END OF PROGRAM