0% found this document useful (0 votes)
85 views

Activity No.1 Setting Up and Programming Controllers

This activity aims to demonstrate programming a microprocessor system to control LEDs. Students are asked to write programs to perform tasks like turning on odd-numbered LEDs, blinking LEDs one by one, and alternately blinking odd and even LEDs. They provide the code, flowcharts, and test results. The code is written in C++ and uploaded to control an Arduino board connected to 8 LEDs. Test results show the LED pin voltages are 4.85V when high and 0V when low, with a current of 2.97mA when high and 0A when low. Bugs in the programs are also noted.

Uploaded by

RUEL ALEJANDRO
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Activity No.1 Setting Up and Programming Controllers

This activity aims to demonstrate programming a microprocessor system to control LEDs. Students are asked to write programs to perform tasks like turning on odd-numbered LEDs, blinking LEDs one by one, and alternately blinking odd and even LEDs. They provide the code, flowcharts, and test results. The code is written in C++ and uploaded to control an Arduino board connected to 8 LEDs. Test results show the LED pin voltages are 4.85V when high and 0V when low, with a current of 2.97mA when high and 0A when low. Bugs in the programs are also noted.

Uploaded by

RUEL ALEJANDRO
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Activity No.

1
Setting up and Programming Controllers
Course Code: ECE 018 Program:
Course Title: Microprocessor and Microcontroller Systems and Design Date Performed: March 4, 2021
Section: ECE32S1 Date Submitted: March 3, 2021
Name/s: Arroyo, Rainier , Instructor:
Camacho, Albert
Faminiano, Emiel Renz
Viduya, Tan hay
1. Objective:
This activity aims to demonstrate the concept of programming a microprocessor-based system. Another
aim of this activity is to introduce procedures in testing and identification of errors in a program.
2. Intended Learning Outcomes (ILOs):
After completion of this activity the students should be able to:
2.1 Write a functional program for a microprocessor-based system
2.2 Compile and Upload a processor source code
2.3 Identify errors and Debug issues in a source code for LED control.

3. Discussion:
In essence, the word programming means giving a mechanism the directions to accomplish a task. If you
are like most people, you’ve already programmed several mechanisms, such as your digital video recorder
(DVR), cell phone, or coffee maker. Like these devices, a computer also is a mechanism that can be
programmed. The directions (typically called instructions) given to a computer are called computer
programs or, more simply, programs.

Programmers use a variety of special languages, called programming languages, to communicate with the
computer. Some popular programming languages are C++, Visual Basic, C#, Java, and Python. In this
book, you will use the C++ programming language.

Designing and implementing processor programs is different and more challenging than writing typical
workstation or PC programs. The code must not only provide rich functionality, it must also often run at a
required rate to meet system deadlines, fit into the allowed amount of memory, and meet power
consumption requirements.

Designing code that simultaneously meets multiple design constraints is a considerable challenge, but
luckily there are techniques and tools that can be used to help through the design process. Making sure
that the program works is also a challenge, but once again methods and tools such as flowcharts and
pseudo codes simplify the algorithm writing procedures.

In mathematics, computer science, and related subjects, an algorithm is a finite sequence of steps
expressed for solving a problem. An algorithmcan be defined as “a process that performs some
sequence of operations in order to solve a given problem”. Algorithms are used for calculation, data
processing, and many other fields.

In computing, algorithms are essential because theyserve as the systematic procedures that computers
require. A good algorithm is like using the right tool in the workshop. It does the job with the right amount
of effort.
4. Resources:
The activity will require the following software, tools and equipment:
4.1 Desktop Computer
4.2 Dev C/C++/Processing
4.3 Sketch/Flowcode
4.4 Multisim or_
4.5 Other tools:

5. Procedures:
1. Configure and connect the circuit to the microcomputer device. Each of the individual LED’s are
connected to a unique output pin as seen in the following block diagram. Draw the circuit diagram on
the Results section.

2. Test the function of each digital pin by turning ON all the LED’s in the system. Write the program in the
Results section.
3. Write a flowchart and program that controls the activity of LED bulbs. The program should be able to
perform the following, separately:
a. Turn on only the bits at the ODD position.

b. Blink one bulb at a time, and then repeat when finished.

c. Alternately blink odd and even bulbs with a 100 millisecond interval on a continuous loop.
4. Write the source code in the space provided in the following section and include comments in the
source code.
5. Take note of possible bugs in the program. Cite your detections in the observations.
6. Using a Digital Multi-meter, test the operating voltages and currents of the microcontrollers’ pins. Write
the findings in the table provided in the following section.

6. Results
Circuit Diagram

Figure 1. Circuit Configuration

Test Program(All LED’s)

void setup()
{
for (int x = 1; x < 8; x++) pinMode(x,
OUTPUT);
}
void loop()
{
for (int y = 1; y < 8; y++)
{
digitalWrite(y, HIGH);
}

}
Program 3A
int ledpin=8;
void setup() {
for (int i=1;i<=ledpin;i++)
{
if (i%2==0)
{
pinMode(i, OUTPUT);
}
}
}
void loop()
{
for (int i=1;i<=ledpin;i++)
{
if (i%2==0)
{
digitalWrite(i, HIGH);
}
}
}

https://www.tinkercad.com/things/3VSk10pwXUw-swanky-curcan-
kasi/editel?sharecode=fUfpBxG7mmtRwNkOgXad73FnW3gqq-AktvQmigzHgNY

Program 3B

int ledpin=8;

void setup()
{
for (int i=1;i<=ledpin;i++)
{ pinMode(i, OUTPUT);
}
}
void loop()
{
for (int i=1;i<=ledpin;i++)
{ digitalWrite(i, HIGH);
delay(500); digitalWrite(i, LOW);
}
}
Flowchart 3A
Program 3B
int ledpin=8;

