0% found this document useful (0 votes)
80 views13 pages

Assignment No. 1 Embedded Systems and Design

This document contains an assembly language assignment submitted by Deberjeet Usham. It includes responses to 5 questions asking to write assembly language programs. The programs include counting even numbers, finding the maximum value in an array, generating periodic interrupts, displaying numbers on a 7-segment LED, and writing a subroutine to generate 7-segment display codes. Flowcharts and assembly code are provided for each question.

Uploaded by

deberjeet usham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views13 pages

Assignment No. 1 Embedded Systems and Design

This document contains an assembly language assignment submitted by Deberjeet Usham. It includes responses to 5 questions asking to write assembly language programs. The programs include counting even numbers, finding the maximum value in an array, generating periodic interrupts, displaying numbers on a 7-segment LED, and writing a subroutine to generate 7-segment display codes. Flowcharts and assembly code are provided for each question.

Uploaded by

deberjeet usham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

ASSIGNMENT No. 1
EMBEDDED SYSTEMS AND DESIGN

Q1. Write an Assembly Language Program to count number of even numbers from a set of
Ten 8-bit numbers stored at successive memory location starting from 0x10 H.

Ans:
FLOW CHART:

1
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

ASSEMBLY LANGUAGE PROGRAM:


VARIABLE DEFINITIONS
Count EQU 0x30 ; variable used for storing no.s of even number
main
; remaining code goes here
movlw 0x0A ;Loading random no.s into 10 succesive location
movwf 0x20
movlw 0x1E
movwf 0x21
movlw 0x05
movwf 0x22
movlw 0x03
movwf 0x23
movlw 0x17
movwf 0x24
movlw 0x07
movwf 0x25
movlw 0x11
movwf 0x26
movlw 0x13
movwf 0x27
movlw 0x1F
movwf 0x28
movlw 0x4C
movwf 0x29
movlw 0x1F
movwf FSR ;FSR Points to one location previous to first no.

2
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

movlw 0x00
movwf Count ;Count initilize to 0
NEXT clrw ;Clear W
Incf FSR,1 ;increment FSR
movf INDF,0 ;Using indirect addressing mode
xorlw 0xFF ;Complement of no. to reverse its nature
andlw 01 ;AND with 01
btfss STATUS,2;Increment count every times when even no. spot skip if not
incf Count
movf FSR,0 ;To check whether the FSR points to last location
xorlw 0x29
btfss STATUS,Z
goto NEXT
END ; directive 'end of program'
OUTPUT:

3
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

Q2. Write an Assembly Language Program to find the maximum value among the list of
Ten 8- bit numbers.
Ans:
FLOW CHART:

ASSEMBLY LANGUAGE PROGRAM:


VARIABLE DEFINITIONS
SET_MAX EQU 0x30 ; variable used for storing larger no.
main
; remaining code goes here
movlw 0x0A ;loading successive 10 random no.s
movwf 0x20
movlw 0x1E
movwf 0x21

4
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

movlw 0x05
movwf 0x22
movlw 0x03
movwf 0x23
movlw 0x17
movwf 0x24
movlw 0x07
movwf 0x25
movlw 0x11
movwf 0x26
movlw 0x13
movwf 0x27
movlw 0x1F
movwf 0x28
movlw 0x4C
movwf 0x29
movf 0x20,0 ;Loading first no. to location SET_MAX
movwf SET_MAX
movlw 0x20 ;FSR points first no.
movwf FSR
Loop clrw
incf FSR ;Increment FSR to point next no.
movf SET_MAX,0
subwf INDF,0 ;Subtraction of two no.s
btfsc STATUS,0 ;check STATUS for any borrow
goto Next ;if Carry bit clear goto NEXT
Previous movf FSR,0 ;Checking for last location

5
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

xorlw 0x29
btfss STATUS,Z
goto Loop
goto Finish

Next

movf INDF,0
movwf SET_MAX ;Swap the contents of FSR and SET_MAX
goto Previous

Finish

END ; directive 'end of program'


OUTPUT:

Q3. Write an Assembly Language Program to generate periodic interrupts every 8ms with
high priority using Timer-2.(Assuming clock frequency is 32 MHz)
Ans:
ASSEMBLY LANGUAGE PROGRAM:
Main:

movlw D'249' ;load 249 into PR2 so thatTMr2 counts up to 249 and reset
movwf PR2,A
bsf RCON,IPEN,A ;enable priority interrupt

bsf IPR1,TMR2IP,A ;place TMR2 interrupt at high Priority

6
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

bcf PIR1,TMR2IF,A
movlw 0xC0
movwf INTCON,A ;Enable global interrupt
movlw 0x7E ;Enable TMR2, set prescaler to 16
movwf T2CON,A ;postscaler to 16
bsf PIE1,TMR2IE,A ;Enable TMR2 overflow interrupt
;End of program

END
OUTPUT:

