LAB:INTRODUCTION TO KEIL&C

 

 

 

INTRODUCTION
For this lab you will write a C code subroutine to approximate the square root of an argument using a bisection
method. All the math is done with integers, so the resulting square root will also be an integer. This lab will develop an
appreciation of the steps involved in cross-compiling for, and downloading to, an embedded target board.
HARDWARE
There is no hardware requirement for this lab. We will be simulating a C167 uC in the Keil IDE software.
PROCEDURE
1. Start the Keil µVision 5 Integrated Development Environment (IDE) program.
2. From the top Project drop-down menu, create a new uVision project and save to a new folder (Keil makes a range of
files and sub-folders). Make sure not to have any spaces (underscores are fine) in the project name – this breaks the
linker. Select the legacy device database and the Infineon C167CR-LM target. Click Ok, and then Yes to adding a copy
of ‘START167.A66’.
3. Open the options for target from the top menu bar.
4. Set external memory locations per the image below, then hit Ok.
5. Add new item to source group 1. Select .c file. Name the file main.
6. Complete the ‘main’ function and write a static C function that takes the passed argument and returns the square root.
Some considerations: The ‘sqrt’ function returns a value from 0 to 65535, so you should select an appropriate return
type, as well as argument type. The result variable is declared ‘volatile’ to ensure you can inspect its value in the
debugger’s locals window
7. When you are confident your code is correct, compile your code using the Build icon (keyboard shortcut F7)
8. The debugger can be started from the Debug menu (keyboard shortcut ctrl-F5)
9. Test (and if necessary, debug) your code. You can single step through your code from the Debug menu (keyboard
shortcut F11). You can Step Over (keyboard shortcut F10) the call to your function sqrt( ) to see the retuned value
without stepping into the function. You can run the function without stepping (keyboard shortcut F5).
10. Get completion of this lab for your group after showing a tutor your compiled function returning the correct results
for the input arguments below:
sqrt_x = sqrt(0);
sqrt_x = sqrt(1);
sqrt_x = sqrt(25);
sqrt_x = sqrt(133);
sqrt_x = sqrt(4294967295); //extension
KEIL INTEGER TYPES (C167)
type range
char 0 -> 255
signed char -128 -> 127
short -32768 -> 32767
unsigned short 0 -> 65535
int -32768 -> 32767
unsigned int 0 -> 65535
long -2147483648 -> 2147483647
unsigned long 0 -> 4294967295
long long -9.2 x 1018
-> 9.2 x 1018
unsigned long long 0 -> 1.8 x 1019
Note: these are compiler specific. ANSI C rules are:
short <= int <= long
SQUARE ROOT ALGORITHM FLOWCHART
This algorithm calculates the square root of a number, given interval endpoints within which the square root lies. Base
your software on the following flowchart.
INPUT: x, where x is an unsigned long
INITIALISE: endpoint values a, b, such that a < b; the midpoint m, and the previous iterations midpoint.
WHILE LOOP: shown within a blue dashed rectangle.
EXIT CONDITIONS: shown within a green dashed rectangle.
OUTPUT: sqrt_x, where sqrt_x is an unsigned short. This value differs from the true sqrt(x) by less than 1.
Figure 3: Example flowchart of the function sqrt( ).

Sample Solution

came to power in 1979 and represented for many, laissez-faire economics and individual self-determination (Steele, 2018). She believed in power of the market, utilizing it to restore the stagnant British economy and moving away from state provided services. In 1979, cuts resulted in reducing the standard rate of tax from 33% to 30%, the top rate from 83% to 60% and finally cutting public spending by 3% (Bolick, 1995). She reduced the amount of public spending, from 50% to 43%. Thatcher felt high taxes discouraged the incentive to work however, effects of tax cuts increased income inequality through as high earners saw ‘the top 10%- did far better, with their incomes increasing from the equivalent of £472.98 in 1979 to £694.83 in 1990’. The uneven distribution of wealth saw the poorest families receive the least. Reductions in public expenditure affected health, education and social services which created a knock-on effect with substantial loss of public sector jobs resulting in decreased spending on goods and services. Privatisation became Thatcher’s most important and long-lasting legacy. She revealed in her memoirs that it was crucial for ‘reversing the corrosive and corrupting effects of socialism’ Parker. In the 1980-90s, due to fiscal pressures, Thatcher’s conservative views on private ownership and public discontent with the current regime saw the privatisation of public owned entities. For example, the sale of just ‘over 50% of shares in BT and the sale of British Energy in 1996’ (Berrington, 1998). Other privatised industries included electricity, gas, British steel, public bus transportation and other public services. As a result, workforces declined as ‘employment in the electricity and gas industries was cut in half’(Edwards, 2017), problems arose in the regulation of private monopolies to prevent abuse of power, however improved ‘economic growth and improved living standards as privatised businesses cut costs, increased service quality’ (Edwards, 2017). Thatcher can be seen as the key instigator of the sweeping shift from traditional to ‘New Public Management’ initiated by public service reforms. NPM involved the adoption of private sector management ideas to improve structures and processes in the public sector. Thatcher who led the 1980s ‘New Right’ administrations, that put a ‘shrinking government and reduced taxation on the agenda’ (Ferlie, 2017). Thatcher also wanted to remove ‘inefficiency in the state bureaucracy and the deprivilege of the civil service’ as she concluded that the public sector was ‘wasteful, overbureaucratic and underperforming’ (Ferlie et al., 1996). Thatcher wanted to identify areas of waste and inefficiency in the government and ‘improve service quality and customer-orientated service’ (Pollitt, 1996) whilst reducin

This question has been answered.

Get Answer
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, Welcome to Compliant Papers.