You are on page 1of 24

E MBEDDED S YSTEM

D ESIGN
LAB FILE

Rohit Sharma
05/ECE/145
INDEX

S. NO. EXPERIMENTS

1. Write an Assembly language Programme (ALP) to generate 10 kHz


square wave for 8051.

2. Write an Assembly Language Program to generate a square wave of 10


KHz using timer register in 8051.

3. Write an Assembly Language Program to glow 8 LEDs one by one in


serial order after a delay of 70ms.

4. To Study the Development Tools / Environment for Microcontroller


Programme.

5. To write an ALP for DAC Embedded trainer for PIC 16f877 - module DAC.

6. To write an ALP to glow alternate LEDs using embedded trainer for PIC
16F877 - module even LEDs.

7. To write an ALP for PWM based speed control of motor using embedded
trainer for PIC 16F877 - PWM controlled DCM at RC2.

8. To write an ALP for seven segment display using embedded trainer for PIC
16F877 – module seven segment display.

9. To write an ALP to control stepper motor using embedded trainer for PIC
16F877 – module stepper motor.
EXPERIMENT NO.1

AIM: Write an Assembly language Programme (ALP) to generate 10 kHz square wave for 8051

MAIN: SETB P1.0


LCALL DELAY
CLR P1.0
LCALL DELAY
SJMP MAIN

DELAY: MOV R1, #10H


NOP
NOP
NOP
HERE: DJNZ R1, HERE
RET

Note:

Address of P1.0 is 90H


OUTPUT
EXPERIMENT NO.2

AIM: Write an Assembly Language Program to generate a square wave of 10 KHz using timer register
in 8051.

MOV TMOD, #10H


MAIN: MOV TL1, #0D2H
MOV TH1, #0FFH
SETB TR1
HERE: JNB TF1, HERE
CLR TR1
CPL P1.0
CLR TF1
SJMP MAIN

Note:

Name of Register/Pin Address


TMOD 89H
TL1 8BH
TH1 8DH
TR1 8EH
TF1 8FH
P1.0 90H
OUTPUT
EXPERIMENT NO. 3

AIM: Write an Assembly Language Program to glow 8 LEDs one by one in serial
order after a delay of 70ms.

MAIN: MOV TMOD, #10H


MOV TL1, #00H
MOV TH1, #00H
MOV A, #01
HERE: MOV P1, A
LCALL DELAY
RL A
SJMP HERE

DELAY: SETB TR1


LAB: JNB TF1, LAB
CLR TR1
CLR TF1
RET
OUTPUT
EXPERIMENT NO. 4

AIM: To Study the Development Tools / Environment for Microcontroller Programme.

THEORY: MPLAB IDE is a software program that runs on a PC to develop applications for Microchip
microcontrollers. It is called an Integrated Development Environment, or IDE, because it provides a
single integrated "environment" to develop code for an embedded microcontroller.
An IDE combines all of the required diff. functions into a single program that will allow us to edit,
assemble or compile, simulate, emulate, & program our application. The IDE is typically centered on the
editor & uses the source code window to reference back syntax errors for the assembler & compilers &
allow us to easily follow the exeecution of the program.

Development tools used for microcontroller are:

INTEGRATED DEVELOPMENT SYSTEM

EMULATORS SIMULATORS LOGIC TARGET


ANALYSER SYSTEM
PERFOR

SIMULATOR EDITOR LOADER LINKER

ASSEMBLER & COMPILER


CROSS ASSEMBLER

Figure 1) A List of an IDE System & Tools


EMULATOR: An Emulator is a piece of hardware that is placed into an application circuit to allow us
to run &observe the operation of the application without going through the hassle of developing
stimulus files. An emulator is an excellent tool for determining whether or not we have correctly
modeled the hardware, the microcontroller interfaced to.

SIMULATOR: A Simulator is a program that simulates the microcontroller


processor (& , optionally the hardware connected to it ) to allow us to watch the execution of our
application to make sure it works properly before it is burned into acual hardware. The simulator is
integrated into MPLAB IDE integrated development environment. It allows us to:

