SlideShare a Scribd company logo
C:UsersCARLOSDesktoppractica dspicUART_LEDS.c
#include "p30fxxxx.h" #include "LCD.h" #include "UART.h"
#include "libpic30.h"
//Macros para la configuración de los fusibles
_FOSC(CSW_FSCM_OFF & XT_PLL4); _FWDT(WDT_OFF); _FBORPOR(PBOR_OFF & PWRT_16 & MCLR_EN);
_FGS(CODE_PROT_OFF);
#define BORRAR_HYPERTERMINAL TX_UART1_CHAR('f')
unsigned char rx; void main() {
ADPCFG = 0xFFFF;
__delay_ms(15);
//LCD_CONFIG();
INICIO_UART1(_9600);
//BORRAR_HYPERTERMINAL; //TX_UART1_MENSAJE("Hola alumnos UTPnr",18); //TX_UART1_MENSAJE("ttCuanto va el Peru
Panama?nr",29);
ADPCFG = 0XFFFF;
TRISB = 0xFF00; //Los cuatro pines menos significativos son salida
while(1);
}
void __attribute__((__interrupt__))_U1RXInterrupt(void)
{
rx = U1RXREG;
// if(rx=='s' || rx=='S')
if(rx=='A' ) { PORTBbits.RB0 = 1; __delay_ms(200);PORTBbits.RB0 = 0; __delay_ms(200);}
if(rx=='B' ) { PORTBbits.RB1 = 1; __delay_ms(200);PORTBbits.RB1 = 0; __delay_ms(200); }
// TX_UART1_MENSAJE("Va ganando Peru 2 a 1n",23);
IFS0bits.U1RXIF = 0;
}
// ***********************CONFIGURACION DEL REGISTRO UART***************************
void INICIO_UART1(unsigned char baudios)
{
U1BRG = baudios; //9600 bps, U1BRG es un registro de 16 bits U1MODE = 0; //8 bits de datos, sin paridad(STSEL=0) y 1 bit de
stop.
/*PDSEL<1:0> - Parity and data selection bits 00 – 8-bit data, no parity 01 – 8-bit data, even parity 10 – 8-bit data, odd parity 11 – 9-bit
data, no parity*/
// STSEL – STOP selection bit (STSEL=0 one STOP bit, STSEL=1 two STOP bits)
U1MODEbits.UARTEN = 1; // habilito UART dentro del registro U1MODE
U1STAbits.UTXEN = 1; // habilito la transmision dentro del registro U1STA
IPC2 = IPC2 | 0x0030; // Prioridad nivel 3 para U1RXIP
/* Los registros IECx permite habilitar las respectivas interrupciones del CPU. Una vez puesto a '1' logico el respectivo bit, la
interrupcion queda activa y es posible que un evento la dispare. Estos bits,normalmente se habilitan una sola vez en el programa, a
menos que el programador desee desactivar la interrupcion a raiz de otro evento */
IEC0bits.U1RXIE = 1; // Para habilitar la interrupcion
/* Los registros IFSx contienen las banderas de las diversas interrupciones del DSPIC30F3014. Estas banderas automaticamente se
ponen a '1' logico para indicar que una interrupcion ha ocurrido. Una vez atendida la interrupcion esta bandera debe ser puesta a '0'
logico por firmware, ya que de no hacerlo la rutina de interrupcion sera considerada no atendida por el CPU y esta se volvera a
ejecutar */
IFS0bits.U1RXIF = 0; // Para borrar la bandera o flag de interrupcion por el U1RXREG
}
void TX_UART1_CHAR(unsigned char dato)
{
U1TXREG = dato;
while(U1STAbits.TRMT == 0);
/* TRMT - Transmitir registro de desplazamiento es poco vacío (TRMT = 0 transmiten registro de desplazamiento no está vacío,
transmisión en curso, TRMT = 1 registro de desplazamiento de transmisión está vacía, la transmisión completa) */
}
void TX_UART1_MENSAJE(unsigned char *datos, unsigned char tam)
{
unsigned char i=0;
while(i<tam)
{
TX_UART1_CHAR(datos[i]);
i++;

}
}
C:UsersCARLOSDesktoppractica dspicUART.h
 este archivo incluyan como UART.h
