INP and OUT Port

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

Contact trouble

Post by danner »

Ted,

I got your mail just now. For some reason what I've tried to send to you lately keeps coming back. I sent you one from hotmail last week, and also posted a message direct to you on here and had not heard.

I guess if all else fails, we'll have to clutter this forum up.

I was waiting to hear what you suggested. The tower.. your programs reads 127..the laptop 120 as it should.. the difference I noticed was the tower shows S0 as checked and the laptop does not.

I just finished putting another computer together.. need to run your program before I connect anything to see what it reads.

I have a resonator I can try in place of the crystal.. or another chip I can try. With the S0 being off in the tower computer I was not sure if my circuit would have caused that or not? If so.. how can I avoid it happening to the next one? How do you suggest I proceed? What would you try next?

Thankyou,
Daniel
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

S0 is not used except when the port is in EPP mode, so the port is messed up somehow. There is no pin for S0 to S2 , but it would only add 1 if checked. That means that S1 and 2 are also being read as on or a total of 7 is added: 1 + 2 + 4 = 7. That explains the problem!

Since our program and circuit are not using these areas, the port is bad.

Use the resonator! Put it somewhere and jumper to it. A crystal may be causing problems too!

Did you try your addon port? Make sure it does not use the same address and try it. That means that the program will have to read different port addresses too. Windows can give you the new port's base address also. Then status is base address + 1 and control is base + 2.

Use current limiting resistors to all port pins for safety! 1K should be fine. Connect resistors to all cable wires going to the pins.

Suggestion: Get a new email address! Try Gmail........I just moved there.
You also have my good address too.

Ted
danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

next step?

Post by danner »

Ted,