• modify object code and immediately re-execute it


• inject external stimuli to the simulated processor
• set pin and register values at prespecified intervals
• trace the execution of the object code (MCU's only)

An INTERPRETER does expressaion by expression (line bu\yline) translation to the machine


executable code. On thwe other hand , a COMPILER use the complete sets of the expression. It may
also include the expressions from the library routines; i.e. standard tailor made program. While an
interpreter helps in online execution on the codes, acompiler helps in the offline programming for
obtaining the executable machine codes later. The C programs are used with an interpreter as well as
with a compiler. A high level language is machine independent.It will have an expression like X=X+11,
or X=2*Y+V*Z+23, etc. The C language needs a compiler. It is not executable using an interpreter. A
tool is needed by the machine codes for a target system. The tool may be provided in C.

The word mnemonic is used instead of expression or statement while we program in the assembly
language. A simulator has an assembler as an essential part of it. An assembly language has the
mnemonics that are machine dependent. Example of a mnemonic is ADC A,0BH. It means an
instruction that adds along with the previous carry the A register of the processor with the hexadecimal
number 0B. An assembly mnemonic is specific to a microcontroller. It has different symbolic form on
the different microcontrollers. It is as per the instructions provided in the instruction set. The assembly
mnemonic needs an interpreter to translate into the machine codes that are executed on a specific
microcontroller.

Using an EDITOR, the assembly language programmer writes the mnemonics. The keyboard of the PC
is for entering the program. The Editor has the following features. It allows the entry, addition, deletion,
insert, appending previously written lines or files, merging record and files at the specific positions, etc.
A source file stores the edited file. It also has an appropriate name. The latter iis given by the
programmer. An ASSEMBLER is a program that translates the assembly mnemonics into the binary
opcodes and instructions i.e., into executable file, called object file. It also creates a list file that can be
printed. The list file has address, source code (assembly language mnemonic), and object codes in
hexadecimal. The object file has addresses that are to be adjusted during actual run of the assembly
language program. A LOADER is a program that helps in the task by reallocating addresses before the
opcodes & operands load in the computer memory. A LINKER linkes the needed object code files &
library code files. This is before the loader reallocates the addresses in the memory, & the program runs
on the computer. A DISSEMBLER translates the object codes into the mnemonics form of assembly
language. It helps in understanding the previously made object codes. A CROSS ASSEMBLER is
useful to convert object codes for a microcontroller or processor to other codes for another
microcontroller or processor & vice versa. Cross assemblers let us use a processor of the PC of the
development system. It later on provides the object codes. These codes will actually be needed in the
finally developed system that will use another processor or microcontroller.

RESULT: The Study of Development Tools / Environment for microcontroller programme is done
successfully.
EXPERIMENT NO. 5

AIM: To write an ALP for DAC Embedded trainer for PIC 16f877 - module DAC.

Date: Oct, 2008

LIST P=16F877A
#INCLUDE "P16F877A.INC"
ORG 0000H
REG2: EQU 20H

ORG 0000H
GOTO START
ORG 0004H
RETFIE
ORG 0005H

START: BSF STATUS, RP0


BCF STATUS, RP1
MOVLW 00H
MOVWF `TRISC
MOVWF TRISD ; PORTC, PORTD AS OUTPUT PORTS

BCF STATUS, RP0


CLRF PIR1
CLRF CCP1CON
MOVLW 00H
MOVWF REG2 ; INITIALIZE COUNTER
START1:MOVF REG2,0
MOVWF PORTC ; OUT COUNTS ON DAC DATABUS
BCF PORTD, 5
BSF PORTD, 5
INCF REG2, 1 ; INCREMENT COUNTER
GOTO START1
END

;NAME:ROHIT SHARMA;ROLL NO.:05/ECE/145


;ESD LAB.

OUTPUT
EXPERIMENT NO. 6
AIM: To write an ALP to glow alternate LEDs using embedded trainer for PIC 16F877 - module
even LEDs

Date: Nov, 2008


LIST P=16F877A
INCLUDE "P16F877A.INC"
ORG 0000H

REG2: EQU 20H


DLY2: EQU 21H
DLY3: EQU 22H
PTR: EQU 23H
TEMP1: EQU 24H
TEMP2: EQU 25H

ORG 0000H
GOTO START
ORG 0004H
RETFIE
ORG 0005H

START: BSF STATUS, RP0


BCF STATUS, RP1
MOVLW 00H
MOVWF TRISC ; PORTC, PORTD AS OUTPUT PORTS
MOVWF TRISD

BCF STATUS, RP0


CLRF PIR1
CLRF CCP1CON
START1: MOVLW 055H
MOVWF PORTC
MOVWF PORTD ; GLOW ALTERNATE LEDS
CALL DELAY
MOVLW 0AAH
MOVWF PORTC
MOVWF PORTD ; GLOW REMAINING LEDS
CALL DELAY
GOTO START1

DELAY: MOVLW 0B0H


MOVWF DLY3
LOOP2: MOVLW 0FFH
MOVWF DLY2
LOOP1: DECFSZ DLY2, 1
GOTO LOOP1
DECFSZ DLY3, 1
GOTO LOOP2
RETURN
END
;NAME:ROHIT SHARMA;ROLLNO: 05/ECE/145;ESD LAB.
OUTPUT

EXPERIMENT NO.7
AIM: To write an ALP for PWM based speed control of motor using embedded trainer for PIC
16F877 - PWM controlled DCM at RC2

Date: Nov, 2008


LIST P=16F877A
#INCLUDE "P16F877A.INC"
ORG 0000H

REG2: EQU 20H


DLY2: EQU 21H
DLY3: EQU 22H
REG5: EQU 23H
TEMP1: EQU 24H
TEMP2: EQU 25H
REG3: EQU 26H
REG4: EQU 27H
ADCON0 EQU 1FH
ADCON1 EQU 9FH
PIR1 EQU 0CH
PIE1 EQU 8CH
INTCON EQU 0BH
ADRESH EQU 1EH
ADRESL EQU 9EH

ORG 0000H
GOTO START

ORG 0004H
RETFIE

ORG 0005H

START: BCF STATUS,RP1


BSF STATUS,RP0 ;SET BANK-1
MOVLW 0FFH
MOVWF TRISC ;PORTC INPUT PORTS
BCF TRISC,2 ;SET RC2 AS PWM O/P
BCF TRISC,0 ;SET RC0 AS RELAY O/P
MOVLW 0FFH
MOVWF PR2 ;SET PWM PERIOD

BCF STATUS,RP0 ;SET BANK-0


BSF PORTC,0 ;SET RELAY AS ON
MOVLW 07H
MOVWF CCPR1L ;SET 8 BIT PWM DUTY CYCLE
BCF CCP1CON,4 ;LSB1 BIT OF PWM DUTY CYCLE
BCF CCP1CON,5 ;LSB0 BIT OF PWM DUTY CYCLE
MOVLW 01H ;SET PWM FREQ FOR 3.83KHz
MOVWF TMR2 ;SET TIMER PRESCALE VALUE AS ‘1’
MOVLW 04H
MOVWF T2CON ;SET TIMER-2 ON
BSF CCP1CON,3 ;SET PWM MODE
BSF CCP1CON,2 ;SET PWM MODE
WAIT: GOTO WAIT

END

;TO RUN MOTOR CLOCKWISE OR ANTICLOCKWISE SET/RESET RCO BIT


;TO CHANGE THE SPEED OF MOTOR 06H DATA OUT AT CCPR1L FOR LOW
;SPEED & FFH DATA OUT AT CCPR1L FOR HIGH SPEED

;NAME: ROHIT SHARMA


;ROLL NO.: 05/ECE/145
;ESD LAB.

OUTPUT
EXPERIMENT NO. 8
AIM: To write an ALP for seven segment display using embedded trainer for PIC 16F877 - module
seven segment display.

Date: Nov, 2008

LIST P=16F877A
#INCLUDE "P16F877A.INC"
ORG 0000H

REG2: EQU 20H


DLY2: EQU 21H
DLY3: EQU 22H
PTR: EQU 23H
TEMP1: EQU 24H
TEMP2: EQU 25H

ORG 0000H
GOTO START
ORG 0004H
RETFIE
ORG 0005H

START:BSF STATUS,RP0
BCF STATUS,RP1
MOVLW 00H ;PORTA,PORTB,PORTC,PORTD AS OUTPUT
MOVWF TRISC
MOVWF TRISD
MOVWF TRISA
MOVWF TRISB

BCF STATUS,RP0
CLRF PIR1
CLRF CCP1CON
MOVLW 0FFH
MOVWF PORTC
MOVWF PORTD

INIT: MOVLW 0F9H


MOVWF PORTC
MOVLW 0F8H
MOVWF PORTD ;DISPLAY I
CALL DELAY
MOVLW 92H
MOVWF PORTC
MOVLW 0F9H
MOVWF PORTD ;DISPLAY S
CALL DELAY
MOVLW 8CH
MOVWF PORTC
MOVLW 0FAH
MOVWF PORTD ;DISPLAY P
CALL DELAY
MOVLW 87H
MOVWF PORTC
MOVLW 0FBH
MOVWF PORTD ;DISPLAY t
CALL DELAY
MOVLW 0AFH
MOVWF PORTC
MOVLW 0FCH
MOVWF PORTD ;DISPLAY r
CALL DELAY
MOVLW 0ABH
MOVWF PORTC
MOVLW 0FDH
MOVWF PORTD ;DISPLAY n
CALL DELAY
GOTO INIT

DELAY: MOVLW 4H
MOVWF DLY3
LOOP2: MOVLW 0FFH
MOVWF DLY2
LOOP1: DECFSZ DLY2,1
GOTO LOOP1
DECFSZ DLY3,1
GOTO LOOP2
RETURN
END

;NAME: ROHIT SHARMA


;ROLLNO.: 05/ECE/145
;ESD LAB.

OUTPUT
EXPERIMENT NO. 9
AIM: To write an ALP to control stepper motor using embedded trainer for PIC 16F877 - module
stepper motor

Date: Nov, 2008

;CONNECTION DETAILS:
;ORANGE=A,BROWN=B,YELLOW=C,BLACK=D & RED=GND

LIST P=16F877A
#INCLUDE "P16F877A.INC"
ORG 0000H

REG2: EQU 20H


DLY2: EQU 21H
DLY3: EQU 22H
PTR: EQU 23H
TEMP1: EQU 24H
TEMP2: EQU 25H

ORG 0000H
GOTO START
ORG 0004H
RETFIE
ORG 0005H

START: BSF STATUS,RP0


BCF STATUS,RP1
MOVLW 00H
MOVWF TRISC ;PORTC,PORTD AS PUTPUT PORTS
MOVWF TRISD

BCF STATUS,RP0
CLRF PIR1
CLRF CCP1CON
START1: MOVLW 05FH ;OUT 05 ON SPA,SPB,SPC,SPD
MOVWF PORTC
CALL DELAY
MOVLW 6FH ;OUT 06 ON SPA,SPB,SPC,SPD
MOVWF PORTC
CALL DELAY
MOVLW 0AFH ;OUT 0A ON SPA,SPB,SPC,SPD
MOVWF PORTC
CALL DELAY
MOVLW 9FH ;OUT 09 ON SPA,SPB,SPC,SPD
MOVWF PORTC
CALL DELAY
GOTO START1

DELAY: MOVLW 50H


MOVWF DLY3
LOOP2: MOVLW 0FFH
MOVWF DLY2
LOOP1: DECFSZ DLY2,1
GOTO LOOP1
DECFSZ DLY3,1
GOTO LOOP2
RETURN

END

;NAME: ROHIT SHARMA


;ROLL NO.: 05/ECE/145
;ESD LAB.
OUTPUT

You might also like