#define _9600 64
#define _19200 32
#define _38400 15
#define _57600 10
void INICIO_UART1(unsigned char baudios);
void TX_UART1_CHAR(unsigned char dato);
void TX_UART1_MENSAJE(unsigned char *datos,unsigned char tam);
void INICIO_UART2(unsigned char baudios);
void TX_UART2_CHAR(unsigned char dato);
void TX_UART2_MENSAJE(unsigned char *datos,unsigned char tam);
EN LA FIGURA SE MUESTRA LA MANERA DE AJUNTAR ESTOS ARCHIVOS “xxx.h” y “xxx.c”
INTERFAZ GUI MATLAB PARA PROBAR LA COMUNICACIÓN SERIAL DSPIC30F3014

function varargout = LEDS(varargin)
% LEDS M-file for LEDS.fig
%
LEDS, by itself, creates a new LEDS or raises the existing
%
singleton*.
%
%
H = LEDS returns the handle to a new LEDS or the handle to
%
the existing singleton*.
%
%
LEDS('CALLBACK',hObject,eventData,handles,...) calls the local
%
function named CALLBACK in LEDS.M with the given input arguments.
%
%
LEDS('Property','Value',...) creates a new LEDS or raises the
%
existing singleton*. Starting from the left, property value pairs are
%
applied to the GUI before LEDS_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property application
%
stop. All inputs are passed to LEDS_OpeningFcn via varargin.
%
%
*See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
%
instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help LEDS
% Last Modified by GUIDE v2.5 15-Feb-2014 11:26:49
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @LEDS_OpeningFcn, ...
'gui_OutputFcn', @LEDS_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback',
[]);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before LEDS is made visible.
function LEDS_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject
handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% varargin
command line arguments to LEDS (see VARARGIN)
a=imread('ALF.jpg');
imshow(a);
% Choose default command line output for LEDS
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes LEDS wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = LEDS_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject
handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject
handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
clear all;
s = serial('COM3');
set(s,'Baudrate',9600);
fopen(s);
fprintf(s,'%s','A');
fclose(s);
delete(s);
clear s

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject
handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
clear all;
s = serial('COM3');
set(s,'Baudrate',9600);
fopen(s);
fprintf(s,'%s','B');
fclose(s);
delete(s);
clear s
COMUNICACION SERIAL DSPIC30F3014 Y MATLAB

More Related Content

PDF
0.my book draft chap 1
DOCX
TRAFFIC CODE MATLAB Function varargouttraffic code
PDF
Indirect Communications (Concurrency)
PDF
Mdp plus 2.1
PDF
Automatic Identification of Bug-Introducing Changes
PDF
Didactum SNMP Manual
PDF
Scala Under the Hood / ScalaSwarm
PPT
Kts c6-vhdl
0.my book draft chap 1
TRAFFIC CODE MATLAB Function varargouttraffic code
Indirect Communications (Concurrency)
Mdp plus 2.1
Automatic Identification of Bug-Introducing Changes
Didactum SNMP Manual
Scala Under the Hood / ScalaSwarm
Kts c6-vhdl

What's hot (7)

DOCX
Realisation de controlleur VGA(VHDL)
PDF
Anomalies in X-Ray Engine
PPTX
Simware framework hello world: A webinar
TXT
Blood pressure set programming
PDF
Rootkit on Linux X86 v2.6
PPTX
Embedded JavaScript
PDF
Capture and replay hardware behaviour for regression testing and bug reporting
Realisation de controlleur VGA(VHDL)
Anomalies in X-Ray Engine
Simware framework hello world: A webinar
Blood pressure set programming
Rootkit on Linux X86 v2.6
Embedded JavaScript
Capture and replay hardware behaviour for regression testing and bug reporting
Ad

Similar to COMUNICACION SERIAL DSPIC30F3014 Y MATLAB (20)

