Anda di halaman 1dari 70

Experiment No.

1 Date:12/06/2012

Blinking of LEDs connected to a port


Aim: To write an assembly language program to blink all the LEDs connected to port P1 and download the executable file in to an 89S52 based development board.

Program org 000h start: mov P1,#0f0h call delay mov P1,#0fFh call delay sjmp start delay: mov r0,#0ffh loop: mov r1,#0ffh djnz r1,$ djnz r0,loop ret end

Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.2 Date:14/06/2012

Blinking of an LED (using timer for the delay)


Aim: To write an assembly language program to blink an LED (using timer for the delay) connected to port P1 and download the executable file in to an 89S52 based development board. Program LED equ P1.0 org 000H

sjmp MAIN org 00bH

cpl LED mov TH0, #04bh mov TL0, #0fdh clr TF0 reti MAIN:mov TMOD,#001H mov TH0, #04bh mov TL0, #0fdh setb EA setb ET0 setb TR0 jmp $ end Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.3 Date:19/06/2012

Interfacing of Buzzer
Aim: To write an assembly language program to interface a buzzer and download the executable file in to an 89S52 based development board.

Program org 000h start: clr P1.4

call delay setb P1.4 call delay sjmp start delay: mov r0,#0ffh loop: mov r1,#0ffh djnz r1,$ djnz r0,loop ret end

Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.4 Date:21/06/2012

Interfacing of Relay
Aim: To write an assembly language program to interface a relay and download the executable file in to an 89S52 based development board.

Program org 000h SJMP MAIN delay: mov r0,#0ffh loop: mov r1,#0ffh djnz r1,$ djnz r0,loop ret main: clr P1.5 call delay setb P1.5 call delay jmp main end

Result The program has written, executed by an 89S52 microcontroller and output verified

Experiment No.5 Date:26/06/2012

Interfacing of matrix keyboard


Aim: To write an assembly language program to interface matrix keyboard and download the executable file in to an 89S52 based development board.

Program LCD E RS RW data bit bit bit P0 P1.0 P1.2 P1.1

org 000h sjmp MAIN LCD_INIT: mov acall mov acall mov acall mov acall ret COMMAND:mov clr clr setb LCD,A RS RW E A,#38h COMMAND A,#0ch COMMAND A,#01h COMMAND A,#06h COMMAND

acall clr ret DATA_DISPLAY: mov setb clr setb acall clr ret MAIN:

DELAY E

LCD,A RS RW E DELAY E

mov P2,#0x78 acall LCD_INIT

REPEAT:

clr P2.0 setb P2.1 setb P2.2 call ROW1 setb P2.0 clr P2.1 setb P2.2 call ROW2 setb P2.0 setb P2.1 clr P2.2

call ROW3 jmp REPEAT ROW1: mov a,P2

anl a,#0x78 mov 0x0d,a xrl a,#0x78 jz RETURN1

call DELAY mov a,P2 anl a,#0x78 mov 0x0f,a xrl a,#0x78 jz RETURN1

mov a,0x0d xrl a,0x0f jnz RETURN1 mov a,0x0d xrl a,#0x70 jnz LAB2 mov A,#'a' acall DATA_DISPLAY sjmp DBOUN1 LAB2: mov a,0x0d xrl a,#0x68 jnz LAB3 mov A,#'b' acall DATA_DISPLAY sjmp DBOUN1 lab3: mov a,0x0d xrl a,#0x58

jnz lab4 mov A,#'c' acall DATA_DISPLAY sjmp DBOUN1 lab4: mov a,0x0d xrl a,#0x38 jnz DBOUN1 mov A,#'d' acall DATA_DISPLAY DBOUN1:call DBOUNCE RETURN1:ret ROW2: mov a,P2 anl a,#0x78 mov 0X0D,A xrl A,#0x78 jz RETURN2

call DELAY MOV A,P2 anl a,#0x78 mov 0X0F,A xrl A,#0x78 jz RETURN2

MOV A,0x0D XRL A,0x0F JNZ RETURN2 mov a,0x0d xrl a,#0x70

jnz LAB22 mov A,#'e' acall DATA_DISPLAY SJMP DBOUN2 LAB22: MOV A,0X0D XRL A,#0X68 JNZ LAB23 MOV A,#'f' acall DATA_DISPLAY SJMP DBOUN2 lab23: mov a,0x0d xrl a,#0x58 jnz lab24 mov A,#'g' acall DATA_DISPLAY SJMP DBOUN2 lab24: mov a,0x0d xrl a,#0x38 jnz DBOUN2 mov A,#'h' acall DATA_DISPLAY DBOUN2:CALL DBOUNCE RETURN2:ret ROW3: MOV A,P2 anl a,#0x78 mov 0X0D,A xrl A,#0x78

