Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Subject: Microsystems

Students: Mellado Morales Ángel Alejandro Saucillo Castillo Arturo

Practice Name Input and Outputs

Practice Number 1 Length (Hours) 4

OBJECTIVE (Learning result)

Practice with the different configurations between input and output pin/ports. Have a Quick answer with the microcontroller and
remember the choice of the user.

Learn how the different types of frequency can change the answer of the microcontroller.

THEORETICAL FRAMEWORK

There are 3 basic configurations: standard_io, fast_io and fixed_io. The main difference is between the switching speed, pulse
accuracy and the mix of inputs and outputs in the same port.

Now, we need to remember the pins of the PIC18F4550.

To program it, we need to connect the MCLR, VDD,VSS, PGD and PGC to our programmer and load the *.hex file.
The push buttons have two main configurations that change the logical order, pull up and pull down.

The difference is that a pull up configuration set a one logic into the microcontroller and when the button is pushed sets a cero
logic. The Pull down sets a cero logic and when the button is pushed sets a one logic.

A LED (Light Emitter Diode) is a light source that has a polarity defined and need a resistance to control the current flow.

MATERIALS AND EQUIPEMENT

- 1 computer with “PIC C COMPILER”

- 1 Programmer

- 1 PIC18F4550

- 1 Crystal

- 2 capacitors 22pF

- 4 PUSH BUTTONS

- 8 LED’s

- 12 resistances 1k Ohm
METHODOLOGY

Before start making the code to make the sequences, we tried to understand the difference between the different port configurations,
and we noticed that the fast_io help us to make this code because we doesn’t need an accuracy with the waves forms of the
microcontroller, according to the objective, we need a quick answer of the microcontroller so we decided to use a fast_io
configuration.

The next point is for define the sequences that the LED bar is going to reproduce and define if the push buttons are connected with
a pull-up or a pull-down configuration, in this case, we worked with a pull-up configuration.

To make the code, is necessary to know C language and use the “PIC C COMPILER”.

The code idea is to check a button per clock pulse, and if the button is one of the selection buttons, take a second lecture to be sure
of the choose. Check a pin per time, is the slowest method, you can read the full port and use a mask to pull apart the data, but it
needs more code lines.

When you had chosen the sequence, you have to push the start button to see the sequence in the LED bar or push the stop/pause
button to make a new selection. Now, when the sequence is running you can press one time the pause button to freeze de sequence
and press play to defreeze or hold the pause button to stop the sequence after 5 seconds of hold pressed the button.

We use functions to make easier to check the statues of the buttons and to organize the code.

RESULTS

ANNEX CODE
Conclusions

- Saucillo Castillo Arturo: In one microcontroller there are several configurating for the use the ports, one tool is the
instruction "set_tris_port" this instruction allows you to configure the ports as output or input, in this practice, we could
observe by leds and sequence shows in the leds the use of tools for port configuration. The good use of these instructions
we allow have a good program and the best results in the practice.

- Mellado Morales Ángel Alejandro: When we are working with microcontrollers is important to have a quick answer and
get all the information. Learn about the different configurations that the ports can have help us to understand why
sometimes the microcontroller doesn’t works correctly. This practice is the most important because digital ports are based
with Boolean logic, it means that it can be a logic cero or a logic one, in this case ideal 0V or 5V. Another important thing
is that we remember the basic use of the microcontroller, the minimum circuit, the uses of fuses and how to program it
with C language
CODE:

#include <18F4550.h> RESET


#use delay(internal=8M) #ENDASM
#fuses NOPROTECT, NOWDT, NOFCMEN, PLL1, }
CPUDIV1, USBDIV, NOMCLR
#use fast_io(A) }
#use fast_io(B) }
#use fast_io(C)
#use fast_io(D) void pause()
{
int const ban=0;
sec1[8]={0b00000001,0b00000011,0b00000111,0b00 contador=0;
001111,0b00011111,0b00111111,0b01111111,0b1111 while(ban==0)
1111}; {
int const start=input(pin_d2);
sec2[8]={0b11000000,0b01100000,0b00110000,0b00 if(start==0)
011000,0b00001100,0b00000110,0b00000011,0b0000 {
0001}; ban=1;
int const
sec3[8]={0b10000000,0b11000000,0b10100000,0b10 }
010000,0b10001000,0b10000100,0b10000010,0b1000
0001}; btpause=input(pin_d3);
int const
sec4[8]={0b00011000,0b00111100,0b01111110,0b11 if(btpause==1)
111111,0b01111110,0b00111100,0b00011000,0b0000 {
0000}; contador=0;
}
int8 botones;
int if(btpause==0)
sec,start,cont,ban,btpause,contador,tiempo,i; {
int8 dat; contador++;
delay_ms(240);
void leds(); if(contador>=20)
void pause(); {
void seleccionar(); output_b(0b0);
sec=0;
void main() #ASM
{ RESET
set_tris_b(0b00000000); #ENDASM
set_tris_a(0b11111111);
set_tris_d(0b11111111); }
set_tris_c(0b11111111); }
sec=3; }
}
i=0;
void seleccionar()
delay_ms(100); {
//output_b(0b11);
for(;;) delay_ms(100);
{ botones=input_c();
output_b(1); dat=(botones)&0x3;

if(sec==3) switch(dat)
{ {
output_b(2); case 0b11:
seleccionar(); {
delay_ms(200); sec=3;
seleccionar(); break;
} }
case 0b10:
start=input(pin_d2); {
if(start==0) //BOTON DE START sec=2;
{ break;
leds(); }
} case 0b00:
{
btpause=input(pin_d3); sec=1;
if(btpause==0) break;
{ }
#ASM case 0b01:
{ {
sec=4; cont=0;
break; }
} else
default: {
{ cont++;
sec=3; }
break; btpause=input(pin_d3);
} if(btpause==0)
} {
} pause();
}
void leds()
{ }
switch(sec) sec=0;
{ break;
case 1: }
{ case 4:
cont=0; {
ban=1; cont=0;
while(ban) for(;;)
{ {
output_b(sec1[cont]); output_b(sec4[cont]);
delay_ms(100); delay_ms(100);
if(cont==7) if(cont==7)
{ {
cont=0; cont=0;
} }
else else
{ {
cont++; cont++;
} }
btpause=input(pin_d3); btpause=input(pin_d3);
if(btpause==0) if(btpause==0)
{ {
pause(); pause();
} }
} }
sec=0; sec=0;
break; break;
} }
case 2: }
{ }
cont=0;
for(;;)
{
output_b(sec2[cont]);
delay_ms(100);
if(cont==7)
{
cont=0;
}
else
{
cont++;
}
btpause=input(pin_d3);
if(btpause==0)
{
pause();
}

}
sec=0;
break;
}
case 3:
{
cont=0;
for(;;)
{
output_b(sec3[cont]);
delay_ms(100);
if(cont==7)

You might also like