PDF
PLEASE HELP!Modify the source code to implement the followingCh.pdf
PDF
The IoT Academy IoT Training Arduino Part 3 programming
TXT
PIC and LCD
PDF
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
PPT
PPTX
Introduction to Arduino Microcontroller
DOCX
eece237lab2EECE237Lab2.uvproj 1.1 ### uVision .docx
PPTX
Introduction To Arduino-converted for s.pptx
PDF
Embedded systems development Defcon 19
PDF
Lec1combo123456712345671234561234567.pdf
PPTX
Sensors and Actuators in Arduino, Introduction
DOCX
Lab_5.txt.rtfLab_05Design an application that reads the .docx
PPTX
Arduino Programming - Brief Introduction
PPTX
02 General Purpose Input - Output on the Arduino
PDF
Arduino reference
PPTX
ee2004Assignment_four_SemB24-25kk25.pptx
PDF
Experiment 16 x2 parallel lcd
PPT
Lec2.ppt
PLEASE HELP!Modify the source code to implement the followingCh.pdf
The IoT Academy IoT Training Arduino Part 3 programming
PIC and LCD
DEF CON 23 - Rodringo Almeida - embedded system design from electronics
Introduction to Arduino Microcontroller
eece237lab2EECE237Lab2.uvproj 1.1 ### uVision .docx
Introduction To Arduino-converted for s.pptx
Embedded systems development Defcon 19
Lec1combo123456712345671234561234567.pdf
Sensors and Actuators in Arduino, Introduction
Lab_5.txt.rtfLab_05Design an application that reads the .docx
Arduino Programming - Brief Introduction
02 General Purpose Input - Output on the Arduino
Arduino reference
ee2004Assignment_four_SemB24-25kk25.pptx
Experiment 16 x2 parallel lcd
Lec2.ppt
Ad

More from Carlos Buitron Quispe (6)

DOCX
Programación orientada a objetos en vb 2012
DOCX
Uso del timer2 para pwm con el pic 16 f877a con el compilador hi tech
DOCX
Uso del timer0 para el pic 16 f877a con el compilador hi tech
PPTX
SISTEMA RECONOCIMIENTO DE OBJETOS APLICANDO PROCESAMIENTO DE IMAGENES
PDF
Tutorial de programacion en c para pic16 f877a
Programación orientada a objetos en vb 2012
Uso del timer2 para pwm con el pic 16 f877a con el compilador hi tech
Uso del timer0 para el pic 16 f877a con el compilador hi tech
SISTEMA RECONOCIMIENTO DE OBJETOS APLICANDO PROCESAMIENTO DE IMAGENES
Tutorial de programacion en c para pic16 f877a