jz

RETURN3

CALL DELAY MOV A,P2 anl a,#0x78 mov 0X0F,A xrl A,#0x78 jz RETURN3

MOV A,0X0D XRL A,0x0F JNZ RETURN3 mov a,0x0d xrl a,#0x70 jnz LAB32 mov a,#'i' acall DATA_DISPLAY SJMP DBOUN3 LAB32:MOV A,0X0D XRL A,#0X68 JNZ LAB33 MOV A,#'j' acall DATA_DISPLAY SJMP DBOUN3 lab33: mov a,0x0d xrl a,#0x58 jnz lab34

mov A,#'k'

acall DATA_DISPLAY SJMP DBOUN3

lab34: mov a,0x0d xrl a,#0x38 jnz DBOUN3 mov A,#'l' acall DATA_DISPLAY

DBOUN3:CALL DBOUNCE RETURN3:ret DELAY: MOV R1,#0FFH DEL: MOV R2,#0FFH

DJNZ R2,$ DJNZ R1,DEL RET

DBOUNCE: SJMP L1 L3: MOV A,R7 XRL A,#0X78 ORL A,R6 JZ L2

L1:

MOV A,P2 ANL A,#0X78 MOV R7,A MOV R6,#0X00

SJMP L3 L2: RET END

Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.6 Date:28/06/2012

Interfacing of LCD
Aim: To write an assembly language program to interface LCD and download the executable file in to an 89S52 based development board.

Program

LCD E RS RW org

data bit bit

P0 P1.0 P1.2

bit P1.1 000H

LCD_INIT: mov A,#38h

acall COMMAND mov A,#0ch

acall COMMAND mov A,#01h

acall COMMAND mov A,#06h

acall COMMAND DISPLAY:mov A,#80h

acall COMMAND mov A,#'R'

acall DATA_DISPLAY

mov

A,#'I'

acall DATA_DISPLAY mov A,#'J'

acall DATA_DISPLAY mov A,#'O'

acall DATA_DISPLAY

HERE: sjmp HERE

DELAY:mov R0,#0ffh

L1:

mov R1,#0ffh djnz djnz ret R1,$ R0,L1

COMMAND: mov clr clr setb acall clr ret LCD,A RS RW E DELAY E

DATA_DISPLAY: mov LCD,A

setb clr setb acall clr ret end

RS RW E DELAY E

Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.7 Date:03/07/2012

Interfacing of 7 segment

Aim: To write an assembly language program to interface 7 segment and download the executable file in to an 89S52 based development board.

Program ORG 000H

AGAIN:

mov A,#71h mov P2,A acall DELAY mov A,#0b2h mov P2,A acall DELAY mov A,#0d3h mov P2,A acall DELAY mov A,#0e4h mov P2,A

acall DELAY jmp AGAIN

DELAY:

mov R0,#07h

L1:

mov R1,#0ffh djnz R1,$ djnz R0,L1 ret end

Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.8 Date:05/07/2012

Serial data Transmission


Aim: To write an assembly language program to transmit data serially and download the executable file in to an 89S52 based development board.

Program ORG 000H SJMP Serial_Txn Serial_Txn: mov TMOD,#20H mov SCON,#40H clr TF1 clr TR1 clr TI mov TH1,#0FDH mov TL1,#0FDH setb TR1 mov SBUF,#'R' jnb TI,$ clr TI mov TMOD,#20H mov SCON,#40H clr TF1 clr TR1 clr TI mov TH1,#0FDH mov TL1,#0FDH

setb TR1 mov SBUF,#'I' jnb TI,$ clr TI mov TMOD,#20H mov SCON,#40H clr TF1 clr TR1 clr TI mov TH1,#0FDH mov TL1,#0FDH setb TR1 mov SBUF,#'J' jnb TI,$ clr TI mov TMOD,#20H mov SCON,#40H clr TF1 clr TR1 clr TI mov TH1,#0FDH mov TL1,#0FDH setb TR1 mov SBUF,#'O' jnb TI,$ clr TI jmp $

end

Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.9 Date:10/07/2012

Serial data reception


Aim: To write an assembly language program to receive data serially and download the executable file in to an 89S52 based development board.

Program

org 000H sjmp Main org 0023H