I tried the other card in the old tower, it has the same problem. (I wonder if that wasn't what caused the problem originally) It was a complete control card from a very old system, not just a printer add on card.

I got the other computer put together and up and running. I'll try the resonator, and 1K resistors with it and see what I come up with.

I tried your comcast email from another location, let me know if you got any emails from me.. and where they were from.

Thank you,
Daniel
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

No emails yet. We can finish here if we have to.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

mail

Post by danner »

Hi Ted,

That is odd. In the last week I know I have tried to mail you from 3 different addresses. Only the Yahoo address has shown that it was not deliverable. These were all to the comcast address you gave me. I did get the email from you at my yahoo address.

I will try to get the circuit tested on the other computer I put together.. using the resonator and 1K resistor changes... I'll update you as soon as I learn anything. I do know it is showing 120 as it should in your port monitor program. I made sure to get that loaded and tested before I hooked anything up.

Will update you in the next day or two.

Thank you,
Daniel
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Use the one I have here! Button down below called email. WOW you have a lot of problems there.

It worked at Gmail ..........hooray!
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

Update

Post by danner »

Update to all, with a lot of help from Ted the program is mostly up and running with just a few bugs to work out. The bugs being.. getting a buzzer/speaker to work for the keypresses that doesn't interfere with signals to the computer, getting the relay to work (which I believe is due to too large a resistor), and adding a buzzer to the door latch circuit since this latch does not have one.

The computer now receives and processes keypad input properly.

To Ted.. I have not been home to see if you have responded to that email yet. My questions after review and using the E=IR formula.. the Relay is 5V with a 56 Ohm R to its coil and will take 89 mA so I am assuming I do not need much of a resistor in that circuit if any.

On the latch.. for a buzzer I am thinking of trying that speaker that did not work well on the controller chip.. it says it is 4-28V DC.. and after holding the Ohm meter on it for some time.. it leveled off at around 14 Ohms R. The latch is 12V and .332 amps with a Coil R of 34.6 Ohms so I do need to add a little R to that circuit.. maybe the speaker will be just right?

Once I have these bugs worked out and the code touched up I will post it.

Thank you Ted!
Danner
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Dan Fuller's final code

Post by burger2227 »

Code: Select all

'  File...   Door Program 
'Author....   Dan Fuller 
'E-Mail....   qxotic@hotmail.com 
'Started...   14 Nov. 2007  finished 14 Feb. 2008 

'Description - to accept 4 digit code from keypad connected to LPT1, 
'              check code against database, if code is valid at the time 
'              send signal to electronic strike to allow acess and then 
'              log event in history. 


'---- INITIALIZATION ----- 
CLS 
temp$ = " " 
Tt$ = TIME$ 
Td$ = DATE$ 
Hour$ = MID$(TIME$, 1, 2) 

Apt = 0 
CODE = 1000 
TimeZone = 0 
Note$ = "T" 

'*********************************** 
'*              MAIN               * 
'*********************************** 
DO 
   IF INKEY$ = CHR$(27) THEN 
        PRINT "Main Sub Exit" 
        SYSTEM 
   END IF 
        GOSUB AcceptInput 
        GOSUB EvaluateInput 
        GOSUB LogHistory 
LOOP 
END 
'*********************************** 
'*         AcceptInput             * 
'*********************************** 
AcceptInput: 
   flag = 0: count = 0: keycode = 0: keypress = 0: status = 0 

DO 
   IF INKEY$ = CHR$(27) THEN 
        PRINT "AcceptInput exit" 
        SYSTEM 
   END IF 

   status = INP(889) 
      IF status >= 128 THEN
        flag = 1: start = TIMER: count = count + 1
          IF status < 152 THEN keypress = ((status - 120) / 8)
          IF status > 152 AND status < 184 THEN keypress = ((status - 128) / 8)
          IF status > 184 AND status < 216 THEN keypress = ((status - 136) / 8)
          IF status = 232 THEN keypress = 0
          IF status = 240 THEN EXIT DO       '# key exits Input check
          keycode = keycode + keypress
          IF count < 4 THEN keycode = keycode * 10 'assumes no zero first
    END IF      
    TIMER < start THEN start = start - 86400 
    IF flag = 1 AND TIMER > start + 5 THEN 
         count = 0: keycode = 0 
         EXIT DO
    END IF
      'prevent single entry accepted more then once 
    DO: status = INP(889) 
    LOOP UNTIL status = 0
  
'PRINT keycode, keypress, count, status 'used during testing 
LOOP UNTIL count = 4 

RETURN 

'*********************************** 
'*         EvaluateInput           * 
'*********************************** 
EvaluateInput: 
    DBCode = 9998 
OPEN "userdb.dat" FOR INPUT AS #1 
        DO WHILE NOT EOF(1) 
          INPUT #1, Apt, DBCode, TimeZone, Note$ 
             IF DBCode = 9999 THEN GOSUB InvalidCode 
          IF DBCode = keycode THEN EXIT DO 
        LOOP 
     CLOSE 
        IF TimeZone = 1 THEN GOSUB TimeCheck 
        IF DBCode < 9998 AND TimeZone < 5 THEN GOSUB ValidCode 
RETURN 
'*********************************** 
'*         InvalidCode             * 
'*********************************** 
InvalidCode:    ' edit code to send an error signal beep if desired 
        'PRINT "The Code "; keycode; "was invalid" 'used during testing only 
        'PRINT Tt$; Td$ 
        'INPUT temp$ 
RETURN 

'*********************************** 
'*     ValidCode-Door Unlock       * 
'*********************************** 
ValidCode: 
        'PRINT "The Code "; keycode; "was GOOD" 'used during testing only 
        'PRINT Tt$; Td$ 
         OUT 890, INP(890) XOR 8  'door unlock    
RETURN 

'*********************************** 
'*         LogHistory              * 
'*********************************** 
LogHistory: 
        OPEN "History.DAT" FOR APPEND AS #2 
          WRITE #2, Apt, CODE, TimeZone, Tt$, Td$, Note$ 
        CLOSE #2 
RETURN 
'below is data example of password file 
'DATA Apt  Code   Time Zone  Note 
'DATA   01, 1001,   1,        Ten 
'DATA   02, 1002,   1,        Ten 
'DATA   03, 1003,   1,        Ten 
'DATA   04, 1004,   1,        Ten 
'DATA   44, 4444,   4,        Emp 
'DATA   99, 9999,   4,        End File 

There are other ways to do this code. For one, you could add LED's to indicate access using the other Control pins C0 and C1. To just change one control pin value, you can send the pin total needed at the time instead of using XOR as above. Get PortTalk for NT or XP machines!

I have also created a program in VB6 to use in Windows. The only major problem is trying to use the peizo speaker from the chip to indicate keypad entries. It messed up the other chip data sent.

Ted
danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

Schematic

Post by danner »

Thanks Ted for all the help and posting the code.

I looked up to see how to post an image of the schematic as laid out on the PCB but according to the FAQ's I would have to have it posted on a server somewhere and link to it. I don't have that so... if anyone wants to see it or get a parts list they can contact me directly through here.



Thanks,
Danner
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Send it over, I wanna see it. :-).

