# ARM Cortex Assignment Help

#### Lux11

Joined Mar 6, 2021
6
I need help writing these functions for my assignment.

1) A function int ReadSwitches(void) that reads the slide switch bank and returns the current value, encoded as a binary number.

2) A function void DisplayHex(int value) that shows the hex equivalent of value on the lowestorder seven segment display. The easiest way to do this is with a look-up table (array) of values corresponding to the LEDs you want to light up to show a specific value. For example, if you want to display “1”, you want to turn on LED segments 1&2 in the picture. So your array would contain the following (among other things): lookUpTable[1]=0x06;

3) A main routine that blinks the lowest seven segment display ON and OFF. When ON, it should display the hex equivalent of the four-bit number encoded by the lowest four bits of the slide switch bank and this value should update as you change the switch positions. You can use the same delay loop from Part 1 to time the blinking.

The slide switches are memory mapped to address 0xFF200040 (called SW_BASE in address_map_arm.h).

The lower order four seven segment displays are mapped to address 0xFF200020 (called HEX3_HEX0_BASE in address_map_arm.h).

These are the requirements for the functions. Thank you for helping in advance.

#### Papabravo

Joined Feb 24, 2006
17,009

#### Walter Literowich

Joined Mar 15, 2018
40
you need help to become a responsible individual. this is your assignment
you cannot grow if you have this attitude:
Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. Start learning to fish

#### Lux11

Joined Mar 6, 2021
6
I am very new to coding C so I need help writing these functions. I am having trouble starting this code and don't exactly know all the functions mentioned within the assignment.

#### nsaspook

Joined Aug 27, 2009
8,780
I am very new to coding C so I need help writing these functions. I am having trouble starting this code and don't exactly know all the functions mentioned within the assignment.

#### BobaMosfet

Joined Jul 1, 2009
1,883
I need help writing these functions for my assignment.

1) A function int ReadSwitches(void) that reads the slide switch bank and returns the current value, encoded as a binary number.

2) A function void DisplayHex(int value) that shows the hex equivalent of value on the lowestorder seven segment display. The easiest way to do this is with a look-up table (array) of values corresponding to the LEDs you want to light up to show a specific value. For example, if you want to display “1”, you want to turn on LED segments 1&2 in the picture. So your array would contain the following (among other things): lookUpTable[1]=0x06;

3) A main routine that blinks the lowest seven segment display ON and OFF. When ON, it should display the hex equivalent of the four-bit number encoded by the lowest four bits of the slide switch bank and this value should update as you change the switch positions. You can use the same delay loop from Part 1 to time the blinking.

The slide switches are memory mapped to address 0xFF200040 (called SW_BASE in address_map_arm.h).

The lower order four seven segment displays are mapped to address 0xFF200020 (called HEX3_HEX0_BASE in address_map_arm.h).

These are the requirements for the functions. Thank you for helping in advance.
Hopefully this will help-

Title: Standard C [Quick Ref]
Author(s): P.J.Plauger, Jim Brodie
ISBN: 1-55615-158-6

Title: Algorithms in C, 3rd Ed. [Parts 1-4, Fundamentals, Data Structures, Sorting, Searching]
Author: Robert Sedgewick
ISBN: 0-201-31452-5

You should know how to program before taking such courses... IMHO

#### Lux11

Joined Mar 6, 2021
6
How would I read the slide switch bank and return the current value in decimal?

#### Papabravo

