Documente Academic
Documente Profesional
Documente Cultură
show numbers that will count up. The key matrix can be read easily through the command KEYPAD. pressed. If you look
carefully at the keypad, you will see that scancode does not match the actual key In order to read the correct key, we will use a KEYTABLE before outputting the value to the CSG.
12 13 14 15
P0 P1 P2 P3
1 2 3
<Filename: keypadnum.cul>
Const Device = CB280 Set I2c 9,8 Dim I As Integer Dim K As Integer
1 4 7
ESC
11
P4 P5 P6 P7
2 5 8 0
3 6 9
CLR
ST OP
The CSG module is a 4 digit seven segment LED module that can be connected via CUNET or I2C protocol to display numbers and custom characters.
Loop
End If
input is received, it is displayed to the CSG module as a 4 digit number. number is stored into the variable K, which is in BCD code. function BCD2BIN to convert the BCD value back into binary.
If I < 10 Then K = K << 4 K = K + I Csghex 0,K End If ' ' ' Do While Keypad(0) < 255 Loop M = Bcd2bin(K) Debug Dec M,CR End If Loop WAIT UNTIL KEY DEPRESS
Ekeypad
Variable = EKEYPAD( portblockIn, portblockOut) Variable : Variable to store results (Returns Byte) PortblockIn : Port Block to receive input (Input) PortblockOut : Port Block to output (Output) This command EKEYPAD extends KEYPAD to read up to 64 key inputs. Blocks can be used to read up to 64 key inputs. Block must be selected separately. For ports not used within the input Port Block, a resistor must be connected to 5V. This pin may not be used for other purpose when using this command. For ports not used within the output Port Block, they can be left in OPEN state. This Two Port
< 255, we will wait until a key is unpressed which will return a scancode of 255. is to let the processor stop reading input while a key is pressed. fast.
processor might receive multiple key inputs since execution time of CUBLOC is very
0 1
By using _D(0) = M, you can pass the scancode value to relay D0 of LADDER LOGIC. If you need to use a keypad in LADDER, you can modify this code a little bit to get your results quick.
2 3 4 5 6 7
8 9 10 11 12 13 14 15
Keypad
Variable = KEYPAD( PortBlock) Variable : Variable to store results (Returns Byte) PortBlock : Port Block Use this command Keypad to read input from keypad. read a 4 by 4 keypad input. A Port Block can be used to
Port Block and keypad output can be connected to higher 4 bits of the Port Block. Please refer to the below diagram.
4 5 6 7
8 9
10
12 13 14 15
0 1 2 3
1 2 3
11
4 5 6 7