CLanguageProgramming ENEX20001
- Subject Code :
ENEX-20001
ENEX200012025T1
Assignment2CLanguageProgramming
Duedate: |
Week5,Friday(11thApril2025)23:45 20%oftheunitfinalmark 30% OnlineMoodle(Seethesubmissioninstructions below) |
|
Weighting: Minimum: |
||
Submission |
||
1 |
ImportantNote:
It is important to note that this assignment is intended to be completed individually, and sharing your code with others is strictly prohibited. If you use any external resources including tutorial sample codes, please ensure that you provide clear references in the comments to avoid plagiarism. CQ University places a high value on academic honesty and integrity, and any breach of these standards may result in severe penalties. If you require additional guidance on academic integrity, please refer to the information provided in the following link.
https://cqunilife.com/2020/01/07/do-you-understand-academic-integrity/
Youcanonlyusecprogramminglibrariesandfunctionsintroducedinweek1-4lecturesandyoucannot use any other library or functions to complete the assignment. If you are not sure then clarify it withthe unit coordinator.
YoucannotuseanyoftheArduinoFunctions(https://www.arduino.cc/reference/en/) in all the assessments in this unit. Zero marks will be given if you use any Arduino functions or codes.
(100% of marks is equal to 25% of the unit total)
Tosubmittheassignment:
- Create a Single PDF file with your answers for each question and submit it to the Moodle site. Follow the assessment criteria and instructions when answering each question.
- Create a PDF file with your code for each question and upload it to the MoodleName the PDF files Q1-code.pdf, Q2-code.pdf. Copy the AVR C program files from the Tinker cad to a
WordfileandcreatePDFfiles.Anysubmittedprogramwithcompilationerrorswillreceivevery low marks.
- Download the C program files from the Tincker cad simulation and make a zipName the zip file as codes. Zip and upload it to Moodle.
- Upload a separate video file for each question that demonstrates your working program to Moodle.Themaximum filesize is 100MB. Name thevideo files Q1-video,Q2-video, andQ3- video.Thedemonstrationshouldincludeverbalexplanationsandshowyourface.Ifnotyou will receive zero marks.
- The simulation and required AVR C programming should be done in the class Tincker cad simulation You will get a separate workspace for assignment 1 and it shouldnt be modified after the final submission. Any modifications after the final submission will result in zero marks.
Q1.
- Add103(decimal) to the last two digits of your student number and convert it to a binary number of 8 bits. You have to manually calculate the binary conversion and show the steps in your report. You must get this conversion right and otherwise answers to all the following sections will be wrong. Verify your conversion using a calculator or an online conversion table. (5 marks)
- Write down all the steps in your report to convert the binary number created earlier to 01010101 only usingbit setandclear operations only( SHIFT, AND, OR and NOT operations).In each step, only one bit should be changed. You needto show in each step, how bits are changed in each binary operation.(10 marks)
- Write a C code in your report to do the conversion in questions b.) starting from the last two digits of your student number ( store it as a variable). You can only store the last two digits of your student number in a variable and all other operations need to be done using standard C code. Add comments to explain your code.
(5marks)
- Wire the Arduino Uno board in the Tinker Cad class assignment space to display 8-bit binary numbers using 8 LEDs. Use the pins, as assigned according to the following table based on the binary number created in question (Q1.a.). All LEDs need to be labelled according to the following table. Include a screenshot of the Tinker cad breadboard and the circuit diagram in your report. See the following example, for binary number01100101,and youmust include a similar table in your report foryour binary number created in Q1.a and choose the microcontroller pins accordingly. (10marks)
*The following table is an example only, find the pins to which each LED need to beconnected based on your student number.
LEDLabel |
LED7 |
LED6 |
LED5 |
LED4 |
LED3 |
LED2 |
LED1 |
LED0 |
BitNumber |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Thebinarynumberfrom Question 1. A (Thisisanexampleonly) |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
PortPinsEachLEDis connected All zero bits should be assignedtothe corresponding PORTD pins Allonebitsneed tobeassignedto the corresponding PORTB pin for LED0 -LED5, ). If thereare1sin bits6and7then usePC4andPC5. |
PD7 |
PC4 |
PB5 |
PD4 |
PD3 |
PB2 |
PD1 |
PB0 |
- Write a C code in Tincker cad to display the number created in Q1.a and Q1.b alternatively with a 1-second interval inLED0 should display the 0th bit and LED7 should display the 7thbit and each bit should match all other LED labels. Your program should be properly commented on and should work in the simulation.You need to complete the following activities to complete this assessment item. (20marks)
- C codes for Q1. a and Q1.b need to be included in the main program. Optimise the code to use the least number of code lines.
- Add a screenshot of the code to the report and explain the
- A clear video recording from the simulation needs to be uploaded to the Moodle site as evidence of the correct functionality of the code. The video demo should include a clear verbal explanation of the code and your face should be visible in the video. ( use third-party software or Zoom screen recording)
- The Tincker cad simulation files should not be modified after the due date of the assignment. The last edited time should be before the submission date and zero marks will be given if the files were modified after the submission
Q2.
In this question, you will build a simulated robot using the Tinker Cad simulator. The robot will have two gear motors connected to two wheels and 2 tactile sensors (SL, and SR) simulated as pushbuttons. You are only required to simulate the electronic circuit with motors and push buttons and write a C program to control the Arduino Uno board. You need to have L293D motor controller circuit to control the two motors.
The SL and SR sensors will be used to detect any obstacles and it is simulated as push buttons presses.Inthe Tinkercadsimulation,use pushbuttonstosimulatethe tactilesensors.Youare required to write an AVR C program to control the robot and show its functionality using the simulation by showing the motors are rotating in the correct direction. The robot should behave as follows.
- When there is an obstacle in the right direction but not in the left direction then the robot should move to the left side.
- When there is an obstacle in the left direction but not in the right direction then the robot should move to the right side.
- When there is a larger obstacle at the front which is detected by both sensors then the robot should reverse.
- In all other cases, the robot moves forward
EachstudentshouldchoosethepinsofthemicrocontrollerunoboardtointerfaceL293basedonthe following table.
*The followingtableisanexampleonly,findthepinsto whicheachL293Dcontrolpinsneedto be connected based on your student number.
L293Dpinandthe pushbutton |
ENA |
IN1 |
IN2 |
ENB |
IN3 |
IN4 |
SL |
SR |
BitNumber |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Thebinarynumber fromQuestion1.A (Thisisanexample only) |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
Allzerobitsshouldbe assigned to the correspondingPORTD pins. All one bits need to be assigned to the corresponding PORTB pin for bit 0 -bit 5. If there are1s in bits6 and7thenusePC4and PC5. |
PD7 |
PC4 |
PB5 |
PD4 |
PD3 |
PB2 |
PD1 |
PB0 |
The simulation circuit needs to be built in the given Tinkercad workspace and a video need to be recordedtoshowthesimulation.Thevideofileshouldclearlyshowthefunctionalityoftherobot.The Tiknercad program cannot be modified after the due date of the submission and the program file should be uploaded to the Moodle site.
Themarkswillbeallocatedaccordingtothefollowingmarkingcriteria.
- Include a representation of the program using a flowchart or a block diagram and explain the logic.(Marks 10)
- Write a fully working program producing expected outcomes, which will be assessed based on the video demonstration, codes, Tinker cad simulation and the report submitted to the Moodle site. Screenshots of the circuit diagram and the Tinkercad simulation need to be included in the report. Failure to provide a demonstration video and codes will result in a zero mark.(Marks 30)
- Explanation of the code, including all functions and configuration parameters, with appropriate comments on all code sections. Screenshots from the code should be used when explaining each section, and this should be included in the report.(Marks 10)
Q2-(50marks)