Joined Feb 24, 2006
17,009
Converting a binary number to decimal for printing and display is fairly easy to describe. You need two built in functions:
1. Integer division, that takes two numbers expressed as integers, in any number base, and returns the quotient as an integer, discarding the remainder
2. A remainder function that takes two numbers expressed as integers, in any number base, and returns the remainder as an integer, discarding the quotient.
If I tell you that is has been 21,000 seconds since I last had a cigarette. How much time would that be?
We know there are 3600 seconds in 1 hour so we divide 21,000 by 3600 and get a quotient of 5 hours and a remainder of 3000.
3000 seconds is less than 1 hour so we divide by 60 to get a quotient of 50 with a remainder of 0 which tells us we are done. The answer is 5 hours and 50 minutes.
(BTW I haven't smoked a cigarette in over 20 years -- it was just an example)
Converting a number to it's decimal representation involves successive division operations. Each time you get a quotient, you print that digit and then you divide the remainder by the next smaller power of 10. You keep going until the remainder is zero. Since you know which power of 10 you started the division process with you know if there might be leading or trailing zeros and you have to decide how you want to handle those. The usual decision is to suppress leading zeros and print trailing zeros.

N.B. When I say "function" that also includes operators known and understood by the language compiler.

Last edited:

#### Lux11

Joined Mar 6, 2021
6
What I would like to do is use the lowest order four slide switches to control the hex character displayed on the seven segment display.
The slide switches are memory mapped to address 0xFF200040 (called SW_BASE in address_map_arm.h).
The lower order four seven segment displays are mapped to address 0xFF200020 (called HEX3_HEX0_BASE in address_map_arm.h).
The wiring of port I/O bits to segments in the seven segment display is as in the following diagram:

1)A function int ReadSwitches(void) that reads the slide switch bank and returns the current value, encoded as a binary number.
2) A function void DisplayHex(int value) that shows the hex equivalent of value on the lowestorder seven segment display. The easiest way to do this is with a look-up table (array) of values corresponding to the LEDs you want to light up to show a specific value. For example, if you want to display “1”, you want to turn on LED segments 1&2 in the picture. So your array would contain the following (among other things): lookUpTable[1]=0x06;
3) A main routine that blinks the lowest seven segment display ON and OFF. When ON, it should display the hex equivalent of the four-bit number encoded by the lowest four bits of the slide switch bank and this value should update as you change the switch positions. You can use the same delay loop from Part 1 to time the blinking.

#### Lux11

Joined Mar 6, 2021
6
Converting a binary number to decimal for printing and display is fairly easy to describe. You need two built in functions:
1. Integer division, that takes two numbers expressed as integers, in any number base, and returns the quotient as an integer, discarding the remainder
2. A remainder function that takes two numbers expressed as integers, in any number base, and returns the remainder as an integer, discarding the quotient.
If I tell you that is has been 21,000 seconds since I last had a cigarette. How much time would that be?
We know there are 3600 seconds in 1 hour so we divide 21,000 by 3600 and get a quotient of 5 hours and a remainder of 3000.
3000 seconds is less than 1 hour so we divide by 60 to get a quotient of 50 with a remainder of 0 which tells us we are done. The answer is 5 hours and 50 minutes.
(BTW I haven't smoked a cigarette in over 20 years -- it was just an example)
Converting a number to it's decimal representation involves successive division operations. Each time you get a quotient, you print that digit and then you divide the remainder by the next smaller power of 10. You keep going until the remainder is zero. Since you know which power of 10 you started the division process with you know if there might be leading or trailing zeros and you have to decide how you want to handle those. the usual decision is to suppress leading zeros and print trailing zeros.

N.B. When I say "function" that also includes operators known and understood by the language compiler.
Thank you so much.

#### Papabravo

Joined Feb 24, 2006
17,009
When they say that a device is "memory mapped", that means it occupies a particular location in the processors "Large Linear Address Space". Not all of the space has memory. Some addresses contain "Device Registers" instead of memory. The good news is that you can access in "exactly, and precisely" the same way you would access memory. In order to do that you need to create a "pointer" to the fixed memory addresses where the "slide switch" is located. The only difference between actual memory and "Device Registers" is that with memory you should always be able to read back the last thing you wrote to a location. This is not true with "Device Registers". An optimizing compiler needs to know this so it won't try to optimize away a necessary operation. "Device Registers" can also be "Write Only" or "Read Only". Performing a forbidden operation can cause a "fault" on some systems.

The following statement should be decoded and understood with a bit of effort on your part:

C:
char *p = (char *)0xff73000;

#### Lux11

Joined Mar 6, 2021
6
When they say that a device is "memory mapped", that means it occupies a particular location in the processors "Large Linear Address Space". Not all of the space has memory. Some addresses contain "Device Registers" instead of memory. The good news is that you can access in "exactly, and precisely" the same way you would access memory. In order to do that you need to create a "pointer" to the fixed memory addresses where the "slide switch" is located. The only difference between actual memory and "Device Registers" is that with memory you should always be able to read back the last thing you wrote to a location. This is not true with "Device Registers". An optimizing compiler needs to know this so it won't try to optimize away a necessary operation. "Device Registers" can also be "Write Only" or "Read Only". Performing a forbidden operation can cause a "fault" on some systems.

The following statement should be decoded and understood with a bit of effort on your part:

C:
char *p = (char *)0xff73000;
So I have to use pointers in order to access the address for the slide switches. Okay thank you that helps a lot!

#### Papabravo

Joined Feb 24, 2006
17,009
So I have to use pointers in order to access the address for the slide switches. Okay thank you that helps a lot!
I think so, unless you have access to some other method, as specified by your instructor. You do realize that my previous post was a generic example, not the actual address you should use.