Professional Documents
Culture Documents
Microprocessors System Interfacing
Microprocessors System Interfacing
Microprocessors System Interfacing
Question 1:
Generate a rectangular wave with PIC18F452 microcontroller with following
requirements.
Code:
Delayon: ; 1 ms delay
BSF T0CON,7 ; Timer 0 on
MOVLW 0xEC ; Load 0xEC78 for 1 ms delay
MOVWF TMR0H
MOVLW 0x78
PAGE 1
MOVWF TMR0L
Again:
BTFSS INTCON,2 ; Wait till TMR0IF flag set
GOTO Again
BCF T0CON,7 ; Timer 0 off
BCF INTCON,2 ; Clear flag
RETURN
Delayoff: ; 4 ms delay
BSF T0CON,7 ; Timer0 on
MOVLW 0xB1 ; Load 0xB1E0 for 4 ms delay
MOVWF TMR0H
MOVLW 0xE0
MOVWF TMR0L
Check:
BTFSS INTCON,2 ; Wait till TMR0IF flag set
GOTO Check
BCF T0CON,7 ; Timer0 off
BCF INTCON,2 ; Clear flag
RETURN
END
PAGE 2
Main:
CLRF TRISB ; Port B pins as output
MOVLW 0x02
MOVWF T0CON ; Timer0, 16 bit, prescaler 8
CLRF PORTB
Loop:
BSF PORTB,0 ; Drive RB0 high
CALL Delayon ; 5 ms delay
BCF PORTB,0 ; Drive RB0 low
CALL Delayoff ; 20 ms delay
GOTO Loop
Delayon: ; 5 ms delay
BSF T0CON,7 ; Timer 0 on
MOVLW 0xE7 ; Load 0xE796 for 5 ms delay
MOVWF TMR0H
MOVLW 0x96
MOVWF TMR0L
Again:
BTFSS INTCON,2 ; Wait till TMR0IF flag set
GOTO Again
BCF T0CON,7 ; Timer 0 off
BCF INTCON,2 ; Clear flag
RETURN
Delayoff: ; 15 ms delay
BSF T0CON,7 ; Timer0 on
MOVLW 0xB6 ; Load 0xB6C2 for 15 ms delay
MOVWF TMR0H
PAGE 3
MOVLW 0xC2
MOVWF TMR0L
Check:
BTFSS INTCON,2 ; Wait till TMR0IF flag set
GOTO Check
BCF T0CON,7 ; Timer0 off
BCF INTCON,2 ; Clear flag
RETURN
END
Delay: ; .5 s delay
PAGE 4
BSF T0CON,7 ; Timer 0 on
MOVLW 0xB3 ; Load 0xB3B5 for .5s delay
MOVWF TMR0H
MOVLW 0xB5
MOVWF TMR0L
Again:
BTFSS INTCON,2 ; Wait till TMR0IF flag set
GOTO Again
BCF T0CON,7 ; Timer 0 off
BCF INTCON,2 ; Clear flag
RETURN
END
PAGE 5
GOTO Loop
PAGE 6
PAGE 7
QUESTION 2
Implement a RADAR System using PIC18F452. Radar system uses a listening
sensor and listens for high value from sensor. Once it detects high value from sensor
it will generate a pulse with duration of 300ms. Use XTAL=24 MHz with PIC18F452
Code
#include<p18f452.inc>
ORG 0H
start
CLRF TRISB ; Port B as output
BSF TRISD,0 ; RD0 as input
PAGE 8
MOVLW 0x05
MOVWF T0CON ; Timer0, 16 bit with prescaler 64
CLRF PORTB
Loop:
BTFSS PORTD,0 ; Check whether high value from sensor
GOTO Loop ; If not then check again
BSF PORTB,0 ; If yes then drive RB0 high
CALL Delay ; Call Delay subroutine of 300 ms delay
BCF PORTB,0 ; Drive RB0 Low
GOTO Loop
Delay: ; Delay subroutine
MOVLW 0x92
MOVWF TMR0H ; Move the value 37411 which is 0x9223 to TMR0
MOVLW 0x23
MOVWF TMR0L
BSF T0CON,7 ; Timer0 On
Again:
BTFSS INTCON,2 ; Check whether TMR0IF is set
GOTO Again ; Check till it is set
BCF T0CON,7 ; Timer0 off
BCF INTCON,2 ; TMR0IF cleared
RETURN
END
PAGE 9
PAGE 10