Change the world

Control Software

Download: Examples - Basic Input Output.zip

The following example programs are available to demonstrate the basic principles of input, output and delays:

ex1_flash_leds.c

Example program that turns on 8 LEDs for 250ms, then off for 250ms, repeatedly.

* 8 LEDs connected to PC7 - PC0

 

ex1b_flash_leds.c

Example program that turns on 8 LEDs for 250ms, then off for 250ms, repeatedly.

* 8 LEDs connected to PE15 - PE8 (LD3 - LD10 ON STM32F3-DISCOVERY BOARD)

 

ex1c_flash_leds.c

Example program that turns on 8 LEDs for 250ms, then off for 250ms, repeatedly.

* 8 LEDs connected to PC7 - PC0
* 8 LEDs connected to PE15 - PE8 (LD3 - LD10 ON STM32F3-DISCOVERY BOARD)

 

ex1d_flash_leds.c

Example program that turns on two sets of 8 LEDs for 250ms, then off for 250ms, repeatedly.  This example makes use of the predefined functions STM_EVAL_LEDInit(), STM_EVAL_LEDOff(), and STM_EVAL_LEDToggle() which are to be used with LD3 to LD10 on the STM32F3-Discovery board.

* 8 LEDs connected to PE15 - PE8 (LD3 - LD10 ON STM32F3-DISCOVERY BOARD)

 

ex2_flash_one_led.c

Example program that turns on an LED for 400ms, then off for 400ms, repeatedly.

* 1 LED connected to PC0

  

ex2b_flash_one_led.c

Example program that turns on an LED for 400ms, then off for 400ms, repeatedly.

* 1 LED connected to PE8 (LD4 ON STM32F3-DISCOVERY BOARD)

 

ex2c_flash_one_led.c

Example program that turns on an LED for 400ms, then off for 400ms, repeatedly.  This example makes use of the predefined functions STM_EVAL_LEDInit(), STM_EVAL_LEDOff(), and STM_EVAL_LEDToggle() which are to be used with LD3 to LD10 on the STM32F3-Discovery board.

* 1 LED connected to PE8 (LD4 ON STM32F3-DISCOVERY BOARD)

 

ex3_sw_leds.c

Reads the value of 8 switches and displays this value on 8 LEDs.

* 8 LEDs connected to PC7 - PC0
* 8 switches connected to PB8 - PB15 with pullup resitors  

 

ex4_button_led.c

Reads the value of button and then turns an LED on when the button is on otherwise the LED is turned off. 

* a pushbutton connected to PB8 with a pullup resitor
* a LED connected to PC0

 

 

ex4b_button_led.c

Reads the value of button and then turns an LED on when the button is on otherwise the LED is turned off. 

* a pushbutton connected to PA0 (USER BUTTON STM32F3-DISCOVERY BOARD)
* 1 LED connected to PE8 (LD4 ON STM32F3-DISCOVERY BOARD)

 

ex4c_button_led.c

Reads the value of button and then turns an LED on when the button is on otherwise the LED is turned off. This example makes use of the predefined functions STM_EVAL_LEDInit(), STM_EVAL_LEDOff(), and STM_EVAL_LEDOn(), STM_EVAL_PBInit(), and the UserButtonPressed variable which are to be used with LD3 to LD10 and the USER button on the STM32F3-Discovery board.    

* a pushbutton connected to PA0 (USER BUTTON STM32F3-DISCOVERY BOARD)
* 1 LED connected to PE8 (LD4 ON STM32F3-DISCOVERY BOARD)

 

ex4d_button_led.c

Reads the value of button and then turns an LED on when the button is on otherwise the LED is turned off. 

* a pushbutton connected to PB8 with a pullup resitor
* a LED connected to PC0

 

ex5_sw_leds_portb.c

Reads the value of 8 switches on PORTB (using the internal pullup resistors) and displays this value on 8 LEDs. 

* 8 LEDs connected to PC7 - PC0
* 8 switches connected to PB8 - PB15 with pullup resitors

 

ex6_sw_leds_truth.c

Reads the value of 3 switches and then controls the output of 8 LEDs as follows:

                  SW2 SW3 SW0 LEDs (0=OFF, 1=ON)

                   0   0   0  00000000

                   0   0   1  00001111

                   0   1   0  11110000

                   0   1   1  11111111

                   1   0   0  10101010

                   1   0   1  10101010

                   1   1   0  10101010

                   1   1   1  10101010

* 8 LEDs connected to PC7 - PC0
* 3 switches connected to PB15(SW2), PB14(SW1)and PB13(SW0) with pullup resitors

 

ex7_led_count.c

Increments a counter from 0 to 255 repeatedly in 200ms delays and display the count value on 8 LEDs.

* 8 LEDs connected to PC7 - PC0

 

ex8_button_count.c

Increments a counter from 0 to 255 when a button is pushed and released. The count value is displayed on 8 LEDs.  Due to the contact bounce effect on the button, the counter will count fairly inconsistend.  The example ex9_button_count_debounce.c will solve this.

* 8 LEDs connected to PC7 - PC0
* a pushbutton connected to PB8 with a pullup resitor

 

ex9_button_count_debounce.c

This is the upgrade of ex8_button_count.c to compensate for the debounce effect on the pushbutton which causes the inconsistend counting.

* 8 LEDs connected to PC7 - PC0
* a pushbutton connected to PB8 with a pullup resitor

 

ex10_button_count_function.c

Same as ex9_button_count_debounce.c, but uses a user defined function is_button_pressed() to debounce the input pushbutton's state.

* 8 LEDs connected to PC7 - PC0
* a pushbutton connected to PB8 with a pullup resitor

 

ex11_led_count_on_16bit_port.c

The same as example ex7_led_count.c, but demonstrates how to write to 8 bits on a 16-bit port without influencing the state of the other 8 bits.

* 8 LEDs connected to PC7 - PC0
* You can also connect 8 LEDs to PC15 - PC8 to prove that this value will not change while the system counts on PC7 - PC0