I can upload it to my server too if you want to link to it. or forward it to pete so he can upload it to his.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

hmmmmmmmm

Post by burger2227 »

Would photobucket work? You can upload images there.

Myst, wish you had an email address here. Note my Signature also (teehee)

Pleasure to help Dan! My VB code is not gonna work in .NET and you would also have to figure out the form controls used. VB6 can also use Control Arrays which I used for the Port bit checkboxes. That is why I never sent you the code.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

lol well I have an email in my profile ;-)...lol.

and yeah, I like that signature ;-)
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Here is the PCB screen shot that danner sent me a few minutes ago.

Image

EDIT Added the following part/location list for the PCB above:

Code: Select all

PCB ? RS 276-170 

COMPONENT          PCB LOCATION     COMPONENT  PCB LOCATION
------------------ ------------     ---------- ------------  
Resistors                           Red Wires
 4.7 KOhm           Y44 ? I42                   A45 ? X45
 4.7 KOhm           Y43 ? I41                   A44 ? X44
 4.7 KOhm           Y41 ? J40                   I43 ? X38
 4.7 KOhm           Y39 ? J39                   F10 ? X10
   1 KOhm           Y37 ? J37                    G7 ? G10
 330 Ohm            H27 ? E29                   I10 ? I19
 330 Ohm            H25 ? E27                   J10 ? J15
 330 Ohm            H23 ? E25       Black Wires
 330 Ohm            H21 ? E23                   B43 ? F38
 4.7 KOhm           C21 ? D20                   E31 ? H37
 4.7 KOhm           C17 ? D16                   J38 ? Y38
 2.2 KOhm           H18 ? I17                    J4 ? Y5
 2.2 KOhm           H14 ? H12
 2.2 KOhm           F13 ? E8        Coral

Diodes                              Row         C23 ? C42
 1N4001              C6 ? C4        Row         D25 ? D41
 1N4001              G6 ? I7        Row         C27 ? C40
 
Optocoupler                         Row         D29 ? D39
 Mouser 512-4N3     E20 ? F20       Pin 11      E33 ? H46
 Mouser 512-4N32    E16 ? F16       Column      H31 ? I39
 
Encoder Chip                        Column      H33 ? H40
 EDE1144            E47 ? F47       Column      G35 ? H41
Jameco 171969
 
Transistor                          Base wire    J5 ? J17
 NPN RS 276-1617    Emit. G11 ? G13
 NPN RS 276-1617    Emit. I4 ? I6   Yellow Wires
 
Relay                                            Pwr sply ? c2
 5VDC RS 275-240    Coil F6 ? F7                 D2 ? D4
 
Crystal                                          Gray Wires
 DigiKey 445-1638ND H44 ? J45                    Pwr Gnd ? I2
                                                 H2 ? H11
 
                                    Terminals    RS 276-1388
danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

Thanks for posting

Post by danner »

Thanks to both you and Ted for posting the information, looks great.

I learned a lot on this project.

Take care,

Danner
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Check this thread out! We actually made the program and LPT board.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

Project

Post by danner »

