Question
Hi, I'm trying to solve this problem in C but having difficulity with the implementation. Thanks. Code: #include #include #include #include void setup_led_buttons( void )
Hi, I'm trying to solve this problem in C but having difficulity with the implementation. Thanks.
Code:
#include
void setup_led_buttons( void ) { // (a) Set the CPU speed to 8MHz (you must also be compiling at 8MHz).
// (b) Configure the data direction register for Port B to enable output // to LED0 and LED1. The data direction for LED0 is controlled by Pin 2, // while that for LED1 is controlled by Pin 3. No other pins should be // affected.
// (c) Turn off LED0, LED1, and all other outputs connected to Port B, by // clearing all bits in the Port B output register.
// (d) Configure the data direction register for Port F to enable input // from the left button (SW1 on the pin-out diagram) and right button // (SW2 on the pin-out diagram). SW1 is activated by clearing Pin 6, and // SW2 is activated by clearing Pin 5. No other pins should be affected by // this operation. }
void process_led_buttons( void ) { // (e) Test the relevant pins in the Port F input register. If the // bits corresponding to _both_ SW1 and SW2 are set, turn off _both_ LEDs. No // pins other than those controlling LED0 and LED1 should be affected by // this action.
// (f) Otherwise, if the bit corresponding to SW1 is set, turn on LED0 // while ensuring that no other pins are affected.
// (g) Otherwise, if the bit corresponding to SW2 is set, turn on LED1 // while ensuring that no other pins are affected. }
int main(void) { setup_led_buttons();
while ( 1 ) { process_led_buttons(); _delay_ms(100); }
return 0; }
lete the implementation ofthe setup led buttons and process led buttons unctions. The hashtags for this exercise are: #cab202 and #cab202 LedButtons r completing this exercise you will be able to detect when the user has depressed the two buttons, and control the LEDs mounted on the Teensy circuit board. You will: Control the CPU clock speed to enable accurate timing Set up a data direction register to enable digital output to the LEDs. Write data to an output register to control the LEDs. Set up a data direction register to enable digital input from the buttons. Test the pins in an input register to determine if buttons are pressed. . To complete th e program, follow the instructions detailed in the in-line comments in the skeleton code below efer to the Teensy Pin-out diagram (a subset of the QUT Teensy Schematic diagram) to identify the Port and Pin associated with each LED and switch. Note that the relevant witches are labelled SW1 and SW2 on the pin-out diagram, but are labelled SW2 and SW3 on the Teensy itself. Use the labels from the pin-out diagram rather than those printed on he Teensy TEENSY PINOUT VCC uc1 Teensy GND B0 B1 B2 B3 B7 DO D1 D2 D3 C6 C7 VCC SWCENTER FO F1 F4 F5 F6 SW SW1 LCD SCK LCD DIN LCD DC LCD RST LCD SCE SWD SWC B6 B5 B4 D7 D6 RX TXStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started