User Tools

Site Tools


haas:fall2019:c4eng:projects:epf1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
haas:fall2019:c4eng:projects:epf1 [2019/09/30 12:48] – created wedgehaas:fall2019:c4eng:projects:epf1 [2019/09/30 19:08] (current) wedge
Line 11: Line 11:
 =====Reading===== =====Reading=====
 In "The C Book", please read through Chapter 5. In "The C Book", please read through Chapter 5.
 +
 +=====Diagram=====
 +
 +To refresh your memory, here is a diagram of the circuit you can build to drive the LEDbar:
 +
 +{{:haas:fall2019:c4eng:projects:ledbar.png?400|}}
 +
 +Be sure to use 220 Ohm resistors for this.
  
 =====Program===== =====Program=====
Line 73: Line 81:
 lab46:~/src/c4eng/epf1$  lab46:~/src/c4eng/epf1$ 
 </cli> </cli>
 +
 +=====Obtaining binary values=====
 +You might wonder how, when you are limited to non-binary input, how you can obtain the binary value so that you can work with it.
 +
 +There are a couple ways to go about this:
 +
 +====Method one: convert from decimal to binary====
 +Using the division method, you can convert a decimal value to binary, continually dividing the value (or its quotient) by the base, until the quotient is 0, then we use the remainders to give us the binary value:
 +
 +  * value / base
 +  * value = 15
 +  * value / 2
 +    * ie: 15 / 2
 +      * quotient: 7
 +      * remainder: 1
 +  * value = quotient
 +  * value / 2
 +    * ie: 7 / 2
 +      * quotient: 3
 +      * remainder: 1
 +  * value = quotient
 +  * value / 2
 +    * ie: 3 / 2
 +      * quotient: 1
 +      * remainder: 1
 +  * value = quotient
 +  * value / 2
 +    * ie: 1 / 2
 +      * quotient: 0
 +      * remainder: 1
 +
 +The binary for 15 (decimal) is 1111 (binary)
 +
 +Or:
 +  * value = 11
 +  * value / 2
 +    * quotient: 5
 +    * remainder: 1
 +  * value = 5
 +  * value / 2
 +    * quotient: 2
 +    * remainder: 1
 +  * value = 2
 +  * value / 2
 +    * quotient: 1
 +    * remainder: 0
 +  * value = 1
 +  * value / 2
 +    * quotient: 0
 +    * remainder: 1
 +
 +The binary for 11 (decimal) is 1011 (binary).
 +
 +NOTE that the order in which we get the remainders produces the number from right to left.
 +
 +====Method 2: bitwise AND the place values====
 +If one understands the weight values corresponding with the places of each bit in a binary number, we can simply do a bitwise AND and see if the result is greater than 0 or not:
 +
 +^  2 to the 7  ^  2 to the 6  ^  2 to the 5  ^  2 to the 4  ^  2 to the 3  ^  2 to the 2  ^  2 to the 1  ^  2 to the 0  ^
 +|  128  |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
 +
 +So, if we wanted to see if the 2 to the 7th bit is active, we can simply:
 +
 +<code c>
 +    value  = number & 128;
 +</code>
 +
 +We can then check of value is greater than 0; if it is, we've got a 1 in that position, if it isn't, we have a 0.
 +
 +We can then repeat the operation for 64, 32, 16, etc. down to 1, to get each bit of our number.
 +
 +NOTE that I have only taken us out to 8-bits. You may need to extend this to incorporate all the allowed values for this project.
  
 =====Submission===== =====Submission=====
Line 97: Line 177:
  
 You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches. You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
- 
-What I'll be looking for: 
- 
-<code> 
-78:epf1:final tally of results (78/78) 
-*:epf1:proper error checking and status reporting performed [13/13] 
-*:epf1:correct variable types and name lengths used [13/13] 
-*:epf1:proper output formatting per specifications [13/13] 
-*:epf1:runtime tests of submitted program succeed [13/13] 
-*:epf1:no negative compiler messages for program [13/13] 
-*:epf1:code is pushed to lab46 repository [13/13] 
-</code> 
- 
-Additionally: 
-  * Solutions not abiding by spirit of project will be subject to a 25% overall deduction 
-  * Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction 
-  * Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction 
-  * Solutions not organized and easy to read are subject to a 25% overall deduction 
haas/fall2019/c4eng/projects/epf1.1569847736.txt.gz · Last modified: 2019/09/30 12:48 by wedge