INT_Rxn:

clr RI mov SBUF,SBUF jnb TI,$ clr TI reti

Main:

mov TMOD,#20H mov SCON,#50H mov IE,#90H

clr TF1 clr TR1

mov TH1,#0FDH mov TL1,#0FDH

setb TR1 jmp $ end

Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.10 Date:12/07/2012

External interrupt programming

Aim: To write an assembly language program to understand the int 0 interrupt using buzzer and download the executable file in to an 89S52 based development board.

Program

BUZ equ P1.4 org 000h sjmp MAIN org 0003h cpl BUZ clr IE0 reti MAIN: setb EA setb EX0 setb BUZ jmp $ end Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.11 Date:17/07/2012

Interfacing of RTC
Aim: To write an assembly language program to interface RTC and download the executable file in to an 89S52 based development board.

Program SCL SDA BIT BIT P3.5 P3.4 20H 22H 26H

BitCnt DATA VALUE DATA

SECOND DATA MINUTE

DATA 27H

HOUR DATA 28H DAY MONTH DATA 2AH DATA 2BH

YEAR DATA 2CH CNT DATA 2DH

SEC_HIGH DATA 2EH SEC_LOW DATA 2FH HR_HIGH DATA HR_LOW DATA 30H 31H

MIN_HIGH DATA 32H MIN_LOW DATA 33H

YEAR_HIGH DATA 34H YEAR_LOW DATA 35H

MON_HIGH DATA 36H MON_LOW DATA 37H DAY_HIGH DATA 38H DAY_LOW org 0000h ljmp MAIN micro10:nop nop nop nop nop nop nop nop ret I2C_Start: SETB ACALL SETB ACALL CLR ACALL CLR ACALL RET I2C_Stop: CLR NOP NOP SDA SCL micro10 SDA micro10 SDA micro10 SCL micro10 DATA 39H

NOP SETB ACALL ACALL SETB acall RET I2C_Write: MOV MOV I2C_Write_Loop: clr SCL NOP RLC JNC SETB JMP LAB1: LAB2: CLR NOP nop nop nop nop nop nop nop nop nop SDA LAB2 SDA A LAB1 R1,A BitCnt,#08H SCL micro10 micro10 SDA micro10

setb

SCL micro10 BitCnt,I2C_Write_Loop

ACALL DJNZ NOP NOP clr call

SCL micro10 I2C_Ack_Read

ACALL JnC

label I2C_Stop I2C_Start I2C_Write

ACALL ACALL SJMP Label: RET

I2C_Ack_Read: setb scl nop nop nop nop nop MOV nop nop nop nop CLR call SCL micro10 C,SDA

RET I2C_Read_Dummy: SETB CLR MOV I2C_Read_Loop: CLR NOP NOP nop nop nop nop nop nop MOV RLC nop nop nop SETB ACALL DJNZ CLR ACALL MOV RET SCL micro10 BitCnt,I2C_Read_Loop SCL micro10 VALUE,A C,SDA A SCL SDA A BitCnt,#08H

DEL_10MS: MOV r0,#012H L1: MOV r2,#000H DJNZ r2,$ DJNZ r0,L1 RET RET I2C_Ack_Write: clr NOP clr acall acall SETB acall CLR acall nop nop nop RET I2C_Nack_Write: clr NOP NOP NOP NOP SETB SDA SCL SDA micro10 micro10 SCL micro10 SCL micro10 SCL

acall SETB acall CLR acall clr acall SETB nop nop nop RET I2C_Read: ACALL ACALL RET I2C_Read_Last: ACALL ACALL acall RET

micro10 SCL micro10 SCL micro10 SDA micro10 SCL

I2C_Read_Dummy I2C_Ack_Write

I2C_Read_Dummy I2C_Nack_Write I2C_Stop

RTC_WRITE:ACALL I2C_Start MOV A,#0XD0 ACALL I2C_Write MOV A,#0X00 ACALL I2C_Write MOV A,#0X00 ACALL I2C_Write ACALL I2C_Stop

RET RTC_READ: ACALL I2C_Start MOV A, #0XD0 ACALL I2C_Write MOV A, #0X00 ACALL I2C_Write ACALL I2C_Start MOV A,#0XD1 ACALL I2C_Write LABEL1: ACALL MOV INC I2C_Read @R0,VALUE R0

