Button

Input of the button can be received.

 

Things to Prepare

CM-510 or 700

 

Theory

Electronic signals of the devices connected to the controller can be read through I/O Port of the micro controller.  You can see the status of pressed built-in switches through this example.

PORTC and PORTE are used in this example.  Please refer to Controller Port Map.

Source

The Example of CM-510

if(~PINE & BTN_UP)

PORTC &= ~LED_MANAGE;

else if(~PINE & BTN_DOWN)

PORTC &= ~LED_AUX;

else if(~PINE & BTN_LEFT)

PORTC &= ~LED_PROGRAM;

else if(~PINE & BTN_RIGHT)

PORTC &= ~LED_PLAY;

else if(~PIND & BTN_START)

PORTC = ~(LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY);

else PORTC = LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY;

 

You can see the pressed buttons through PORTD and PORTE, and LEDs can be turned on and off by controlling PORTC depending on the pressed buttons.

You can use macro function PIND and PINE to get input value through PORTD and PORTE..

PIND and PINE are 1 byte, and the pins of PORTD and PORTE are facing each bit.

Therefore, you can read the value of the certain pin through "&" operation etc.

 

 

The Example of CM-700

if(~PIND & BTN_START)

PORTC = ~(LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY);

else PORTC = LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY;

 

You can see the pressed buttons through PORTD, and LEDs can be turned on and off by controlling PORTC depending on the pressed buttons.

You can use macro fuction PIND to get the input value through PORTD.

PIND is 1 byte, and the pins of PORTD are facing each bit.

Therefore, you can read the value of the certain pin through "&" operation etc.

 

Result

If you press buttons, depending on pressed buttons, different LEDs are turned on.