'-------------------------------------------------------------- ' mega88.bas ' mega88 sample file ' (c) 2004, MCS Electronics '-------------------------------------------------------------- $regfile = "m48def.dat" $crystal = 8000000 $baud = 19200 Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Declare Sub Dididi Dim Di As Byte Dim Da As Byte Dim H As Byte Dim A As Byte Dim B As Byte Dim Opp As Byte Dim Ned As Byte $eeprom Di = 1 Da = 1 A = 0 B = 0 Opp = 1 Ned = 1 Readeeprom H , 10 If H = 0 Then H = 100 'Config Portd = Input Ddrb = &B0000_0011 '0=input 1=output Ddrd = &B0000_0110 Ddrc = &B0000_1100 Portc = &B0011_0000 'Pulup resistors Portd = &B0001_1000 Do Opp = Pind.3 Ned = Pind.4 Di = Pinc.4 Da = Pinc.5 If Opp = 0 Then H = H + 1 Portb.0 = 1 If H = 255 Then H = 254 Call Dididi End If If Ned = 0 Then H = H - 1 Portb.1 = 1 If H = 0 Then H = 1 Call Dididi End If If Di = 0 And Da = 0 Then If A = 0 Then Di = 0 Da = 1 End If If A = 1 Then Di = 1 Da = 0 End If End If If Di = 0 Then Portb.1 = 1 Portc.3 = 1 Waitms H Portb.0 = 0 Portb.1 = 0 Portc.3 = 0 Waitms H A = 1 End If If Da = 0 Then Portb.0 = 1 Portc.3 = 1 Waitms H Waitms H Waitms H Portb.0 = 0 Portb.1 = 0 Portc.3 = 0 Waitms H A = 0 End If Loop Sub Dididi Writeeeprom H , 10 Portb.0 = 1 Portb.1 = 1 Portc.3 = 1 Waitms H Portb.0 = 0 Portb.1 = 0 Portc.3 = 0 Waitms H Portb.0 = 1 Portb.1 = 1 Portc.3 = 1 Waitms H Portb.0 = 0 Portb.1 = 0 Portc.3 = 0 Waitms H Portb.0 = 1 Portb.1 = 1 Portc.3 = 1 Waitms H Portb.0 = 0 Portb.1 = 0 Portc.3 = 0 Waitms H Portb.0 = 1 Portb.1 = 1 Portc.3 = 1 Waitms H Portb.0 = 0 Portb.1 = 0 Portc.3 = 0 Waitms H Portb.0 = 1 Portb.1 = 1 Portc.3 = 1 Waitms H Portb.0 = 0 Portb.1 = 0 Portc.3 = 0 Waitms H End Sub End