DJNZ CNT,LABEL1 LCALL MOV RET RTC_init_read:ACALL I2C_Start MOV A, #0XD0 ACALL I2C_Write MOV A, #0X00 ACALL I2C_Write ACALL I2C_Start MOV A,#0XD1 ACALL I2C_Write ACALL RET UART: CLR SM0 I2C_Read_Last I2C_Read_Last YEAR,VALUE

setb SM1 MOV TMOD,#020H CLR TF1 CLR TR1 CLR TI MOV TH1,#0FDH SETB TR1 RET MAIN: ACALL UART acall RTC_init_read MOV A,VALUE XRL A,#0X80 JNZ REPEAT ACALL RTC_WRITE ACALL DEL_10MS REPEAT: MOV MOV R0,#026H CNT,#06H

ACALL RTC_READ MOV A,YEAR ANL A,#0X70 SWAP A ADD A,#'0' MOV YEAR_HIGH,A MOV A,YEAR ANL A,#0X0F ADD A,#'0' MOV YEAR_LOW,A

MOV A,MONTH ANL A,#0X70 SWAP A ADD A,#'0' MOV MON_HIGH,A MOV A,MONTH ANL A,#0X0F ADD A,#'0' MOV MON_LOW,A MOV A,DAY ANL A,#0X70 SWAP A ADD A,#'0' MOV DAY_HIGH,A MOV A,DAY ANL A,#0X0F ADD A,#'0' MOV DAY_LOW,A MOV A,HOUR ANL A,#0X70 SWAP A ADD A,#'0' MOV HR_HIGH,A MOV A,HOUR ANL A,#0X0F ADD A,#'0' MOV HR_LOW,A

MOV A,MINUTE ANL A,#0X70 SWAP A ADD A,#'0' MOV MIN_HIGH,A MOV A,MINUTE ANL A,#0X0F ADD A,#'0' MOV MIN_LOW,A MOV A,SECOND ANL A,#0X70 SWAP A ADD A,#'0' MOV SEC_HIGH,A MOV A,SECOND ANL A,#0X0F ADD A,#'0' MOV SEC_LOW,A MOV SBUF,HR_HIGH JNB TI,$ CLR TI MOV SBUF,HR_LOW JNB TI,$ CLR TI MOV SBUF,#':' JNB TI,$ CLR TI

MOV SBUF,MIN_HIGH JNB TI,$ CLR TI MOV SBUF,MIN_LOW JNB TI,$ CLR TI MOV SBUF,#':' JNB TI,$ CLR TI MOV SBUF,SEC_HIGH JNB TI,$ CLR TI MOV SBUF,SEC_LOW JNB TI,$ CLR TI MOV SBUF,#'-' JNB TI,$ CLR TI MOV SBUF,DAY_HIGH JNB TI,$ CLR TI MOV SBUF,DAY_LOW JNB TI,$ CLR TI MOV SBUF,#'\' JNB TI,$ CLR TI

MOV SBUF,MON_HIGH JNB TI,$ CLR TI MOV SBUF,MON_LOW JNB TI,$ CLR TI MOV SBUF,#'\' JNB TI,$ CLR TI MOV SBUF,YEAR_HIGH JNB TI,$ CLR TI MOV SBUF,YEAR_LOW JNB TI,$ CLR TI MOV SBUF,#0X0D JNB TI,$ CLR TI JMP REPEAT END Result The program has written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Experiment No.12 Date:19/07/2012

PWM Generation

Aim: To write an assembly language program to generate PWM and download the executable file in to an 89S52 based development board.

Program PWMPIN equ P3.6 org 000H SJMP MAIN org 000BH TIMER_0_INTERRUPT: jb F0, HIGH_DONE LOW_DONE: setb F0 setb PWMPIN mov TH0, R7 mov TL0, R6 clr TF0 reti HIGH_DONE:clr F0 clr PWMPIN mov A, #0FFH clr C

subb A, R7 mov TH0, A mov A, #0FFH clr C subb A, R6 mov TL0, A clr TF0 reti MAIN: mov TMOD,#001H mov R7, #04bh mov R6, #0b7h setb EA setb ET0 setb TR0 jmp $ end Result The program has written, executed by an 89S52 microcontroller and output verified

C-PROGRAMMING

Exp No: 1 05/06/12

Blinking of LEDs connected to a port Aim:


To write a C program to blink all the LEDs connected to port P1 and download the executable file in to an 89S52 based development board. Program #include <reg52.h> void msdelay(unsigned int t) { unsigned int i,j; for(i=0;i<t;i++) for(j=0;j<1275;j++); } void main() { while(1) { P1=0X0F; msdelay(250); P1=0X00; msdelay(250); } }