COMUNICACION SERIAL DSPIC30F3014 Y MATLAB

  • 1. C:UsersCARLOSDesktoppractica dspicUART_LEDS.c #include "p30fxxxx.h" #include "LCD.h" #include "UART.h" #include "libpic30.h" //Macros para la configuración de los fusibles _FOSC(CSW_FSCM_OFF & XT_PLL4); _FWDT(WDT_OFF); _FBORPOR(PBOR_OFF & PWRT_16 & MCLR_EN); _FGS(CODE_PROT_OFF); #define BORRAR_HYPERTERMINAL TX_UART1_CHAR('f') unsigned char rx; void main() { ADPCFG = 0xFFFF; __delay_ms(15); //LCD_CONFIG(); INICIO_UART1(_9600); //BORRAR_HYPERTERMINAL; //TX_UART1_MENSAJE("Hola alumnos UTPnr",18); //TX_UART1_MENSAJE("ttCuanto va el Peru Panama?nr",29); ADPCFG = 0XFFFF; TRISB = 0xFF00; //Los cuatro pines menos significativos son salida while(1); } void __attribute__((__interrupt__))_U1RXInterrupt(void) { rx = U1RXREG; // if(rx=='s' || rx=='S') if(rx=='A' ) { PORTBbits.RB0 = 1; __delay_ms(200);PORTBbits.RB0 = 0; __delay_ms(200);} if(rx=='B' ) { PORTBbits.RB1 = 1; __delay_ms(200);PORTBbits.RB1 = 0; __delay_ms(200); } // TX_UART1_MENSAJE("Va ganando Peru 2 a 1n",23); IFS0bits.U1RXIF = 0; }
  • 2. // ***********************CONFIGURACION DEL REGISTRO UART*************************** void INICIO_UART1(unsigned char baudios) { U1BRG = baudios; //9600 bps, U1BRG es un registro de 16 bits U1MODE = 0; //8 bits de datos, sin paridad(STSEL=0) y 1 bit de stop. /*PDSEL<1:0> - Parity and data selection bits 00 – 8-bit data, no parity 01 – 8-bit data, even parity 10 – 8-bit data, odd parity 11 – 9-bit data, no parity*/ // STSEL – STOP selection bit (STSEL=0 one STOP bit, STSEL=1 two STOP bits) U1MODEbits.UARTEN = 1; // habilito UART dentro del registro U1MODE U1STAbits.UTXEN = 1; // habilito la transmision dentro del registro U1STA IPC2 = IPC2 | 0x0030; // Prioridad nivel 3 para U1RXIP /* Los registros IECx permite habilitar las respectivas interrupciones del CPU. Una vez puesto a '1' logico el respectivo bit, la interrupcion queda activa y es posible que un evento la dispare. Estos bits,normalmente se habilitan una sola vez en el programa, a menos que el programador desee desactivar la interrupcion a raiz de otro evento */ IEC0bits.U1RXIE = 1; // Para habilitar la interrupcion /* Los registros IFSx contienen las banderas de las diversas interrupciones del DSPIC30F3014. Estas banderas automaticamente se ponen a '1' logico para indicar que una interrupcion ha ocurrido. Una vez atendida la interrupcion esta bandera debe ser puesta a '0' logico por firmware, ya que de no hacerlo la rutina de interrupcion sera considerada no atendida por el CPU y esta se volvera a ejecutar */ IFS0bits.U1RXIF = 0; // Para borrar la bandera o flag de interrupcion por el U1RXREG } void TX_UART1_CHAR(unsigned char dato) { U1TXREG = dato; while(U1STAbits.TRMT == 0); /* TRMT - Transmitir registro de desplazamiento es poco vacío (TRMT = 0 transmiten registro de desplazamiento no está vacío, transmisión en curso, TRMT = 1 registro de desplazamiento de transmisión está vacía, la transmisión completa) */ }
  • 3. void TX_UART1_MENSAJE(unsigned char *datos, unsigned char tam) { unsigned char i=0; while(i<tam) { TX_UART1_CHAR(datos[i]); i++; } } C:UsersCARLOSDesktoppractica dspicUART.h  este archivo incluyan como UART.h #define _9600 64 #define _19200 32 #define _38400 15 #define _57600 10 void INICIO_UART1(unsigned char baudios); void TX_UART1_CHAR(unsigned char dato); void TX_UART1_MENSAJE(unsigned char *datos,unsigned char tam); void INICIO_UART2(unsigned char baudios); void TX_UART2_CHAR(unsigned char dato); void TX_UART2_MENSAJE(unsigned char *datos,unsigned char tam);
  • 4. EN LA FIGURA SE MUESTRA LA MANERA DE AJUNTAR ESTOS ARCHIVOS “xxx.h” y “xxx.c”
  • 5. INTERFAZ GUI MATLAB PARA PROBAR LA COMUNICACIÓN SERIAL DSPIC30F3014 function varargout = LEDS(varargin) % LEDS M-file for LEDS.fig % LEDS, by itself, creates a new LEDS or raises the existing % singleton*. % % H = LEDS returns the handle to a new LEDS or the handle to % the existing singleton*. % % LEDS('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in LEDS.M with the given input arguments. % % LEDS('Property','Value',...) creates a new LEDS or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before LEDS_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to LEDS_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES
  • 6. % Edit the above text to modify the response to help LEDS % Last Modified by GUIDE v2.5 15-Feb-2014 11:26:49 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @LEDS_OpeningFcn, ... 'gui_OutputFcn', @LEDS_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before LEDS is made visible. function LEDS_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to LEDS (see VARARGIN) a=imread('ALF.jpg'); imshow(a); % Choose default command line output for LEDS handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes LEDS wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line.
  • 7. function varargout = LEDS_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; s = serial('COM3'); set(s,'Baudrate',9600); fopen(s); fprintf(s,'%s','A'); fclose(s); delete(s); clear s % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; s = serial('COM3'); set(s,'Baudrate',9600); fopen(s); fprintf(s,'%s','B'); fclose(s); delete(s); clear s