;RUN ONCE CODE GOES HERE #no_table #no_data symbol Key_Value = b0 Key_Value = 0x00 symbol once = b1 once = 1 'Keypad pins output b.7, b.6, b.5, b.4 input b.3, b.2, b.1, b.0 high b.7 high b.6 high b.5 high b.4 'LED Pins output c.0, c.1, c.2, c.3 low c.0 low c.1 low c.2 low c.3 hsersetup B9600_8, $9 ;This sets the mode bits (most times it is $9 or $f) hserptr = 0 hserinflag = 0 ;Received values will be moved into B10, so clear it out b10 = 0x00 main: ;Check to see if a button is being pressed on the Keypad gosub Scan_Keypad if Key_Value != 0x00 then ;If a key is pressed, transmit it to VB serout c.6, T9600_8, (key_Value) end if ;Check to see if a value showed up in the UART while ;the uController is doing something else ;The incoming information was stored in the scratchpad if hserinflag != 0 then pause 10 ;In case it has not finished reading yet get 0, b10 gosub mail_call end if goto main mail_call: ;If block that does a job determined by VB button on form if b10 = "A" then ;if I got an X from VB - toggle C.0 toggle c.0 else if b10 = "B" then ;if I got a Y from VB - toggle C.1 toggle c.1 else if b10 = "C" then ;if I got an X from VB - toggle C.2 toggle c.2 else if b10 = "D" then ;if I got a Y from VB - toggle C.3 toggle c.3 else if b10 = "X" then ;if I got a X from VB - Reset all LEDs Low c.3 Low c.2 Low c.1 Low c.0 end if hserptr = 0 hserinflag = 0 b10 = 0x00 return Scan_Keypad: Key_Value = 0x00 'Assume no buttons are pressed and Key_Value is 0x00 pinsb = %01110000 'Set column 1 to ground pause 2 if pinb.3 = 0 then 'Look at the rows, if any are grounded then a button is pressed. Key_Value = "1" else if pinb.2 = 0 then Key_Value = "4" else if pinb.1 = 0 then Key_Value = "7" else if pinb.0 = 0 then Key_Value = "0" end if pinsb = %10110000 'Set column 2 to ground pause 2 if pinb.3 = 0 then ' Look at the rows, if any are grounded then a button is pressed. Key_Value = "2" else if pinb.2 = 0 then Key_Value = "5" else if pinb.1 = 0 then Key_Value = "8" else if pinb.0 = 0 then Key_Value = "F" end if pinsb = %11010000 'Set column 3 to ground pause 2 if pinb.3 = 0 then ' Look at the rows, if any are grounded then a button is pressed. Key_Value = "3" else if pinb.2 = 0 then Key_Value = "6" else if pinb.1 = 0 then Key_Value = "9" else if pinb.0 = 0 then Key_Value = "E" end if pinsb = %11100000 'Set column 4 to ground pause 2 if pinb.3 = 0 then ' Look at the rows, if any are grounded then a button is pressed. Key_Value = "A" else if pinb.2 = 0 then Key_Value = "B" else if pinb.1 = 0 then Key_Value = "C" else if pinb.0 = 0 then Key_Value = "D" end if pinsb = %11110000 'If no keys were pressed, Key_Value is 0x00 and that is returned. If Key_Value != 0x00 and once = 1 then once = 0 'If a key was pressed, 'return the ASCII value that is printed on the key. 'Variable once is set to 0 to prevent this if 'statement from running again. else if Key_Value != 0x00 and once = 0 then Key_Value = 0x00 'If a key was pressed, the value was returned, and the 'key is still being pressed, make Key_Value = 0x00 'so the program thinks nothing was pressed. else if Key_Value = 0x00 and once = 0 then once = 1 'If a key was released, make once = 1 'so the next key pressed will be returned End If return