Result

The program was written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Exp No: 2 07/06/12

Blinking of an LED (using timer for the delay) Aim:


To write a C program to blink an LED connected to port P1.4 ,with the time delay predefined using timer and download the executable file in to an 89S52 based development board. Program #include <reg52.h> void delay(void); sbit p=P1^4; voidmain (void) { while(1) { p=~p; delay(); } } void delay() { TMOD=0X01; TL0=0XFd; TH0=0X4B; TR0=1; while(TF0==0);

TR0=0; TF0=0; } Result The program was written, executed by an 89S52 microcontroller and output verified

Circuit Diagram

Exp No: 3 12/06/12

Interfacing of Buzzer Aim:


To write a C program to interface a buzzer and download the executable file in to an 89S52 based development board.

Program #include <reg52.h> void delay(void); sbit p=P1^4; voidmain (void) { while(1) { p=~p; delay(); } } void delay() { TMOD=0X01; TL0=0XFd; TH0=0X4B; TR0=1; while(TF0==0);

TR0=0; TF0=0; }

Result The program was written, executed by an 89S52 microcontroller and output verified.

Circuit Diagram

Exp No: 4 14/06/12

Interfacing of LCD Aim:


To write a C program to interface an LCD and download the executable file in to an 89S52 based development board. Program #include<reg52.h> sfr ldata=0x80; sbit rs=P1^2; sbit rw=P1^1; sbit en= P1^0;

void lcdcmd (unsigned char value); void lcddata(unsigned char value); void msdelay(unsigned int t); void main() { lcdcmd(0x38); msdelay(250); lcdcmd(0x0c); msdelay(250); lcdcmd(0x01); msdelay(250); lcdcmd(0x06); msdelay(250);

lcdcmd(0x80); msdelay(250); lcddata('g'); msdelay(250); lcddata('o'); msdelay(250); lcddata('d'); msdelay(250); } void lcdcmd (unsigned char value) { ldata=value; rs=0; rw=0; en=1; msdelay(1); en=0; return; } void lcddata(unsigned char value) { ldata=value; rs=1; rw=0; en=1; msdelay(1); en=0; return;

} void msdelay(unsigned int t) { unsigned int i,j; for(i=0;i<t;i++) for(j=0;j<1275;j++); }

Result The program was written, executed by an 89S52 microcontroller and output verified.

Circuit Diagram

Exp No: 5 19/06/12

Interfacing of 7 segment Display Aim:


To write a C program to interface an LCD and download the executable file in to an 89S52 based development board. Program #include<reg52.h> void main (void) { while(1) { P2 = 0x071; void delay(); P2 = 0x0B2; void delay(); P2 = 0x0D3; void delay(); P2 = 0x0E4; void delay(); }
void delay() { TMOD=0X01; TL0=0XFd; TH0=0X4B; TR0=1; while(TF0==0);

TR0=0; TF0=0; }

Result The program was written, executed by an 89S52 microcontroller and output verified.

Circuit Diagram

Exp No: 6 21/06/12

Serial data Transmission Aim:


To write a C program transmit data serially and download the executable file in to an 89S52 based development board. Program #include <reg52.h> void main(void) { TMOD=0X20; TH1=0XFD; SCON=0X40; TR1=1; while (1) { SBUF='B'; while(TI==0); TI=0; } } Result The program was written, executed by an 89S52 microcontroller and output verified.

Circuit Diagram

Exp No: 7 26/06/12

Serial data Reception Aim:


To write a C program receive data serially and download the executable file in to an 89S52 based development board. Program #include <reg52.h> void main(void) unsigned long int a; { TMOD=0X20; TH1=0XFD; SCON=0X40; TR1=1; RI = 0; while (1) { a = SBUF; while(TI==0); TI=0; } } Result The program was written, executed by an 89S52 microcontroller and output verified.

Circuit Diagram

Exp No: 8 28/06/12

External Interrupt Programming Aim:


To write a C program transmit data serially and download the executable file in to an 89S52 based development board. Program #include <reg52.h> sbit intr = P3^2; void main() { unsigned int x,i,j; P3 = 0XFF; while (1) { if ( intr == 1) { P2 = P2; } else { x= P2; for (i=0;i<30000;i++); for (j =0;j<10000;j++); x = x + 1; P2 = x;}}+} Result The program was written, executed by an 89S52 microcontroller and output verified.

Circuit Diagram

Anda mungkin juga menyukai