This was a good project. It helped me as I took it another step. I built a board using a BS2pe module from Parallax which holds my program and logs the data onto a thumb drive. It utilizes the same board to control the latch and speaker as shown above. For our sites, this new setup works better. I do not have to have a computer at each location. I am way out of the loop on Basic programming now. I don't have any other projects in mind so I do not expect to get back into this anytime soon. Thanks again to all those who helped along the way.

Danner
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

That is GREAT to hear! I was wondering if anything would last that long as LPT ports are rapidly disappearing on computers.

Apparently you also got the beeper to work. What changes did you make?

Can I get a piece of the action? 8)

Ted

In loving memory of Mac who owned the Network 54 Qbasic Forum until his untimely death!
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
danner
Coder
Posts: 17
Joined: Thu Oct 11, 2007 11:21 am
Location: Mt. Sterling, IL
Contact:

Update

Post by danner »

I saved the program as a text file.. I did not see how to upload it as an attachment so I pasted it below.

You are right that LPT ports are going away, and I also found my original program worked fine on some 98 computers but didn't on others so I went the Basic Stamp route as shown below... I'm pretty sure this is the latest verstion. I drive the speaker the same as I do the latch, through an opto. The additional hardware has the stamp, an onboard clock and a data-logger that I plug a thumb drive into. Anything I need to update other than the clock which I do from the keypad. The log file is kept on the thumb drive as well as the password files.

Danner

Code: Select all

' {$STAMP BS2pe}
' {$PBASIC 2.5}
' =========================================================================
'
'   File...... Door1.BS2pe
'   Purpose... Electronic door latch controller
'   Author.... Daniel Fuller
'   E-mail.... qxotic@hotmail.com
'   Started... 11 August 2009
'   Updated... 21 September 2009
' -----[ Program Description ]---------------------------------------------
'
' Provides entry control for a door.
'
' The (Grayhill series 88) keypad used for this program is layed out like this:
'
'  --- --- ---
' | 1 | 2 | 3 |   R1
'  --- --- ---
' | 4 | 5 | 6 |   R2
'  --- --- ---
' | 7 | 8 | 9 |   R3
'  --- --- ---
' | * | 0 | # |   R4
'  --- --- ---
'
'   C   C   C
'   1   2   3
' -----[ I/O Definitions ]-------------------------------------------------
TX              PIN     0        ' Transmit Data to Logger   --> 27937.4 (RXD)
RX              PIN     1        ' Receive Data from Logger  <-- 27937.5 (TXD)

