KhaledOsmani
Full Member level 6
Hi,
The problem is to give the full code in PIC18 IDE, to accomplish what is cleared in the .docx attached file.
I was able to only come up with the following code: It has severe stack overflow, and data is often corrupted. It is composed of 1250 lines! And still not done.
I`m sure that no one has the time to read it all, but in case, here is the code (you can directly loaded into the compiler, and start simulation, and compare to what's given)
- - - Updated - - -
- - - Updated - - -
(Since .docx is not supported here are some screen shots of the project):
The problem is to give the full code in PIC18 IDE, to accomplish what is cleared in the .docx attached file.
I was able to only come up with the following code: It has severe stack overflow, and data is often corrupted. It is composed of 1250 lines! And still not done.
I`m sure that no one has the time to read it all, but in case, here is the code (you can directly loaded into the compiler, and start simulation, and compare to what's given)
- - - Updated - - -
Code:
Define GLCD_DREG = PORTB
Define GLCD_RSREG = PORTD
Define GLCD_RSBIT = 2
Define GLCD_EREG = PORTD
Define GLCD_EBIT = 3
Define GLCD_RWREG = PORTD
Define GLCD_RWBIT = 4
Define GLCD_CS1REG = PORTD
Define GLCD_CS1BIT = 0
Define GLCD_CS2REG = PORTD
Define GLCD_CS2BIT = 1
WaitMs 20
GLcdinit
Dim x As Word
Dim i As Word
i = 0
main:
GLcdclear
GLcdposition 0, 0
GLcdwrite "1.Alarm ON"
GLcdposition 8, 0
GLcdwrite "/ OFF"
GLcdposition 1, 0
GLcdwrite "2.Lock /"
GLcdposition 9, 0
GLcdwrite "Master ID"
GLcdposition 3, 0
GLcdwrite "Selection:"
Gosub select12
End
select12:
High PORTC.0
If PORTC.4 Then
Gosub alarmmenu
Endif
Low PORTC.0
High PORTC.1
If PORTC.4 Then
Gosub lockmastermenu
Endif
Low PORTC.1
Goto select12
Return
alarmmenu:
GLcdclear
GLcdposition 0, 0
GLcdwrite " Alarm"
GLcdposition 8, 0
GLcdwrite "Menu"
GLcdposition 2, 0
GLcdwrite "CODE:"
WaitMs 50
Gosub checkcode
Return
lockmastermenu:
GLcdclear
GLcdposition 0, 0
GLcdwrite "1."
GLcdposition 8, 0
GLcdwrite "Open"
GLcdposition 8, 28
GLcdwrite "Lock"
GLcdposition 1, 0
GLcdwrite "2."
GLcdposition 9, 0
GLcdwrite "Master"
GLcdposition 9, 40
GLcdwrite "ID"
GLcdposition 2, 0
GLcdwrite "Selection:"
WaitMs 20
selectbetween12:
x = 0
High PORTC.0
If PORTC.4 Then
GLcdposition 10, 0
x = 1
GLcdwrite "1"
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto selectbetween12
Endif
WaitMs 50
If PORTC.7 Then
Goto lock
Endif
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
WaitMs 20
Low PORTC.0
High PORTC.1
If PORTC.4 Then
x = 2
GLcdposition 10, 0
GLcdwrite "2"
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto selectbetween12
Endif
WaitMs 20
High PORTC.0
If PORTC.7 Then
Goto masterlock
Endif
Low PORTC.0
WaitMs 20
Low PORTC.1
Goto selectbetween12
Return
checkcode:
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
If PORTC.4 Then
x = x * 10 + 1
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkcode
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.7 Then
Goto checktruth
Endif
If PORTC.5 Then
x = x * 10 + 4
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkcode
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.7 Then
Goto checktruth
Endif
If PORTC.6 Then
x = x * 10 + 7
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkcode
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
High PORTC.1
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
If PORTC.4 Then
x = x * 10 + 2
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkcode
Endif
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
If PORTC.5 Then
x = x * 10 + 5
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkcode
Endif
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
If PORTC.6 Then
x = x * 10 + 8
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkcode
Endif
High PORTC.2
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
Low PORTC.1
High PORTC.2
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
If PORTC.4 Then
x = x * 10 + 3
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkcode
Endif
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
If PORTC.5 Then
x = x * 10 + 42
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkcode
Endif
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
If PORTC.6 Then
x = x * 10 + 9
GLcdposition 10, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkcode
Endif
High PORTC.0
If PORTC.7 Then
Goto checktruth
Endif
Low PORTC.0
If PORTC.7 Then
GLcdclean 10, 0
i = 0
x = 0
Endif
Low PORTC.2
Goto checkcode
Return
checktruth:
If x = 1234 Then
GLcdclear
GLcdposition 0, 1
GLcdwrite "1."
GLcdposition 0, 19
GLcdwrite "ON"
GLcdposition 8, 0
GLcdwrite "2."
GLcdposition 8, 19
GLcdwrite "OFF"
GLcdposition 2, 0
innercheck:
High PORTC.0
If PORTC.4 Then
GLcdwrite "1"
GLcdposition 4, 0
GLcdwrite "Alarm"
GLcdposition 4, 40
GLcdwrite "ON"
WaitMs 100
i = 0
x = 0
Goto main
Endif
Low PORTC.0
High PORTC.1
If PORTC.4 Then
GLcdwrite "2"
GLcdposition 4, 0
GLcdwrite "Alarm"
GLcdposition 4, 40
GLcdwrite "OFF"
WaitMs 100
i = 0
x = 0
Goto main
Endif
Low PORTC.1
Goto innercheck
Else
GLcdclear
GLcdposition 0, 31
GLcdwrite "Wrong"
GLcdposition 8, 0
GLcdwrite "Code"
WaitMs 150
i = 0
x = 0
Goto main
Endif
Return
lock:
x = 0
i = 0
GLcdclear
GLcdposition 0, 0
GLcdwrite "Code:"
GLcdposition 8, 0
Gosub checkcodelock
state:
If x = 1234 Then
GLcdclear
GLcdposition 0, 20
GLcdwrite "Lock"
GLcdposition 8, 0
GLcdwrite "Opened"
WaitMs 100
Goto main
Else
GLcdclear
GLcdposition 0, 20
GLcdwrite "Wrong"
GLcdposition 8, 0
GLcdwrite "Code"
Goto main
Endif
Return
masterlock:
GLcdclear
GLcdposition 0, 21
GLcdwrite "Master"
GLcdposition 8, 0
GLcdwrite "Code:"
GLcdposition 2, 0
Gosub checkmasterlock
state2:
If x = 4321 Then
Goto changemasteruser
Else
GLcdclear
GLcdposition 0, 21
GLcdwrite "Wrong"
GLcdposition 0, 55
GLcdwrite "Code"
Goto main
Endif
Return
checkcodelock:
High PORTC.0
If PORTC.4 Then
x = x * 10 + 1
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkcodelock
Endif
If PORTC.7 Then
Goto state
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.5 Then
x = x * 10 + 4
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkcodelock
Endif
If PORTC.7 Then
Goto state
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.6 Then
x = x * 10 + 7
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkcodelock
Endif
If PORTC.7 Then
Goto state
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
High PORTC.1
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
Low PORTC.2
If PORTC.4 Then
x = x * 10 + 2
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkcodelock
Endif
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
Low PORTC.2
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
If PORTC.5 Then
x = x * 10 + 5
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkcodelock
Endif
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
Low PORTC.2
If PORTC.6 Then
x = x * 10 + 8
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkcodelock
Endif
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
Low PORTC.2
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
Low PORTC.1
High PORTC.2
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
If PORTC.4 Then
x = x * 10 + 3
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkcodelock
Endif
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
If PORTC.5 Then
x = x * 10 + 42
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkcodelock
Endif
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
If PORTC.6 Then
x = x * 10 + 9
GLcdposition 8, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkcodelock
Endif
If PORTC.7 Then
GLcdclean 8, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state
Endif
Low PORTC.0
Low PORTC.2
Goto checkcodelock
Return
checkmasterlock:
High PORTC.0
If PORTC.4 Then
x = x * 10 + 1
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkmasterlock
Endif
If PORTC.7 Then
Goto state2
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.5 Then
x = x * 10 + 4
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkmasterlock
Endif
If PORTC.7 Then
Goto state2
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.6 Then
x = x * 10 + 7
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
i = i + 6
Goto checkmasterlock
Endif
If PORTC.7 Then
Goto state2
Endif
High PORTC.2
Low PORTC.0
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
Low PORTC.2
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
High PORTC.1
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
Low PORTC.2
If PORTC.4 Then
x = x * 10 + 2
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkmasterlock
Endif
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
Low PORTC.2
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
If PORTC.5 Then
x = x * 10 + 5
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkmasterlock
Endif
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
Low PORTC.2
If PORTC.6 Then
x = x * 10 + 8
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
Low PORTC.2
i = i + 6
Goto checkmasterlock
Endif
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
Low PORTC.2
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
Low PORTC.1
High PORTC.2
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
If PORTC.4 Then
x = x * 10 + 3
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkmasterlock
Endif
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
If PORTC.5 Then
x = x * 10 + 42
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkmasterlock
Endif
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
If PORTC.6 Then
x = x * 10 + 9
GLcdposition 2, i
GLcdwrite "*"
WaitMs 50
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
i = i + 6
Goto checkmasterlock
Endif
If PORTC.7 Then
GLcdclean 2, 0
i = 0
x = 0
Endif
High PORTC.0
If PORTC.7 Then
Goto state2
Endif
Low PORTC.0
Low PORTC.2
Goto checkmasterlock
Return
changemasteruser:
GLcdclear
GLcdposition 0, 0
GLcdwrite "To be done"
WaitMs 100
Goto main
Return
- - - Updated - - -
(Since .docx is not supported here are some screen shots of the project):