4. Write a subroutine that Uses relative addressing method to generate the common
cathode /(or anode) seven segment code and pass this code to main program where this
seven segment LED code is passed to the ports through which seven segment LED is
connected.
Ans:
config h'3f18' ;sets the configuration settings - internal oscillator, watchdog timer
OFF PC equ h'02 ;The program counter will be refered to as PC - The program counter
cblock h'20' ;Within this cblock and endc, we can define our variables. More info on
this, later.
delay_1 ;set aside 1 byte for a variable called delay_1
delay_2 ;set aside 1 byte for a variable called delay_1
endc ;that's the end of defining our variables

7
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

org h'0000'
movlw h'07' ;This will turn the comparators OFF.
movwf CMCON ;(we just want to use the ports as digital ports)
bsf STATUS, RP0 ;select bank 1 (to enable us to change the Input / Output
status of ports) movlw b'00000000' ;set PORTB all outputs
movwf TRISB ;We can set each bit individualy. Each port having 8-bits or
8 pins.
movlw b'00100000' ;set PORTA all outputs except for bit 5. Bit 5 is an input
ONLY pin.
movwf TRISA ;It cannot be set to an output!
bcf STATUS, RP0 ;select bank 0

setup
movlw b'11111111' ;we want all LED's off to start with
movwf PORTB ;(remember we need a '0' to turn an LED on)

begin ;This is where our main program starts.


movlw b'11000000’ ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '0'
call delay ;and now call the delay to hold that number.
movlw b'11110011' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '1'
call delay
movlw b'10100100' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '2'
call delay
movlw b'10100001' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '3'
call delay
movlw b'10010011' ;Turn the LED's in such a combination so that

8
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

movwf PORTB ;we display the number '4'


call delay
movlw b'10001001' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '5'
call delay
movlw b'10001000' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '6'
call delay
movlw b'11100011' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '7'
call delay
movlw b'10000000' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '8'
call delay
movlw b'10000001' ;Turn the LED's in such a combination so that
movwf PORTB ;we display the number '9'
call delay
goto begin ;and repeat!

delay ;here is a nice and simple delay routine


movlw d'255' (decimal 255)
movwf delay_1 ;and now copy it from the w register to delay_1 and
delay_2
movwf delay_2 ;Now the rest of the routine will focus on counting down to
zero.
delay_loop ;We come back to this label when we have not yet reached
zero.

9
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

decfsz delay_1, f ;decrement whatever is in delay_1 by 1 and store the


answer back in delay_1
goto delay_loop ;if the answer is not zero, then go back to the delay_loop
label. but if the
decfsz delay_2, f ;answer is zero then decrement delay_2 by one and store
the answer in delay_2
goto delay_loop ;if the answer is not zero, then go back to delay_loop label.
but if answer
return
end

Q5. Write an Assembly Language Program to divide an 8-bit number by 8-bit number.
Store the result as quotient and remainder.

Ans:

FLOW CHART:

10
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

ASSEMBLER LANGUAGE PROGRAM:


VARIABLE DEFINITIONS
Quotient EQU 0x30 ; variable used for saving Quotient
Remainder EQU 0x31 ; variable used for saving
Remainder main

; remaining code goes here


movlw 0x1E ; Loading two no.s at two succsive locations
movwf 0x20
movlw 0x0A
movwf 0x21
movlw 0x00
movwf Quotient ; Initialize Quotient to 0
movf 0x20,0
movwf Remainder ; Move dividend to Remainder
movf 0x21,0 ; Move diviser to W
loop incf Quotient,1 ; increment quotient by 1
subwf Remainder,1; subtract divisor from dividend
btfsc STATUS, 0 ; If carry bit is not clear goto loop
goto loop
decf Quotient,1 ; If carry bit is clear than decrement the Quotient and add
addwf Remainder,1; Add divisor and result of Remainder after subtraction
successive from divisor
result in borrow
goto Finish
Finish
END ; directive 'end of program'

11
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

OUTPUT:

Q6. Configure CCP1 in PWM mode to generate a digital waveform with 40% duty cycle
and 10KHz frequency. Assuming PIC-18 MCU is running with 32 MHz crystal oscillator.

Ans:
ASSEMBLER LANGUAGE POGRAM:
Main:

movlw 0xC7 ;set period value to 199


movwf PR2,A
movlw 0x50 ;set duty cycle value to 80
movwf CCPR1L,A
movwf CCPR1H,A
bcf TRISC,CCP1,A ;configure CCP1 for outpot
movlw 0x81 ;Enable Timer3 in 16 bit mode and
use
movwf T3CON,A ;Timer2 as time base for
PWM1through PWM5
clrf TMR2,A ;Force Timer2 to count from 0
movlw 0x05 ;Enable timer2 and set its prescaler
to 4
movwf T2CON,A
movlw 0x0C ;Enable CCP1 PWM module
movwf CCP1CON,A

12
Deberjeet Usham (2K21/VLS/05) ESD Assignment 1

END
OUTPUT:

13

You might also like