PS2SetKBLeds

Syntax:

    PS2SetKBLeds (LedStatus)

Command Availability:

Available on all microcontrollers.

Explanation:

This routine will turn the status LEDs on a keyboard on or off. LedStatus is a variable, of which the lower 3 bits correspond to the 3 LEDs. Bit 0 is for Scroll Lock, bit 1 controls Num Lock and bit 2 controls Caps Lock.

Note that this routine does not alter the status variables within the INKEY routine - so even if the Caps Lock LED is turned on, Caps Lock will stay off.

Example:

	'A spinning LED program for a keyboard
	'Will flash Num Lock, then Caps Lock, then Scroll Lock.

	'Hardware settings
	#chip 16F88, 8

	#define PS2Clock PORTB.2
	#define PS2Data PORTB.3
	#define PS2_DELAY 10 ms

	'Main Loop
	Do

		'Turn on only Num Lock (bit 1)
		PS2SetKBLeds b'00000010'          ' <<< the PS2SetKBLeds instruction
		Wait 250 ms

		'Turn on only Caps Lock (bit 2)
		PS2SetKBLeds b'00000100'
		Wait 250 ms

		'Turn on only Scroll Lock (bit 0)
		PS2SetKBLeds b'00000001'
		Wait 250 ms

	Loop

Key line: PS2SetKBLeds b'00000010' — sets bit 1 (Num Lock) high and the other status LEDs low, turning on only the Num Lock LED; this does not affect the actual Caps Lock/Num Lock/Scroll Lock state tracked by InKey, only the physical LEDs.

See Also:

  • PS/2 Overview — category overview
  • InKey — related command in the same category
  • PS2ReadByte — related command in the same category