'------------------------------------- ' ! D E M O P R O G R A M ! ' ' FOR Bascom AVR Simulator '------------------------------------- ' Code is consisted of 4 digits. ' 1 user code is entered in program. '------------------------------------- 'Project: CodeLockAVR - LCD ' File:codelcd-D1SIM.bas 'Copyright: Kripa PURI 'WWW: www.avr.4mg.com 'Device: Atmel AVR uC 'Date: 15.11.2007 '------------------------------------- $sim 'Instructs the compiler to generate empty wait loops for the WAIT and WAITMS statements. 'Instruction allows faster simulation. ' '! In AVR Simulator run the simulation with the command: '! Step into code (F8) ' '! SET LCD PIN CONNECTIONS in menu: 'Options => Compiler => Output => LCD ' ' Lcd type = 16 * 2 ' DB4 = Portb.0 , DB5 = Portb.1 , DB6 = Portb.2 , DB7 = Portb.3 ' RS = Portd.5, Enable = Portd.6 $regfile = "2313def.dat" $crystal = 4000000 Dim Keyread As Byte Dim Key As Byte Dim Code As Word Dim Mycode As Word Dim Digits As Byte Dim Point As Byte Ddrd = 255 Portd = 0 Relay Alias Portd.4 Beep Alias Portd.3 Config Kbd = Portb , Debounce = 40 Config Lcd = 16 * 2 '------------------------------------- Mycode = 5060 '------------------------------------- Do Cls Cursor Off Noblink Lcd "WWW.AVR.4MG.COM" Wait 2 Lowerline Lcd "CodeLockAVRdemo" Wait 4 Cls Set Beep Waitms 100 Reset Beep Waitms 100 Begin: Code = 0 Digits = 0 Point = 0 Scan: Cls Lcd " Enter code" Do Keyread = Getkbd() If Keyread <> 16 Then Gosub Gotkey Waitms 100 If Digits = 4 Then If Code = Mycode Then Goto Opendoor Else Goto Error End If End If Loop Loop Gotkey: Ddrb = 255 Set Beep Waitms 100 Reset Beep Waitms 100 Key = Lookup(keyread , Dta) Incr Digits Point = Digits + 6 Locate 2 , Point Lcd Key Code = Code * 10 Code = Code + Key Return Dta: Data 1 , 2 , 3 , 13 , 4 , 5 , 6 , 14 , 7 , 8 , 9 , 15 , 11 , 0 , 12 , 16 Error: Cls Lcd " Code wrong" Waitms 100 Set Beep Wait 3 Reset Beep Wait 20 Goto Begin Ok: Waitms 100 Set Beep Waitms 200 Reset Beep Waitms 200 Set Beep Waitms 200 Reset Beep Return Opendoor: Cls Lcd " Code accepted" Gosub Ok Lowerline Lcd " Unlocked" Waitms 300 Set Relay Wait 1 Reset Relay Wait 1 Goto Begin