void setup()
{
for (int i=1;i<=ledpin;i++)
{ pinMode(i, OUTPUT);
}
}
void loop()
{
for (int i=1;i<=ledpin;i++)
{ digitalWrite(i, HIGH);
delay(500); digitalWrite(i, LOW);
}
}

https://www.tinkercad.com/things/iOpi9Yr78uD-spectacular-
waasa/editel?sharecode=2L2ZzAPbgaE6yipYrrpupbS0lbwPNSj5p07Wl5l2bqs
Flowchart 3B
Program 3C
int ledpin = 8; void setup()
{
for (int i=1;i<=ledpin;i++) { pinMode(i, OUTPUT);
}
}
void loop()
{
for (int i=1;i<=ledpin;i++) { if(i%2==0){ digitalWrite(i,LOW);
}
else { digitalWrite(i,HIGH);
}}
delay(100); for (int i=1;i<=ledpin;i++) { if(i%2==0){ digitalWrite(i,HIGH);
}
else { digitalWrite(i,LOW);
}
}
delay(100);
}

https://www.tinkercad.com/things/fgGWnHSoGT4-stunning-hango/editel?sharecode=j-
cnVOk7XkyHJMFJDDBgBCbnLeXOSwtlFvs9RhJ5qCQ
Flowchart 3C
Test Results
Pin Number Voltage when HIGH Voltage when LOW Remarks

1 4.85 V 0V The voltage of the LED


connected to pin 1 is 0V
when it is off and 4.85V
when it is on. The
current, on the other
hand, is 2.97mA when it’s
HIGH and 0A when it’s
LOW.

2 4.85 V 0V
The voltage of the LED
connected to pin 2 is 0V
when it is off and 4.85V
when it is on. The current,
on the other hand, is
2.97mA when it’s HIGH
and 0A when it’s LOW.

3 4.85 V 0V

The voltage of the LED


connected to pin 3 is 0V
when it is off and 4.85V
when it is on. The current,
on the other hand, is
2.97mA when it’s HIGH
and 0A when it’s LOW.

4 4.85 V 0V The voltage of the LED


connected to pin 4 is 0V
when it is off and 4.85V
when it is on. The current,
on the other hand, is
2.97mA when it’s HIGH
and 0A when it’s LOW.

5 4.85 V 0V
The voltage of the LED
connected to pin 5 is 0V
when it is off and 4.85V
5 4.85 V 0V
The voltage of the LED
connected to pin 5 is 0V
when it is off and 4.85V
when it is on. The
current, on the other
hand, is 2.97mA
when it’s HIGH and 0A
when it’s LOW.

6 4.85 V 0V
The voltage of the LED
connected to pin 6 is 0V
when it is off and 4.85V
when it is on. The
current, on the other
hand, is 2.97mA
when it’s HIGH and 0A
when it’s LOW.

7 4.85 V 0V
The voltage of the LED
connected to pin 7 is 0V
when it is off and 4.85V
when it is on. The
current, on the other
hand, is 2.97mA
when it’s HIGH and 0A
when it’s LOW.

8 4.85 V 0V The voltage of the LED


connected to pin 8 is 0V
when it is off and 4.85V
when it is on. The
current, on the other
hand, is 2.97mA
when it’s HIGH and 0A
when it’s LOW.
Errors Detected
Error Solution

expected ‘}’ at end of input

Due to the number of times brackets were used in the


program, there was this one time where we got this error
unintentionally. What we did was that we reviewed the code
and easily found where a missed a closing bracket.
Tinkercad helps you find it easily by highlighting the line
where the error is found.

expected ‘;’ before ‘}’ token


We also forgot to put a semicolon after the delay function.
We fixed it quickly because Tinkercad highlighted the line
where we forgot to put a semicolon to complete or separate
statements/functions.

7. Observations
In this laboratory activity, We used a microcontroller board Arduino Uno, the first step is to set up the coding
software settings and power the Arduino board using the USB cord connected to the USB port of the computer. We don’t
familiar with Arduino coding that’s why upon doing the activity, we encounter the problem of blinking two led's one at
a time. The two leds have a delay in interchange. the first step is to set up the coding software settings and power the
Arduino board using the USB cord connected to the USB port of the computer.

8. Conclusions
We learned how to use Tinkercad in creating and simulating Arduino uno projects. We enjoyed creating circuit
diagrams and we hope to be able to use our learnings in this activity in the preceding laboratories. Through
this activity, we can use the different elements of an Arduino uno utilizing an online 3D called Tinkercad.
Utilizing the Arduino uno, breadboard, resistors, and 7 LEDs in Tinkercad, we can create a circuit where its
capacities are let the LED blink alternately then again with a 100 millisecond span, let the LED flicker each in
turn constantly. We are likewise ready to compose a program for the arduino and distinguish mistakes and
troubleshoot issues in a source code for LED control.
9. Supplementary Activity

Modify code 3B such that it is able to reverse its running light direction when it light ups the last LED in its
sequence, and then it will repeat itself. The running light should run from pin 0 to pin 13 with a delay of half
a second per LED.

Circuit Diagram:

Program:
int ledpin = 13;
void setup()
{
for (int i=0;i<=ledpin;i++) { pinMode(i,
OUTPUT);
}
}
void loop()
{
for (int i=0;i<=ledpin;i++) {
digitalWrite(i, HIGH); delay(500);
digitalWrite(i, LOW);
}
for (int i=ledpin;i>=0;i--) {
digitalWrite(i, HIGH); delay(500);
digitalWrite(i, LOW);
}
}

10. Assessment (Rubric for Laboratory Performance):

You might also like