8051 interfacing manual_asm only

Upload: ajay-patil

Post on 10-Jan-2016

53 views

Category:

Documents


3 download

DESCRIPTION

interfacing of 8051

TRANSCRIPT

PROGRAM 1: LED INTERFACEDescription:LEDs are most commonly used in many applications for indicating the output. They find huge range of applications as indicators during test to check the validity of results at different stages. They are very cheap and easily available in a variety of shape, color and size.The principle of operation of LEDs is very easy. A Simple LEDs also serves as a basic display devices, it On and OFF state express meaning full information about a device. The common available LEDs have a 1.7v voltage drop that means when we apply above 1.7V, the diode conducts. The diode needs 10mA current to glow with full intensity. The following circuit describes how to glow the LEDs.LEDs can be interfaced to the microcontroller in either common anode or common cathode configuration. Here the LEDs are connected in common anode configuration because the common cathode configuration consumes more power.

ASSEMBLY CODEorg 0000hloop: clr p0.2 acall delay setb p0.2 acall delay sjmp loopdelay: mov r7,#100again_delay: djnz r7,again_delay retendC CODING#includesbit LED= P0^2;void delay( unsigned int a);void main(){ LED=0;while(1){ LED=0;delay(60);LED=1;delay(60);}}

void delay (unsigned int b){ unsigned int k;for(k=0;k 82h) ANL A, #0F0H ;mask it with 0fh (82h & f0h = 80h) MOV L, A ;save it at temp location l RET ;return ; move to port sub-routineMOVE_TO_PORT: MOV PORT, A ;put content of a to port SETB EN ;make en high ACALL DELAY ;call a short delay routine CLR EN ;clear en ACALL DELAY ;short delay RET ;return ; lcd command write sub-routine LCD_CMD: CLR RS ;clear rs, going to send command ACALL SEPARATOR ;separate the command and save to u and l MOV A, U ;copy u to a ACALL MOVE_TO_PORT ;move content of a to port MOV A, L ;copy l to a ACALL MOVE_TO_PORT ;move content of a to port RET ;return ; lcd data write sub-routine LCD_DATA: SETB RS ;rs=1, going to send data ACALL SEPARATOR ;separate the data and save to u & l MOV A, U ;copy u to a ACALL MOVE_TO_PORT ;send it to lcd MOV A, L ;copy l to a ACALL MOVE_TO_PORT ;send it to lcd RET ;return ;lcd initialization sub-routine INIT: ACALL DELAY ;some delay to lcd after power on ACALL DELAY MOV PORT, #20H ;send 20h to lcd to set 4 bit mode CLR RS ;after that we can use lcd_cmd SETB EN ;make en switching ACALL DELAY CLR EN MOV A, #28H ACALL LCD_CMD MOV A, #0CH ACALL LCD_CMD MOV A, #06H ACALL LCD_CMD MOV A, #01H ACALL LCD_CMD RET ; a delay sub-routine DELAY: MOV R0, #10HL2: MOV R1, #0FHL1: DJNZ R1, L1 DJNZ R0, L2 RET END

Assembly code; Reset Vector org 0000h mov a,#3ch acall command mov a,#0eh acall command mov a,#06h acall command mov a,#01h acall command mov a,#87h acall command mov a,#'H' acall datadis mov a,#'E' acall datadis mov a,#'L' acall datadis mov a,#'L' acall datadis mov a,#'O' acall datadis mov a,#'W' acall datadis mov a,#'E' acall datadis mov a,#'L' acall datadis mov a,#'C' acall datadis mov a,#'O' acall datadis mov a,#'M' acall datadis mov a,#'E' acall datadis mov a,#'I' acall datadis mov a,#5 acall command mov a,#1 acall commandhere1: sjmp here1command: acall ready mov p1,a clr p3.2 clr p3.3 setb p3.4 acall delay clr p3.4 retdatadis:acall ready mov p1,a setb p3.2 clr p3.3 setb p3.4 clr p3.4 ret ready: clr p3.4 mov p1,#0ffh clr p3.2 setb p3.3 wait: clr p3.4 setb p3.4 jb p1.7 ,wait clr p3.4 ret delay: mov r3,#255here2: mov r4,#255 mov r5,#255here3: djnz r5,here3here: djnz r4,here djnz r3,here2 ret end ONLY DISPLAY AJAY PATIL MESSAGE TO LCD PROGRAM

org 0000h mov dptr,#mycommc1: clr a movc a,@a+dptr acall commwrt acall delay jz send_data inc dptr sjmp c1 send_data:mov dptr,#mydatad1: clr a movc a,@a+dptr acall datawrt acall delay inc dptr jz again sjmp d1 again: sjmp againcommwrt: mov p1,a clr P3.2 clr P3.3 setb P3.4 acall delay clr P3.4 retdatawrt: mov p1,a setb P3.2 clr P3.3 setb P3.4 acall delay clr P3.4 acall delay mov dptr,#mycomm1 clr a movc a,@a+dptr acall commwrt acall delay retdelay: mov r3,#250here2: mov r4,#255here: djnz r4,here djnz r3,here2 ret

org 300hmycomm: db 38h,0eh,01,06,84h,0mydata: db "AJAY PATIL",0

mycomm1: db 18hEND ------------------------------------------------------------------------------------------------------------------------------------------------------- SCROLLING DISPLAY OF MESSAGE AJAY PATIL TO LCD PROGRAM

org 0000h mov dptr,#mycommc1: clr a movc a,@a+dptr acall commwrt acall delay jz send_data inc dptr sjmp c1 send_data:mov dptr,#mydatad1: clr a movc a,@a+dptr acall datawrt acall delay inc dptr jz again sjmp d1CONT: sjmp cont again: mov dptr,#mycomm1 clr a movc a,@a+dptr acall commwrt acall delay sjmp again

commwrt: mov p1,a clr P3.2 clr P3.3 setb P3.4 acall delay clr P3.4 retdatawrt: mov p1,a setb P3.2 clr P3.3 setb P3.4 acall delay clr P3.4 acall delay retdelay: mov r3,#250here2: mov r4,#255here: djnz r4,here djnz r3,here2 ret

org 300hmycomm: db 38h,0eh,01,06,84H,0mydata: db "AJAY PATIL ",0

mycomm1: db 18hEND

PRACTICAL 4:-Relay Interfacing to MicrocontrollerRelay DesignThere are only four main parts in a relay. They are Electromagnet Movable Armature Switch point contacts Spring

What is a relay ?A relay is usually an electromechanical device that is actuated by an electrical current. The current flowing in one circuit causes the opening or closing of another circuit. Relays are like remote control switches and are used in many applications because of their relative simplicity,long life, and proven high reliability. Relays are used in a wide variety of applications throughout industry, such as in telephone exchanges, digital computers and automation systems. Highly sophisticated relays are utilized to protect electric power systems against trouble and power blackouts as well as to regulate and control the generation and distribution of power. In the home, relays are used in refrigerators, washing machines and dishwashers, and heating and air-conditioning controls. Although relays are generally associated with electrical circuitry, there are many other types, such as pneumatic and hydraulic. Input may be electrical and output directly mechanical, or vice versa.How do relays work?All relays contain a sensing unit, the electric coil, which is powered by AC or DC current. When the applied current or voltage exceeds a threshold value, the coil activates the armature, which operates either to close the open contacts or to open the closed contacts. When a power is supplied to the coil, it generates a magnetic force that actuates the switch mechanism. The magnetic force is, in effect, relaying the action from one circuit to another. The first circuit is called the control circuit; the second is called the load circuit. There are three basic functions of a relay: On/Off Control, Limit Control and Logic Operation.On/Off Control: Example: Air conditioning control, used to limit and control a high powerload, such as a compressorLimit Control: Example: Motor Speed Control, used to disconnect a motor if it runs slower orfaster than the desired speedLogic Operation: Example: Test Equipment, used to connect the instrument to a number oftesting points on the device under testTypes of RelaysThere are two basic classifications of relays: Electromechanical and Solid State. Electromechanical relays have moving parts, whereas solid state relays have no moving parts. Advantages of Electromechanical relays include lower cost, no heat sink is required, multiple poles are available, and they can switch AC or DC with equal ease.

C-DODE#includevoid delay(int a);void main (){P2=0x00;while(1){P2=0x01;delay(6000); P2=0X00;delay(6000);}}void delay(int a){ int i; for(i=0;i