Académique Documents
Professionnel Documents
Culture Documents
Informe de Laboratorio N6
Semestre 2014-II
CUSCO PER
2.- Materiales:
3.- Presupuesto:
COSTOS DE MATERIALES
#include <18F4550.h>
#use delay(clock=48M)
#fuses NOPROTECT,NOWDT,NOLVP,NOBROWNOUT,XTPLL,PLL1,CPUDIV1
#use rs232(baud=9600, bits=8, parity=N, xmit=pin_c6, rcv=pin_c7)
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
//////////////ASIGNACION DE SALIDAS///////////////
#define IN_1 PIN_B0 //IN_1 IN_2 comandos de motor de direccion
#define IN_2 PIN_B1 //
#define EN_1_2 PIN_B2
#define IN_3 PIN_B3 //IN_3 IN_4 comandos de motor de empuje
#define IN_4 PIN_B4
////////////FUNCIONES/////////////////////
void on_go(void) ///ADELANTE
{
output_high(EN_1_2);
output_high(IN_1);
output_high(IN_2);
output_low(IN_3);
output_high(IN_4);
}
void on_back(void) //ATRAS
{
output_high(EN_1_2);
output_high(IN_1);
output_high(IN_2);
output_high(IN_3);
output_low(IN_4);
}
void on_i(void) //izquierda
{
output_high(EN_1_2);
output_high(IN_1);
output_low(IN_2);
output_low(IN_3);
output_high(IN_4);
}
void on_d(void) //derecha
{
output_high(EN_1_2);
output_low(IN_1);
output_high(IN_2);
output_low(IN_3);
output_high(IN_4);
}
void off_all (void)//parado
{
output_high(EN_1_2);
output_high(IN_1);
output_high(IN_2);
output_high(IN_3);
output_high(IN_4);
}
char valor1;
char dato;
int8 q;
#INT_RDA
void rda_isr(void)
{
valor1=GETC(); //comando para capturar el dato de la PC
dato=valor1; //lo vamos a guardar el dato
delay_us(10); //pausa para no saturar el micro
}
void main()
{ set_tris_b(0b00000000);
set_tris_c(0b10000010);
set_tris_d(0b00000000);
output_b(0x00);
output_d(0x00);
q=4;
enable_interrupts(int_rda);
enable_interrupts(global);
while(true)
{
rda_isr();
if (dato=='W')
{
q=0;
}
if (dato=='D')
{
q=1;
}
if (dato=='A')
{
q=2;
}
if (dato=='S')
{
q=3;
}
if ((dato!='W')&&(dato!='D')&&(dato!='A')&&(dato!='S'))
{
q=4;
}
if (q==0)
{
output_d(0b00000001);
on_go();
}
if (q==1)
{
output_d(0b00000010);
on_d();
}
if (q==2)
{
output_d(0b00000100);
on_i();
}
if (q==3)
{
output_d(0b00001000);
on_back();
}
if (q==4)
{
output_d(0b00001111);
off_all();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PuertoSerial
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//buscando los puertos conectados a la PC
Control.CheckForIllegalCrossThreadCalls = false;
//listamos en el combox todos los puertos exitentes que se conectraon
foreach (string s in SerialPort.GetPortNames())
{
cmbListaPuertos.Items.Add(s);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
//enviamos al puerto lo que escribimos en el textbox
puertoSerial.Write(txtDatosEnviar.Text.ToString());
}
//este procedimiento es para no crear comflictos con otros puertos
//modulo para verificar si el puerto es valido y ademas lo deshalitara para no crear
conflictos
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
puertoSerial.PortName = cmbListaPuertos.Text;
try
{
puertoSerial.Open();
}
catch
{
MessageBox.Show("Puerto no vlido");
return;
}
cmbListaPuertos.Enabled = false;
}
//evento para recibir los datos que nos envia el micro mediante el puerto
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs
e)
{
string dato_recibido = puertoSerial.ReadExisting();
MENSAJE_USB.Items.Clear();
MENSAJE_USB.Items.Add(dato_recibido);
}
private void button2_Click(object sender, EventArgs e)
{
//enviamos al puerto el valor 1 del teclado
puertoSerial.Write("1");
}
7.- Conclusin: