'================================================================================ 'RoboSwarm Exec 'version 0.1 'This section remains in every program '-------------------------------------------------------------------------------- $regfile = "m128def.dat" $crystal = 16000000 $baud = 19200 ' baud rate on UART#1 $baud1 = 19200 ' baud rate on UART#2 $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space '$sim ' uncomment when running simulation '-------------------------------------------------------------------------------- 'CONSTANTS 'The Constants is for the LCD. This should remain in every program that uses ' the LCD for display '-------------------------------------------------------------------------------- ' We dont use the R/W Option Of The Lcd In this version So Connect To Ground 'E2 = '***optional for lcd with 2 chips ***not needed*** 'Db4 = Portc.4 'the data bits must be in a nibble to save code 'Db5 = Portc.5 ' 'Db6 = Portc.6 ' 'Db7 = Portc.7 ' $lib "lcd4busy.lib" Const _lcdport = Portc Const _lcdddr = Ddrc Const _lcdin = Pinc Const _lcd_e = 2 'E = Portc.2 Const _lcd_rw = 1 'RW = Portc.1 Const _lcd_rs = 0 'Rs = Portc.0 Const Down = 0 Const Up = 1 '-------------------------------------------------------------------------------- 'CONFIG MCU ' The LCD is configured for this mcu board ' All the port i/o pins are confgured to match the mcu board. '-------------------------------------------------------------------------------- 'The M128 has an extended UART. 'when CONFIG COMx is not used, the default N,8,1 will be used 'Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Open "com2:" For Binary As #2 Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.2 , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Postc.7 Config Lcd = 16 * 2 Config Pina.0 = Input ' Switches Config Pina.1 = Input ' Switches Config Pina.2 = Input ' Switches Config Pina.3 = Input ' Switches Config Pina.4 = Input ' Switches Config Pina.5 = Input ' Config Pina.6 = Input ' Config Pina.7 = Input ' 'Config Pinb.0 = Input ' 'Config Pinb.1 = Input ' 'Config Pinb.2 = Input ' 'Config Pinb.3 = Input ' 'Config Pinb.4 = Input ' 'Config Pinb.5 = Input ' 'Config Pinb.6 = Input ' 'Config Pinb.7 = Input ' 'Config Pinc.0 = Output ' 'Config Pinc.1 = Output ' 'Config Pinc.2 = Output ' 'Config Pinc.3 = Output ' 'Config Pinc.4 = Output ' 'Config Pinc.5 = Output ' 'Config Pinc.6 = Output ' 'Config Pinc.7 = Output ' 'Config Pind.0 = Input ' 'Config Pind.1 = Input ' 'Config Pind.2 = Input 'uart1 rxd1 'Config Pind.3 = Input 'uart1 txd1 'Config Pind.4 = Input ' 'Config Pind.5 = Input ' 'Config Pind.6 = Input ' 'Config Pind.7 = Input ' 'Config Pine.0 = Input ' 'Config Pine.1 = Input ' 'Config Pine.2 = Input ' 'Config Pine.3 = Input ' 'Config Pine.4 = Input ' 'Config Pine.5 = Input ' 'Config Pine.6 = Input ' 'Config Pine.7 = Input ' 'Config Pinf.0 = Input ' adc0 'Config Pinf.1 = Input ' adc1 'Config Pinf.2 = Input ' adc2 'Config Pinf.3 = Input ' adc3 'Config Pinf.4 = Input ' adc4 'Config Pinf.5 = Input ' adc5 'Config Pinf.6 = Input ' adc6 'Config Pinf.7 = Input ' adc7 'Config Ping.0 = Input ' 'Config Ping.1 = Input ' 'Config Ping.2 = Input ' '-------------------------------------------------------------------------------- 'DEFINES 'define the alias names of the port pins '-------------------------------------------------------------------------------- Up_pin Alias Pina.0 'Up key(Up) Lt_pin Alias Pina.1 'Lt key(Left) Ct_pin Alias Pina.2 'Ct key(Center) Rt_pin Alias Pina.3 'Rt key(Right) Dw_pin Alias Pina.4 'Dw key(Down) '-------------------------------------------------------------------------------- 'VARIABLES 'define all the variable used in RSExec '-------------------------------------------------------------------------------- Dim Up_bit As Bit Dim Lt_bit As Bit Dim Ct_bit As Bit Dim Rt_bit As Bit Dim Dw_bit As Bit Dim A As Byte 'key value Dim Menu_type As Byte 'menu type Dim Menu_level As Byte 'menu level Dim X_lcd_curr As Byte Dim Y_lcd_curr As Byte Dim X_lcd_prev As Byte Dim Y_lcd_prev As Byte Dim Blinklcd As Word '-------------------------------------------------------------------------------- 'INITIALIZE 'set all the variable to their inital value '-------------------------------------------------------------------------------- Up_bit = Up Lt_bit = Up Ct_bit = Up Rt_bit = Up Dw_bit = Up A = 0 Menu_level = 0 Menu_type = 0 X_lcd_curr = 2 Y_lcd_curr = 1 X_lcd_prev = 2 Y_lcd_prev = 1 '-------------------------------------------------------------------------------- 'HELLO WORLD 'Display a Hello World screen at bootup '-------------------------------------------------------------------------------- Initlcd Cls Cls 'Lcd"1234567890123456" Lcd Version() 'show date and time of compilation Wait 1 Cls Lcd " " Lcd "RoboSwarmExec v0.1" 'send output to LCD For A = 1 To 32 Shiftlcd Left 'shift the text to the left Waitms 200 'wait a moment Next Cls Home Lcd " Welcome to " 'send output to LCD Lowerline Lcd " RoboSwarm " 'send output to LCD Wait 1 Cls Gosub Main_menu '-------------------------------------------------------------------------------- 'MENU ' This menun loop checks for which button is pressed '-------------------------------------------------------------------------------- Do For Blinklcd = 1 To 10000 If Ct_bit = Up Then Debounce Ct_pin , 0 , Ct_on , Sub Else Debounce Ct_pin , 1 , Ct_off , Sub End If If Up_bit = Up Then Debounce Up_pin , 0 , Up_on , Sub Else Debounce Up_pin , 1 , Up_off , Sub End If If Lt_bit = Up Then Debounce Lt_pin , 0 , Lt_on , Sub Else Debounce Lt_pin , 1 , Lt_off , Sub End If If Rt_bit = Up Then Debounce Rt_pin , 0 , Rt_on , Sub Else Debounce Rt_pin , 1 , Rt_off , Sub End If If Dw_bit = Up Then Debounce Dw_pin , 0 , Dw_on , Sub Else Debounce Dw_pin , 1 , Dw_off , Sub End If If Ct_bit = Down Then Goto Skipblink Locate Y_lcd_curr , X_lcd_curr If Blinklcd < 5000 Then Lcd "+" Else Lcd "X" End If Skipblink: Next Blinklcd Loop '-------------------------------------------------------------------------------- 'FUNCTION: Center Menu Button 'This processes the Enter button '-------------------------------------------------------------------------------- Ct_on: Porta.6 = 1 'Turn LED on Ct_bit = Down Cls Select Case Y_lcd_curr Case 1: 'main menu Gosub Toprow Case 2: 'main menu Gosub Botrow End Select Return Toprow: Cls Select Case Menu_type Case 0: 'main menu If X_lcd_curr = 2 Then Gosub Diag_menu End If If X_lcd_curr = 10 Then Gosub Test_menu End If Case 1: 'diag menu If X_lcd_curr = 2 Then Gosub Diag_menu End If If X_lcd_curr = 10 Then Gosub Diag_menu End If Case 2: 'test menu If X_lcd_curr = 2 Then Gosub Test_menu End If If X_lcd_curr = 10 Then Gosub Test_menu End If Case 3: 'mon menu If X_lcd_curr = 2 Then Gosub Mon_menu End If If X_lcd_curr = 10 Then Gosub Mon_menu End If Case 4: 'appl menu If X_lcd_curr = 2 Then Gosub Appl_menu End If If X_lcd_curr = 10 Then Gosub Appl_menu End If Case 5: 'diag1 menu If X_lcd_curr = 2 Then Gosub Led_test End If If X_lcd_curr = 10 Then Gosub Rs232_test End If Case 6: 'diag2 menu If X_lcd_curr = 2 Then Gosub Edge_test End If If X_lcd_curr = 10 Then Gosub Gp2d_test End If Case 7: 'diag3 menu If X_lcd_curr = 2 Then Gosub Comp_test End If If X_lcd_curr = 10 Then Gosub Rf_test End If End Select Return Botrow: Cls Select Case Menu_type Case 0: 'main menu If X_lcd_curr = 2 Then Gosub Mon_menu End If If X_lcd_curr = 10 Then Gosub Appl_menu End If Case 1: 'diag menu If X_lcd_curr = 2 Then Gosub Diag_menu End If If X_lcd_curr = 10 Then Gosub Diag_menu End If Case 2: 'test menu If X_lcd_curr = 2 Then Gosub Test_menu End If If X_lcd_curr = 10 Then Gosub Test_menu End If Case 3: 'mon menu If X_lcd_curr = 2 Then Gosub Mon_menu End If If X_lcd_curr = 10 Then Gosub Mon_menu End If Case 4: 'appl menu If X_lcd_curr = 2 Then Gosub Appl_menu End If If X_lcd_curr = 10 Then Gosub Appl_menu End If Case 5: 'diag1 menu If X_lcd_curr = 2 Then Gosub Spkr_test End If If X_lcd_curr = 10 Then Gosub Motor_test End If Case 6: 'diag2 menu If X_lcd_curr = 2 Then Gosub Beac_test End If If X_lcd_curr = 10 Then Gosub Rfid_test End If Case 7: 'diag3 menu If X_lcd_curr = 2 Then Gosub No_test1 End If If X_lcd_curr = 10 Then Gosub No_test2 End If End Select Return Ct_off: Ct_bit = Up Porta.6 = 0 'Turn LED off Wait 1 If Menu_type > 4 Then Return Cls If Menu_level = 0 Then Gosub Main_menu If Menu_level = 1 Then Gosub Diag_menu1 If Menu_level = 2 Then Gosub Diag_menu2 If Menu_level = 3 Then Gosub Diag_menu3 Return '-------------------------------------------------------------------------------- 'FUNCTION: Up Arrow Menu Button 'This processes the Up button 'Move Menu Cursor to 1st selection '-------------------------------------------------------------------------------- Up_on: Up_bit = Down X_lcd_prev = X_lcd_curr Y_lcd_prev = Y_lcd_curr If Y_lcd_prev = 1 Then Goto Up_skip X_lcd_curr = X_lcd_prev Y_lcd_curr = Y_lcd_prev - 1 Locate Y_lcd_prev , X_lcd_prev Lcd "+" Locate Y_lcd_curr , X_lcd_curr Lcd "X" If Y_lcd_prev = 2 Then Goto Up_skip2 Up_skip: If Menu_level = 0 Then Goto Up_skip2 Y_lcd_curr = 2 'update cursor position Menu_level = Menu_level - 1 If Menu_level = -1 Then Menu_level = 0 If Menu_level = 0 Then Gosub Main_menu If Menu_level = 1 Then Gosub Diag_menu1 If Menu_level = 2 Then Gosub Diag_menu2 If Menu_level = 3 Then Gosub Diag_menu3 Up_skip2: Porta.6 = 1 'Turn LED on Return Up_off: Up_bit = Up Porta.6 = 0 'Turn LED off Return '-------------------------------------------------------------------------------- 'FUNCTION: Down Arrow Menu Button 'This processes the Down button 'Move Menu Cursor to 4th selection '-------------------------------------------------------------------------------- Dw_on: Dw_bit = Down X_lcd_prev = X_lcd_curr Y_lcd_prev = Y_lcd_curr If Y_lcd_prev = 2 Then Goto Dw_skip X_lcd_curr = X_lcd_prev Y_lcd_curr = Y_lcd_prev + 1 Locate Y_lcd_prev , X_lcd_prev Lcd "+" Locate Y_lcd_curr , X_lcd_curr Lcd "X" If Y_lcd_prev = 1 Then Goto Dw_skip2 Dw_skip: If Menu_level = 0 Then Goto Dw_skip2 If Menu_level = 3 Then Goto Dw_skip3 Y_lcd_curr = 1 'update cursor position Menu_level = Menu_level + 1 If Menu_level = 4 Then Menu_level = 3 If Menu_level = 0 Then Gosub Main_menu If Menu_level = 1 Then Gosub Diag_menu1 If Menu_level = 2 Then Gosub Diag_menu2 Dw_skip3: If Menu_level = 3 Then Gosub Diag_menu3 Dw_skip2: Porta.6 = 1 'Turn LED on Return Dw_off: Dw_bit = Up Porta.6 = 0 'Turn LED off Return '-------------------------------------------------------------------------------- 'FUNCTION: Left Arrow Menu Button 'This processes the Left button 'Move Menu Cursor to 2nd selection '-------------------------------------------------------------------------------- Lt_on: Lt_bit = Down X_lcd_prev = X_lcd_curr Y_lcd_prev = Y_lcd_curr If X_lcd_prev = 2 Then Goto Lt_skip X_lcd_curr = X_lcd_prev - 8 Y_lcd_curr = Y_lcd_prev Locate Y_lcd_prev , X_lcd_prev Lcd "+" Locate Y_lcd_curr , X_lcd_curr Lcd "X" Lt_skip: Porta.6 = 1 'Turn LED on Return Lt_off: Lt_bit = Up Porta.6 = 0 'Turn LED off Return '-------------------------------------------------------------------------------- 'FUNCTION: Right Arrow Menu Button 'This processes the Right button 'Move Menu Cursor to 3rd selection '-------------------------------------------------------------------------------- Rt_on: Rt_bit = Down X_lcd_prev = X_lcd_curr Y_lcd_prev = Y_lcd_curr If X_lcd_prev = 10 Then Goto Rt_skip X_lcd_curr = X_lcd_prev + 8 Y_lcd_curr = Y_lcd_prev Locate Y_lcd_prev , X_lcd_prev Lcd "+" Locate Y_lcd_curr , X_lcd_curr Lcd "X" Rt_skip: Porta.6 = 1 'Turn LED on Return Rt_off: Rt_bit = Up Porta.6 = 0 'Turn LED off Return '-------------------------------------------------------------------------------- 'FUNCTION: Diagnostics Menu 'This processes the Diag menu 'This is contains several low level diagnostics to check the hardware '-------------------------------------------------------------------------------- Diag_menu: Menu_type = 1 Menu_level = 1 Select Case Menu_level Case 1 : Gosub Diag_menu1 Menu_type = 5 Case 2 : Gosub Diag_menu2 Menu_type = 6 Case 3 : Gosub Diag_menu3 Menu_type = 7 Case Else : Cls Lcd "NO GOOD" End Select Return '-------------------------------------------------------------------------------- 'FUNCTION: Test Menu 'This processes the Test menu 'This contains several Functional Tests to check the robot functions '-------------------------------------------------------------------------------- Test_menu: Menu_type = 2 Menu_level = 1 Lcd "TEST Menu" Lowerline Lcd "functional test" Menu_type = 0 ' Menu_level = 0 ' Return '-------------------------------------------------------------------------------- 'FUNCTION: Monitor Menu 'This processes the Monitor menu 'This contains several utilities for managing the robot operations '-------------------------------------------------------------------------------- Mon_menu: Menu_type = 3 Menu_level = 1 Lcd "MON Menu" Lowerline Lcd "Operator Utils" Menu_type = 0 ' Menu_level = 0 ' Return '-------------------------------------------------------------------------------- 'FUNCTION: Application Menu 'This processes the Appl menu 'This contains several application programs for different contests '-------------------------------------------------------------------------------- Appl_menu: Menu_type = 4 Menu_level = 1 Lcd "APPL Menu" Lowerline Lcd "Contest pgms" Menu_type = 0 ' Menu_level = 0 ' Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Menu level=0, menu type=1 'Display the Main Menu '-------------------------------------------------------------------------------- Main_menu: Menu_type = 0 Home Upper Lcd "[+]DIAG [+]TEST " ' Lowerline Lcd "[+]MON [+]APPL " ' Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Diag Menu level=1, menu type=2 'Display the Diag Menu 1 '-------------------------------------------------------------------------------- Diag_menu1: Menu_type = 5 Home Upper Lcd "[+]LED [+]RS232" ' Lowerline Lcd "[+]Spkr [+]Motor" Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Diag Menu level=2, menu type=2 'Display the Diag Menu 2 '-------------------------------------------------------------------------------- Diag_menu2: Menu_type = 6 Home Upper Lcd "[+]Edge [+]GP2D " ' Lowerline Lcd "[+]Beac [+]RFID " ' Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Diag Menu level=3, menu type=2 'Display the Diag Menu 3 '-------------------------------------------------------------------------------- Diag_menu3: Menu_type = 7 Home Upper Lcd "[+]Comp [+]RF " ' Lowerline Lcd "[+]n/a [+]n/a " ' Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Led test level=5, menu type=2 'Run the LED Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Led_test: Cls Lcd "Running" Lowerline ' Lcd "Led_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: RS232 Test level=5, menu type=2 'Run the RS232 Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Rs232_test: Cls Lcd "Running" Lowerline ' Lcd "Rs232_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Spkr Test level=5, menu type=2 'Run the Speaker Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Spkr_test: Cls Lcd "Running" Lowerline ' Lcd "Spkr_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Motor Test level=5, menu type=2 'Run the Motor Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Motor_test: Cls Lcd "Running" Lowerline ' Lcd "Motor_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Edge Test level=6, menu type=2 'Run The Edge Detector Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Edge_test: Cls Lcd "Running" Lowerline ' Lcd "Edge_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: GP2D Test level=6, menu type=2 'Run The GP2D12 IR Ranger Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Gp2d_test: Cls Lcd "Running" Lowerline ' Lcd "Gp2d_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Beacon Test level=6, menu type=2 'Run the IR Beacon Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Beac_test: Cls Lcd "Running" Lowerline ' Lcd "Beacon_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: RFID Test level=6, menu type=2 'Run the RFID Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Rfid_test: Cls Lcd "Running" Lowerline ' Lcd "Rfid_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: Compass Test level=7, menu type=2 'Run the Compass Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Comp_test: Cls Lcd "Running" Lowerline ' Lcd "Compass_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: RF Test level=7, menu type=2 'Run the RF Test '******************************ENTER YOUR CODE HERE************************ '-------------------------------------------------------------------------------- Rf_test: Cls Lcd "Running" Lowerline ' Lcd "Rf_test" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: No Test 1 level=7, menu type=2 'No Test is defined here '-------------------------------------------------------------------------------- No_test1: Cls Lcd "Running" Lowerline ' Lcd "No_test1" Menu_type = 1 ' Wait 1 Return '-------------------------------------------------------------------------------- 'FUNCTIONS: No Test 2 level=7, menu type=2 'No Test is defined here '-------------------------------------------------------------------------------- No_test2: Cls Lcd "Running" Lowerline ' Lcd "No_test2" Menu_type = 1 ' Wait 1 Return '============================================================================== End