{ ***************************************************************************** * Name : JUNEBUG.BAS * * Author : William Richardson, Mike Webb * * Notice : Copyright (c) 2008 blueroomelectronics * * : All Rights Reserved * * Date : 2/29/2008 * * Version : 0.93beta * * Notes : * * : * ***************************************************************************** } Module Junebug Device = 18F1320 Public Sub LED(x As Byte) Select x Case 1 // LED 1 TRISA.7 = 1 High(PORTA.0) Low (PORTA.6) Case 2 // LED 2 TRISA.7 = 1 Low (PORTA.0) High(PORTA.6) Case 3 // LED 3 TRISA.0 = 1 High(PORTA.6) Low (PORTA.7) Case 4 // LED 4 TRISA.0 = 1 Low (PORTA.6) High(PORTA.7) Case 5 // LED 5 TRISA.6 = 1 Low (PORTA.0) High(PORTA.7) Case 6 // LED 6 TRISA.6 = 1 High(PORTA.0) Low (PORTA.7) Else // All LEDs Off TRISA.0 = 1 TRISA.6 = 1 TRISA.7 = 1 End Select End Sub Function GetBit(Bin As Byte) As Byte Dim I As Byte GetBit=0 For I=1 To 8 If ((Bin And 1) = 1) Then GetBit=I EndIf Bin=Bin>>1 Next End Function Dim OldKeys As Byte Dim OldEdges As Byte Dim KeyCount As Byte Const KeyDelay=30 //initial delay before repeating in 10mS Const KeyRepeat = 12 //repeat delay in 10mS Public Function ReadKeys() As Byte Dim Keys As Byte Dim Edges As Byte INTCON2.7=0 //WPUs on port B ReadKeys=0 //return Zero unless key pressed Keys=0 If(PORTB.0=0) Then //move from port B to Keys Keys=Keys Or 1 EndIf If(PORTB.2=0) Then Keys=Keys Or 2 EndIf If(PORTB.5=0) Then Keys=Keys Or 4 EndIf Edges=(Keys Xor OldKeys) And Keys //edges contains new key presses If Edges <> 0 Then //if new keypress OldEdges=Edges //keep copy of it for repeating KeyCount=KeyDelay //set initial delay ReadKeys=GetBit(Edges) //return key number EndIf If Keys<>0 Then //repeating? KeyCount=KeyCount-1 //Yes, so count down If(KeyCount=0) Then //time to repeat yet? ReadKeys=GetBit(OldEdges) //yes, return key number KeyCount=KeyRepeat //set repeat count EndIf EndIf OldKeys=Keys //keep copy for next time End Function Config OSC = INTIO2, WDT = OFF, LVP = OFF