embedded C code and functions

Intro to embedded C code and functions In a previous lab, you learned how to detect switches, blink LEDs, and use delays, making use of…

Intro
to embedded C code and functions

In a previous lab, you learned how to detect switches, blink LEDs,
and use delays, making use of subroutines for good structure. In this
lab, you will learn basic C language and make use of functions to
perform the desired tasks. Use code warrior C .

Part 1) Write a MAIN function, GPIO functions, and a delay function
that does the following: Initialize GPIO for PORTB

Perform other initialization functions if needed While (1)

Set_GPIO_Bits() //
set all 4 bits = 1 Delay_10ms(50) // delay 10*50ms = 500ms
Clr_GPIO_Bits() // clear all 4 bits = 0 Delay_10ms(50) // delay
10*50ms = 500ms

EndWhile

This should blink the LEDs at a rate of a half second per blink.
Allow your instructor to verify the delay timing.

Part
2) After your delay timing has been tweaked, add the following
functions and make the changes required in main to perform as
follows:

MAIN P-Code

Perform Initialization (GPIO and stack) While (1) { meaning always
true}

switch_state = Read_Switches() // returns switch settings in variable
called switch_state If switch_state == left

Scroll_Left(1) // scroll LEDs left 1 bit Delay_10ms(25) { 250 ms }

Else If switch_state == right

Scroll_Right(1) // scroll LEDs right 1 bit Delay_10ms(25)

Else If switch_state == both left and right Set_GPIO_Bits() // set
all 4 bits = 1 Delay_10ms(50) // delay 10*50ms = 500ms
Clr_GPIO_Bits() // clear all 4 bits = 0

Delay_10ms(50) // delay 10*50ms = 500ms Else All_LEDs_Off() // turn
all LEDS off

Endif Endif

Endif EndWhile
Let’s block ads! (Why?)

Do you need any assistance with this question?
Send us your paper details now
We’ll find the best professional writer for you!

 



error: Content is protected !!