SDA             PIN     8        ' clock - used Sparkfun RTC BOB-00099
SCL             PIN     9        ' clock
' -----[ Constants ]-------------------------------------------------------
Baud            CON     188                  'A baud rate of 4800
DS1307          CON     %1101 <<4> 510)THEN start = 0
  LOOP UNTIL (IN3 = 0)              ' wait for key
  key = ~KeyPad   ' get inverted state of bits

  IF (start <510>26 THEN
    GOSUB ValidCode
  ELSEIF clock(2)>6 AND clock(2)<22 THEN
    GOSUB ValidCode
  ELSE
    Note = "Z":GOSUB InvalidCode   ' set note for timezone denial
  ENDIF
RETURN


' -----[ InvalidCode ]----------------------------------------------------
InvalidCode:

  GOSUB Beep2
  GOSUB Beep2
  GOSUB Beep2
  GOSUB History
  GOSUB Main

' -----[ ValidCode ]----------------------------------------------------
ValidCode:

  Note = "G"            'set note to 1 for access granted
  HIGH 12               'send signal to open latch
  GOSUB Beep2
  GOSUB Beep
  PAUSE 2500            'delay to keep latch open
  LOW 12                'send signal to close latch
  GOSUB Beep2
  GOSUB History

  GOSUB Main

' -----[ History ]----------------------------------------------------
History:             'this info goes into a history log on logger
 GOSUB Check_Logger

 SEROUT TX, Baud, [$01, $20, "Log.txt", $0D]            ' DIR
  SERIN RX, Baud, 500, No_Log,[WAIT($20)]         ' Wait for $20 or time out if no response

  SEROUT TX,Baud,[$9,$20,"Log.txt", CR]
  SERIN RX,Baud,500, LogErr2,[WAIT(">")]

  SEROUT TX,Baud,[$8,$20,$0,$0,$0,DEC 24,CR,DEC2 Apt," ",DEC4 keycode,
                     " ", Note," ",
                     HEX2 clock(2),":",HEX2 clock(1)," ",
                     HEX2 clock(6),HEX2 clock(5),HEX2 clock(4),CR,$0A,CR]
  SERIN RX,Baud,500, LogErr3,[WAIT(">")]

  SEROUT TX,Baud,[$0A,$20,"Log.txt", CR]
  SERIN RX,Baud,500, LogCloseErr,[WAIT(">")]

DEBUG CR,? Apt, ? keycode, ASC ? Note    'this data went to History Log
DEBUG HEX2 clock(2), ":", HEX2 clock(1), ":", HEX2 clock(0), CR

DEBUG "20", HEX2 clock(6), "-", HEX2 clock(5), "-", HEX2 clock(4), CR
RETURN
'-----[ Logger Error checks for Log file]-----------------------------------------------
LogErr2:
   Note = "M"
   GOSUB InvalidCode
LogErr3:
   Note = "N"
   GOSUB InvalidCode
LogCloseErr:
   Note = "P"
   SEROUT TX,Baud,[$0A,$20,"Log.txt", CR]
   GOSUB InvalidCode
No_Log:
  SEROUT TX,Baud,[$9,$20,"Log2.txt", CR]      ' create second log file if log is corrupted
  SERIN RX,Baud,500, LogErr2,[WAIT(">")]

  SEROUT TX,Baud,[$8,$20,$0,$0,$0,DEC 24,CR,DEC2 Apt," ",DEC4 keycode,
                     " ", Note," ",
                     HEX2 clock(2),":",HEX2 clock(1)," ",
                     HEX2 clock(6),HEX2 clock(5),HEX2 clock(4),CR,$0A,CR]
  SERIN RX,Baud,500, LogErr3,[WAIT(">")]

  SEROUT TX,Baud,[$0A,$20,"Log2.txt", CR]
  SERIN RX,Baud,500, LogCloseErr,[WAIT(">")]
  GOSUB Main
' -----[ Use Keypad to Update Clock ]----------------------------------------------------
KP_Clock_Update:

  GOSUB Beep         ' 4 beeps for ready for time and date entry
  GOSUB Beep
  GOSUB Beep
  GOSUB Beep

  GOSUB GetKeyPad
  IF keyIn <>4 THEN GOSUB InvalidCode    'sub password
  GOSUB Beep
  GOSUB Beep2
  counter = 12
DO
  GOSUB GetKeyPad
    counter = counter - 1
    kpEntry(counter) = keyIn

LOOP UNTIL counter = 1

  clock(1) = kpEntry(2) * 10 + kpEntry(1)
     clock(1) = clock(1) // 60            'update mins
     clock(1) = (clock(1) / 10 << 4) + (clock(1) // 10)'decimal to BCD
  clock(2) = kpEntry(4) * 10 + kpEntry(3)
     clock(2) = clock(2) // 24            'update hours
     clock(2) = (clock(2) / 10 << 4) + (clock(2) // 10)'decimal to BCD
  clock(3) = kpEntry(5)
     clock(3) = clock(3) // 7            'update day of week
     clock(3) = (clock(3) / 10 << 4) + (clock(3) // 10)'decimal to BCD

  clock(4) = kpEntry(7) * 10 + kpEntry(6)
     clock(4) = clock(4) // 31            'update day of month
     clock(4) = (clock(4) / 10 << 4) + (clock(4) // 10)'decimal to BCD

  clock(5) = kpEntry(9) * 10 + kpEntry(8)
     clock(5) = clock(5) // 12            'update month
     clock(5) = (clock(5) / 10 << 4) + (clock(5) // 10)'decimal to BCD

  clock(6) = kpEntry(11) * 10 + kpEntry(10)
     clock(6) = (clock(6) / 10 << 4) + (clock(6) // 10)'decimal to BCD
  clock(0) = $00
  clock(7) = 0


  GOSUB Set_Clock
  GOSUB Get_Clock

  DEBUG CR, HEX2 clock(2), ":", HEX2 clock(1), ":", HEX2 clock(0), CR
  DEBUG ? clock(3), CR

  DEBUG "20", HEX2 clock(6), "-", HEX2 clock(5), "-", HEX2 clock(4), CR

RETURN


' --------[ I2C Clock Subroutines ] ----------------

Set_Clock:
 PAUSE 100
 I2COUT SDA, DS1307, 0, [STR clock\8]           ' update clock registers
RETURN

Get_Clock:
  PAUSE 100                           ' wait 100 ms  CHANGE IF MORE CODE IS ADDED !!!
  I2CIN SDA, DS1307, 0, [STR clock\8]  ' retrieve clock registers
RETURN

' --------[ Beeps ] ----------------
Beep:
  HIGH 14                'beep for ready
  PAUSE 200
  LOW 14
  PAUSE 100
RETURN

Beep2:
  HIGH 14                'beep for ready
  PAUSE 200
  LOW 14
  PAUSE 200
RETURN
'------------(  Code Update )----------------------------------
Code_Update:

  GOSUB Beep         ' 2 beeps for ready for Code update
  GOSUB Beep

  GOSUB GetKeyPad
  IF keyIn =2 THEN GOSUB Add_Code ELSEIF keyIn = 3 THEN GOSUB Delete_Code ELSE GOSUB InvalidCode

  RETURN
' --------[ Add PassCode ] ----------------
Add_Code:
  GOSUB Code_Loop
  GOSUB Check_Logger

  SEROUT TX,Baud,[$9,$20, DEC4 keycode, CR] ' creates file
  SERIN RX,Baud,500, LogErr2,[WAIT(">")]

  SEROUT TX,Baud,[$8,$20,$0,$0,$0,DEC 2,CR,DEC2 Apt,CR] 'writes Apt no to file
  SERIN RX,Baud,500, LogErr3,[WAIT(">")]

  GOSUB Close_Logger
  GOSUB Beep
  GOSUB Beep
  DEBUG CR,? Apt, ? keycode
RETURN
' --------[ Delete PassCode ] ----------------
Delete_Code:
  GOSUB Code_Loop
  GOSUB Check_Logger

 SEROUT TX,Baud,[$07,$20,DEC4 keycode,CR]  'deletes file
 SERIN RX,Baud,500,DeleteErr,[WAIT(">")]
  GOSUB Beep
  GOSUB Beep

  DEBUG ? keycode, CR
RETURN

DeleteErr:
   DEBUG "file delete error", CR
   GOSUB InvalidCode

' --------[ Loop for Code Input ] ----------------
Code_Loop:
GOSUB Beep
   counter = 0
   keycode = 0
DO
  GOSUB GetKeyPad
    counter = counter + 1
    kpEntry(counter) = keyIn

LOOP UNTIL counter = 6

    keycode = kpEntry(1) * 10
    keycode = keycode + kpEntry(2)
    keycode = keycode * 10
    keycode = keycode + kpEntry(3)
    keycode = keycode * 10
    keycode = keycode + kpEntry(4)
    Apt = kpEntry(5) * 10
    Apt = Apt + kpEntry(6)
RETURN

' --------[ Check Logger ] ----------------
Check_Logger:
 PAUSE 100                              ' Allow Time To Settle
 SEROUT TX, Baud, [CR]
 SERIN RX,Baud,500,Not_Found2,[WAIT(">")]
RETURN

Not_Found2:
  Note = 2
  GOSUB InvalidCode

' --------[ Clear Variables ] ----------------
Clear_Variables:
   counter = 0
   key = 0
   keyIn = 0
   Apt = 0
   Note = 0
   start(1) = 0
   keycode = 0
   HIGH 2              ' shut logger power off
RETURN
Post Reply