You are on page 1of 13

Activity No.

1
Setting up and Programming Controllers
Course Code: ECE 018 Program:
Course Title: Microprocessor and Microcontroller Date Performed:
Systems and
Section: Design
ECE32S1 MarchSubmitted:
Date 4, 2021
Name/s: Arroyo, Rainier , March 3, 2021
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
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.


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
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);
}
}
}

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);
}
}
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);
}
Flowchart 3C
Test Results
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.
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
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
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
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.
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