University of Science and technology
Biomedical engineering
Embedded Systems
Assignment - 6
Supervisor : Eng. Ammar Kord
By Students :
- Abdullah AL-Qahtani
- Hasan Ali Mohammed
- Khaled Nabil
- Waleed Nasser
2024 – 2025
1
Q1. Modify the program to display your first name as the welcome scree:
# #include p16f877a.inc ; Include register definition file
Timer1 EQU 20 ; 1ms count register
TimerX EQU 21 ; Xms count register
Point EQU 23 ; Program table pointer
Select EQU 24 ; Copy of RS bit
OutCod EQU 25 ; Temp store for output code
RS EQU 1 ; Register select output bit
E EQU 2 ; Display enable
Key EQU 26 ; Count of keys
Pin_flag EQU 27
CODE 0 ; Place machine code
NOP ; for ICD mode
CLRF Pin_flag
; Initialise ports.........................................
BANKSEL TRISC ; Display
CLRW ; all outputs
MOVWF TRISC ;
MOVWF TRISB
MOVLW B'00000111' ; Keypad
MOVWF TRISD ; bidirectional
BANKSEL PORTC ; Display off
CLRF PORTC ; initially
CLRF PORTB
GOTO main ; jump to main
; Check a row of keys .....................................
row:
INCF Key ; Count first key
BTFSS PORTD,0 ; Check key
GOTO found ; and quit if on
2
INCF Key ; and repeat
BTFSS PORTD,1 ; for second
GOTO found ; key
INCF Key ; and repeat
BTFSS PORTD,2 ; for third
GOTO found ; key
GOTO next ; go for next row
; Scan the keypad..........................................
scan:
CLRF Key ; Zero key count
BSF 3,0 ; Set Carry Flag
BCF PORTD,4 ; Select first row
newrow:
GOTO row ; check row
next:
BSF PORTD,3 ; Set fill bit
RLF PORTD ; Select next row
BTFSC 3,0 ; 0 into carry flag?
GOTO newrow ; if not, next row
GOTO scan ; if so, start again
found:
RETURN ; quit with key count
; Display code table.......................................
table:
MOVF Key,W ; Get key count
ADDWF PCL ; and calculate jump
NOP ; into table
GOTO One;'1' ; Code for '1'
GOTO Two ; Code for '2'
GOTO Three ;'3' ; Code for '3'
RETLW '4' ; Code for '4'
RETLW '5' ; Code for '5'
3
RETLW '6' ; Code for '6'
RETLW '7' ; Code for '7'
RETLW '8' ; Code for '8'
RETLW '9' ; Code for '9'
GOTO Execute; Code for '*'
RETLW '0' ; Code for '0'
GOTO Clear ; '#' ; Code for '#'
; Output display code......................................
One:
MOVLW B'00000010'
MOVWF Pin_flag
RETLW '1'
Two:
MOVLW B'00000100'
MOVWF Pin_flag
RETLW '2'
Three:
MOVLW B'00001000'
MOVWF Pin_flag
RETLW '3'
Execute:
BTFSC Pin_flag, 1
BSF PORTB, 1
BTFSC Pin_flag, 2
BSF PORTB, 2
BTFSC Pin_flag, 3
BSF PORTB, 3
GOTO second_mess
Clear:
CLRF PORTB
CLRF Pin_flag
GOTO main
4
;show:
; CALL table ; Get display code
; MOVWF PORTC ; and show it
; RETURN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Read keypad & display....
Onems:
MOVLW D'249' ; Count for 1ms delay
MOVWF Timer1 ; Load count
Loop1:
NOP ; Pad for 4 cycle loop
DECFSZ Timer1 ; Count
GOTO Loop1 ; until Z
RETURN ; and finish
Xms:
MOVWF TimerX ; Count for X ms
LoopX:
CALL Onems ; Delay 1ms
DECFSZ TimerX ; Repeat X times
GOTO LoopX ; until Z
RETURN ; and finish
PulseE:
BSF PORTC,E ; Set E high
CALL Onems ; Delay 1ms
BCF PORTC,E ; Reset E low
CALL Onems ; Delay 1ms
RETURN ; done
Send:
MOVWF OutCod ; Store output code
ANDLW 0F0 ; Clear low nybble
MOVWF PORTC ; Output high nybble
BTFSC Select,RS ; Test RS bit
5
BSF PORTC,RS ; and set for data
CALL PulseE ; and clock display register
CALL Onems ; wait 1ms for display
SWAPF OutCod ; Swap low and high nibbles
MOVF OutCod,W ; Retrieve output code
ANDLW 0F0 ; Clear low nibble
MOVWF PORTC ; Output low nibble
BTFSC Select,RS ; Test RS bit
BSF PORTC,RS ; and set for data
CALL PulseE ; and clock display register
CALL Onems ; wait 1ms for display
RETURN ; done
Init:
MOVLW D'100' ; Load count 100ms delay
CALL Xms ; and wait for display
MOVLW 0F0 ; Mask for select code
MOVWF Select ; High nibble not masked
MOVLW 0x30 ; Load initial nibble
MOVWF PORTC ; and output it to display
CALL PulseE ; Latch initial code
MOVLW D'5' ; Set delay 5ms
CALL Xms ; and wait
CALL PulseE ; Latch initial code again
CALL Onems ; Wait 1ms
CALL PulseE ; Latch initial code again
BCF PORTC,4 ; Set 4-bit mode
CALL PulseE ; Latch it
MOVLW 0x28 ; Set 4-bit mode, 2 lines
CALL Send ; and send code
MOVLW 0x08 ; Switch off display
CALL Send ; and send code
MOVLW 0x01 ; Clear display
6
CALL Send ; and send code
MOVLW 0x06 ; Enable cursor auto inc
CALL Send ; and send code
MOVLW 0x80 ; Zero display address
CALL Send ; and send code
MOVLW 0x0C ; Turn on display
CALL Send ; and send code
RETURN ; Done
Num_entry:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
MOVF Point,W ; and load it
CALL table ; Get ASCII code from table
CALL Send ; and do it
RETURN
Line1:
ADDWF PCL ; Modify program counter
RETLW 'A' ; Pointer = 0
RETLW 'B' ; Pointer = 1
RETLW 'D' ; Pointer = 2
RETLW 'U' ; Pointer = 3
RETLW 'L' ; Pointer = 4
RETLW 'L' ; Pointer = 5
RETLW 'A' ; Pointer = 6
RETLW 'H' ; Pointer = 7
Line2:
ADDWF PCL ; Modify program counter
RETLW 'S' ; Pointer = 0
RETLW 'e' ; Pointer = 1
RETLW 'l' ; Pointer = 2
RETLW 'e' ; Pointer = 3
7
RETLW 'c' ; Pointer = 4
RETLW 't' ; Pointer = 5
RETLW ' ' ; Pointer = 6
RETLW 'm' ; Pointer = 7
RETLW 'o' ; Pointer = 8
RETLW 't' ; Pointer = 9
RETLW 'o' ; Pointer = 10
RETLW 'r' ; Pointer = 11
Entry_message1:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
Mess1:
MOVF Point,W ; and load it
CALL Line1 ; Get ASCII code from table
CALL Send ; and do it
INCF Point ; point to next character
MOVF Point,W ; and load the pointer
SUBLW D'8' ; check for last table item
BTFSS STATUS,Z ; and finish if 16 done
GOTO Mess1 ; Output character code
MOVLW 0xC0 ; Move cursor to line 2
BCF Select,RS ; Select command mode
CALL Send ; and send code
CLRF Point ; Reset table pointer
MOVLW 0F0 ; Set Delay time
CALL Xms ; Delay
GOTO second_mess
Entry_message2:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
Mess2:
MOVF Point,W ; and load it
8
CALL Line2 ; Get ASCII code from table
CALL Send ; and do it
INCF Point ; point to next character
MOVF Point,W ; and load the pointer
SUBLW D'12' ; check for last table item
BTFSS STATUS,Z ; and finish if 16 done
GOTO Mess2 ; Output character code
MOVLW 0xC0 ; Move cursor to line 2
BCF Select,RS ; Select command mode
CALL Send ; and send code
CLRF Point ; Reset table pointer
GOTO main_loop
main:
CALL Init
CALL Entry_message1
second_mess:
CALL Init
CALL Entry_message2
main_loop:
MOVLW 0FF ; Set all outputs
MOVWF PORTD ; to keypad high
CALL scan ; Get key number
CALL Num_entry ; Display character on LCD
MOVLW 0A0 ; Set Delay time
CALL Xms ; Delay
GOTO main_loop ; and repeat
END;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
10
Q2. Add three more LEDs to the circuit and modify the code so that the user can
activate them.
#include p16f877a.inc ; Include register definition file
Timer1 EQU 20 ; 1ms count register
TimerX EQU 21 ; Xms count register
Point EQU 23 ; Program table pointer
Select EQU 24 ; Copy of RS bit
OutCod EQU 25 ; Temp store for output code
RS EQU 1 ; Register select output bit
E EQU 2 ; Display enable
Key EQU 26 ; Count of keys
Pin_flag EQU 27
CODE 0 ; Place machine code
NOP ; for ICD mode
CLRF Pin_flag
;Initialise ports.........................................
BANKSEL TRISC ; Display
CLRW ; all outputs
MOVWF TRISC;
MOVWF TRISB
MOVLW B'00000111' ; Keypad
MOVWF TRISD ; bidirectional
BANKSEL PORTC ; Display off
CLRF PORTC ; initially
CLRF PORTB
GOTO main ; jump to main
;Check a row of keys.....................................
row:
INCF Key ; Count first key
BTFSS PORTD,0 ; Check key
GOTO found ; and quit if on
INCF Key ; and repeat
11
BTFSS PORTD,1 ; for second
GOTO found ; key
INCF Key ; and repeat
BTFSS PORTD,2 ; for third
GOTO found ; key
GOTO next ; go for next row
;Scan the keypad..........................................
scan:
CLRF Key ; Zero key count
BSF 3,0 ; Set Carry Flag
BCF PORTD,4 ; Select first row
newrow:
GOTO row ; check row
next:
BSF PORTD,3 ; Set fill bit
RLF PORTD ; Select next row
BTFSC 3,0 ; 0 into carry flag?
GOTO newrow ; if not, next row
GOTO scan ; if so, start again
found:
RETURN ; quit with key count
;Display code table.......................................
table:
MOVF Key,W ; Get key count
ADDWF PCL ; and calculate jump
NOP ; into table
GOTO One;'1' ; Code for '1'
GOTO Two ; Code for '2'
GOTO Three ;'3' ; Code for '3'
GOTO Four ;'4' ; Code for '3'
GOTO Five ;'5' ; Code for '3'
GOTO Six ;'6' ; Code for '3'
12
RETLW '7' ; Code for '7'
RETLW '8' ; Code for '8'
RETLW '9' ; Code for '9'
GOTO Execute; Code for'*'
RETLW '0' ; Code for '0'
GOTO Clear ; '#' ; Code for'#'
;Output display code......................................
One:
MOVLW B'00000010'
MOVWF Pin_flag
RETLW '1'
Two:
MOVLW B'00000100'
MOVWF Pin_flag
RETLW '2'
Three:
MOVLW B'00001000'
MOVWF Pin_flag
RETLW '3'
Four:
MOVLW B'00010000'
MOVWF Pin_flag
RETLW '4'
Five:
MOVLW B'00100000'
MOVWF Pin_flag
RETLW '5'
Six:
MOVLW B'01000000'
13
MOVWF Pin_flag
RETLW '6'
Execute:
BTFSC Pin_flag, 1
BSF PORTB, 1
BTFSC Pin_flag, 2
BSF PORTB, 2
BTFSC Pin_flag, 3
BSF PORTB, 3
BTFSC Pin_flag, 4
BSF PORTB, 4
BTFSC Pin_flag, 5
BSF PORTB, 5
BTFSC Pin_flag, 6
BSF PORTB, 6
GOTO second_mess
Clear:
CLRF PORTB
CLRF Pin_flag
GOTO main
;show:
;CALL table ; Get display code
;MOVWF PORTC ; and show it
;RETURN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Read keypad & display....
Onems:
MOVLW D'249' ; Count for 1ms delay
MOVWF Timer1 ; Load count
Loop1:
NOP ; Pad for 4 cycle loop
14
DECFSZ Timer1 ; Count
GOTO Loop1 ; until Z
RETURN ; and finish
Xms:
MOVWF TimerX ; Count for X ms
LoopX:
CALL Onems ; Delay 1ms
DECFSZ TimerX ; Repeat X times
GOTO LoopX ; until Z
RETURN ; and finish
PulseE:
BSF PORTC,E ; Set E high
CALL Onems ; Delay 1ms
BCF PORTC,E ; Reset E low
CALL Onems ; Delay 1ms
RETURN ; done
Send:
MOVWF OutCod ; Store output code
ANDLW 0F0 ; Clear low nybble
MOVWF PORTC ; Output high nybble
BTFSC Select,RS ; Test RS bit
BSF PORTC,RS ; and set for data
CALL PulseE ; and clock display register
CALL Onems ; wait 1ms for display
SWAPF OutCod ; Swap low and high nibbles
MOVF OutCod,W ; Retrieve output code
ANDLW 0F0 ; Clear low nibble
MOVWF PORTC ; Output low nibble
BTFSC Select,RS ; Test RS bit
BSF PORTC,RS ; and set for data
CALL PulseE ; and clock display register
CALL Onems ; wait 1ms for display
15
RETURN ; done
Init:
MOVLW D'100' ; Load count 100ms delay
CALL Xms ; and wait for display
MOVLW 0F0 ; Mask for select code
MOVWF Select ; High nibble not masked
MOVLW 0x30 ; Load initial nibble
MOVWF PORTC ; and output it to display
CALL PulseE ; Latch initial code
MOVLW D'5' ; Set delay 5ms
CALL Xms ; and wait
CALL PulseE ; Latch initial code again
CALL Onems ; Wait 1ms
CALL PulseE ; Latch initial code again
BCF PORTC,4 ; Set 4-bit mode
CALL PulseE ; Latch it
MOVLW 0x28 ; Set 4-bit mode, 2 lines
CALL Send ; and send code
MOVLW 0x08 ; Switch off display
CALL Send ; and send code
MOVLW 0x01 ; Clear display
CALL Send ; and send code
MOVLW 0x06 ; Enable cursor auto inc
CALL Send ; and send code
MOVLW 0x80 ; Zero display address
CALL Send ; and send code
MOVLW 0x0C ; Turn on display
CALL Send ; and send code
RETURN ; Done
Num_entry:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
16
MOVF Point,W ; and load it
CALL table ; Get ASCII code from table
CALL Send ; and do it
RETURN
Line1:
ADDWF PCL ; Modify program counter
RETLW 'A' ; Pointer = 0
RETLW 'B' ; Pointer = 1
RETLW 'D' ; Pointer = 2
RETLW 'U' ; Pointer = 3
RETLW 'L' ; Pointer = 4
RETLW 'L' ; Pointer = 5
RETLW 'A' ; Pointer = 6
RETLW 'H' ; Pointer = 7
Line2:
ADDWF PCL ; Modify program counter
RETLW 'S' ; Pointer = 0
RETLW 'e' ; Pointer = 1
RETLW 'l' ; Pointer = 2
RETLW 'e' ; Pointer = 3
RETLW 'c' ; Pointer = 4
RETLW 't' ; Pointer = 5
RETLW ' ' ; Pointer = 6
RETLW 'm' ; Pointer = 7
RETLW 'o' ; Pointer = 8
RETLW 't' ; Pointer = 9
RETLW 'o' ; Pointer = 10
RETLW 'r' ; Pointer = 11
Entry_message1:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
17
Mess1:
MOVF Point,W ; and load it
CALL Line1 ; Get ASCII code from table
CALL Send ; and do it
INCF Point ; point to next character
MOVF Point,W ; and load the pointer
SUBLW D'8' ; check for last table item
BTFSS STATUS,Z ; and finish if 16 done
GOTO Mess1 ; Output character code
MOVLW 0xC0 ; Move cursor to line 2
BCF Select,RS ; Select command mode
CALL Send ; and send code
CLRF Point ; Reset table pointer
MOVLW 0F0 ; Set Delay time
CALL Xms ; Delay
GOTO second_mess
Entry_message2:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
Mess2:
MOVF Point,W ; and load it
CALL Line2 ; Get ASCII code from table
CALL Send ; and do it
INCF Point ; point to next character
MOVF Point,W ; and load the pointer
SUBLW D'12' ; check for last table item
BTFSS STATUS,Z ; and finish if 16 done
GOTO Mess2 ; Output character code
MOVLW 0xC0 ; Move cursor to line 2
BCF Select,RS ; Select command mode
CALL Send ; and send code
CLRF Point ; Reset table pointer
18
GOTO main_loop
main:
CALL Init
CALL Entry_message1
second_mess:
CALL Init
CALL Entry_message2
main_loop:
MOVLW 0FF ; Set all outputs
MOVWF PORTD ; to keypad high
CALL scan ; Get key number
CALL Num_entry ; Display character on LCD
MOVLW 0A0 ; Set Delay time
CALL Xms ; Delay
GOTO main_loop ; and repeat
19
END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20
Q3.Modify the program to display a message “invalid” to inform the user when trying
to activate an unconnected output port.
#include p16f877a.inc ; Include register definition file
Timer1 EQU 20 ; 1ms count register
TimerX EQU 21 ; Xms count register
Point EQU 23 ; Program table pointer
Select EQU 24 ; Copy of RS bit
OutCod EQU 25 ; Temp store for output code
RS EQU 1 ; Register select output bit
E EQU 2 ; Display enable
Key EQU 26 ; Count of keys
Pin_flag EQU 27
CODE 0 ; Place machine code
NOP ; for ICD mode
CLRF Pin_flag
; Initialise ports.........................................
BANKSEL TRISC ; Display
CLRW ; all outputs
MOVWF TRISC ;
MOVWF TRISB
MOVLW B'00000111' ; Keypad
MOVWF TRISD ; bidirectional
BANKSEL PORTC ; Display off
CLRF PORTC ; initially
CLRF PORTB
21
GOTO main ; jump to main
; Check a row of keys .....................................
row:
INCF Key ; Count first key
BTFSS PORTD,0 ; Check key
GOTO found ; and quit if on
INCF Key ; and repeat
BTFSS PORTD,1 ; for second
GOTO found ; key
INCF Key ; and repeat
BTFSS PORTD,2 ; for third
GOTO found ; key
GOTO next ; go for next row
; Scan the keypad..........................................
scan:
CLRF Key ; Zero key count
BSF 3,0 ; Set Carry Flag
BCF PORTD,4 ; Select first row
newrow:
GOTO row ; check row
next:
BSF PORTD,3 ; Set fill bit
RLF PORTD ; Select next row
BTFSC 3,0 ; 0 into carry flag?
GOTO newrow ; if not, next row
GOTO scan ; if so, start again
found:
22
RETURN ; quit with key count
; Display code table.......................................
table:
MOVF Key,W ; Get key count
ADDWF PCL ; and calculate jump
NOP ; into table
GOTO One;'1' ; Code for '1'
GOTO Two ; Code for '2'
GOTO Three ;'3' ; Code for '3'
GOTO four;'1' ; Code for '1'
GOTO five ; Code for '2'
GOTO six ;'3' ; Code for '3'
GOTO seven
RETLW '8'
RETLW '9'
GOTO Execute; Code for '*'
RETLW '0' ; Code for '0'
GOTO Clear ; '#' ; Code for '#'
; Output display code......................................
One:
MOVLW B'00000010'
MOVWF Pin_flag
RETLW '1'
Two:
MOVLW B'00000100'
MOVWF Pin_flag
RETLW '2'
Three:
23
MOVLW B'00001000'
MOVWF Pin_flag
RETLW '3'
four:
MOVLW B'00010000'
MOVWF Pin_flag
RETLW '4'
five:
MOVLW B'00100000'
MOVWF Pin_flag
RETLW '5'
six:
MOVLW B'01000000'
MOVWF Pin_flag
RETLW '6'
seven:
MOVLW B'10000000'
MOVWF Pin_flag
RETLW '7'
24
Execute:
BTFSC Pin_flag, 1
BSF PORTB, 1
BTFSC Pin_flag, 2
BSF PORTB, 2
BTFSC Pin_flag, 3
BSF PORTB, 3
BTFSC Pin_flag, 4
BSF PORTB, 4
BTFSC Pin_flag, 5
BSF PORTB, 5
BTFSC Pin_flag, 6
BSF PORTB, 6
BTFSC Pin_flag, 7
call Entry_message3
BTFSC Pin_flag, 8
BSF PORTB, 8
BTFSC Pin_flag, 9
BSF PORTB, 9
GOTO second_mess
Clear:
CLRF PORTB
CLRF Pin_flag
GOTO main
;show:
; CALL table ; Get display code
; MOVWF PORTC ; and show it
; RETURN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Read keypad & display....
25
Onems:
MOVLW D'249' ; Count for 1ms delay
MOVWF Timer1 ; Load count
Loop1:
NOP ; Pad for 4 cycle loop
DECFSZ Timer1 ; Count
GOTO Loop1 ; until Z
RETURN ; and finish
Xms:
MOVWF TimerX ; Count for X ms
LoopX:
CALL Onems ; Delay 1ms
DECFSZ TimerX ; Repeat X times
GOTO LoopX ; until Z
RETURN ; and finish
PulseE:
BSF PORTC,E ; Set E high
CALL Onems ; Delay 1ms
BCF PORTC,E ; Reset E low
CALL Onems ; Delay 1ms
RETURN ; done
Send:
MOVWF OutCod ; Store output code
ANDLW 0F0 ; Clear low nybble
MOVWF PORTC ; Output high nybble
BTFSC Select,RS ; Test RS bit
BSF PORTC,RS ; and set for data
CALL PulseE ; and clock display register
26
CALL Onems ; wait 1ms for display
SWAPF OutCod ; Swap low and high nibbles
MOVF OutCod,W ; Retrieve output code
ANDLW 0F0 ; Clear low nibble
MOVWF PORTC ; Output low nibble
BTFSC Select,RS ; Test RS bit
BSF PORTC,RS ; and set for data
CALL PulseE ; and clock display register
CALL Onems ; wait 1ms for display
RETURN ; done
Init:
MOVLW D'100' ; Load count 100ms delay
CALL Xms ; and wait for display
MOVLW 0F0 ; Mask for select code
MOVWF Select ; High nibble not masked
MOVLW 0x30 ; Load initial nibble
MOVWF PORTC ; and output it to display
CALL PulseE ; Latch initial code
MOVLW D'5' ; Set delay 5ms
CALL Xms ; and wait
CALL PulseE ; Latch initial code again
CALL Onems ; Wait 1ms
CALL PulseE ; Latch initial code again
BCF PORTC,4 ; Set 4-bit mode
CALL PulseE ; Latch it
MOVLW 0x28 ; Set 4-bit mode, 2 lines
CALL Send ; and send code
MOVLW 0x08 ; Switch off display
CALL Send ; and send code
MOVLW 0x01 ; Clear display
CALL Send ; and send code
27
MOVLW 0x06 ; Enable cursor auto inc
CALL Send ; and send code
MOVLW 0x80 ; Zero display address
CALL Send ; and send code
MOVLW 0x0C ; Turn on display
CALL Send ; and send code
RETURN ; Done
Num_entry:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
MOVF Point,W ; and load it
CALL table ; Get ASCII code from table
CALL Send ; and do it
RETURN
Line1:
ADDWF PCL ; Modify program counter
RETLW 'a' ; Pointer = 0
RETLW 'b' ; Pointer = 1
RETLW 'd' ; Pointer = 2
RETLW 'u' ; Pointer = 3
RETLW 'l' ; Pointer = 4
RETLW 'l' ; Pointer = 5
RETLW 'a' ; Pointer = 6
RETLW 'h' ; Pointer = 7
Line2:
ADDWF PCL ; Modify program counter
RETLW 'h' ; Pointer = 0
28
RETLW 'e' ; Pointer = 1
RETLW 'l' ; Pointer = 2
RETLW 'e' ; Pointer = 3
RETLW 'c' ; Pointer = 4
RETLW 't' ; Pointer = 5
RETLW ' ' ; Pointer = 6
RETLW 'm' ; Pointer = 7
RETLW 'o' ; Pointer = 8
RETLW 't' ; Pointer = 9
RETLW 'o' ; Pointer = 10
RETLW 'r' ; Pointer = 11
Line3:
ADDWF PCL ; Modify program counter
RETLW 'i' ; Pointer = 0
RETLW 'n' ; Pointer = 1
RETLW 'v' ; Pointer = 2
RETLW 'a' ; Pointer = 3
RETLW 'l' ; Pointer = 4
RETLW 'i' ; Pointer = 5
RETLW 'd' ; Pointer = 6
Entry_message3:
CALL Init
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
Mess3:
MOVF Point,W ; and load it
CALL Line3 ; Get ASCII code from table
CALL Send ; and do it
29
INCF Point ; point to next character
MOVF Point,W ; and load the pointer
SUBLW D'7' ; check for last table item
BTFSS STATUS,Z ; and finish if 16 done
GOTO Mess3 ; Output character code
MOVLW 0xC0 ; Move cursor to line 2
BCF Select,RS ; Select command mode
CALL Send ; and send code
CLRF Point ; Reset table pointer
MOVLW 0F0 ; Set Delay time
CALL Xms ; Delay
GOTO second_mess
Entry_message1:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
Mess1:
MOVF Point,W ; and load it
CALL Line1 ; Get ASCII code from table
CALL Send ; and do it
INCF Point ; point to next character
MOVF Point,W ; and load the pointer
SUBLW D'8' ; check for last table item
BTFSS STATUS,Z ; and finish if 16 done
GOTO Mess1 ; Output character code
MOVLW 0xC0 ; Move cursor to line 2
BCF Select,RS ; Select command mode
CALL Send ; and send code
CLRF Point ; Reset table pointer
MOVLW 0F0 ; Set Delay time
30
CALL Xms ; Delay
GOTO second_mess
Entry_message2:
CLRF Point ; Reset table pointer
BSF Select,RS ; Select data mode
Mess2:
MOVF Point,W ; and load it
CALL Line2 ; Get ASCII code from table
CALL Send ; and do it
INCF Point ; point to next character
MOVF Point,W ; and load the pointer
SUBLW D'12' ; check for last table item
BTFSS STATUS,Z ; and finish if 16 done
GOTO Mess2 ; Output character code
MOVLW 0xC0 ; Move cursor to line 2
BCF Select,RS ; Select command mode
CALL Send ; and send code
CLRF Point ; Reset table pointer
GOTO main_loop
main:
CALL Init
CALL Entry_message1
second_mess:
CALL Init
CALL Entry_message2
main_loop:
MOVLW 0FF ; Set all outputs
31
MOVWF PORTD ; to keypad high
CALL scan ; Get key number
CALL Num_entry ; Display character on LCD
MOVLW 0A0 ; Set Delay time
CALL Xms ; Delay
GOTO main_loop ; and repeat
END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32