0% found this document useful (0 votes)
87 views13 pages

Led Control by Matlab and Massage Display On LCD Serial Communication and Pic 16f877a

This document describes a project using MATLAB, a PIC microcontroller, and serial communication to control LEDs and display messages on an LCD. The project uses MATLAB's graphical user interface to send commands via serial communication to the PIC microcontroller. The PIC then controls two LEDs and displays messages on an LCD based on the received commands. The document provides code examples for MATLAB, the PIC microcontroller, and details the hardware and software setup.

Uploaded by

KalpeshPatil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views13 pages

Led Control by Matlab and Massage Display On LCD Serial Communication and Pic 16f877a

This document describes a project using MATLAB, a PIC microcontroller, and serial communication to control LEDs and display messages on an LCD. The project uses MATLAB's graphical user interface to send commands via serial communication to the PIC microcontroller. The PIC then controls two LEDs and displays messages on an LCD based on the received commands. The document provides code examples for MATLAB, the PIC microcontroller, and details the hardware and software setup.

Uploaded by

KalpeshPatil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

MATLAB Serial Communication, for quire contact: engnr.shakeel@gamil.

com

1 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

LED control by MATLAB and MASSAGE
display on LCD, RS232 SERIAL
COMMUNICATION, and PIC 16F877A
PIC16F877A is an easy micro controller for the beginners
Here in project:
1) How PIC switches to TWO LEDS from MATLAB Graphic User Interface
2) HOW we use PIC in Serial communication
3) How LCD is used with PIC
4) How PIC is connected with RS232 PORT of PC
Than the micro controller read input from the virtual terminal an than display on the LCD and also
Switch on the LED
a. MickroC PRO // for programming of MICRO CONTROLLER
b. Proteous 8 professional //For simulation of CKT and Design
c. MATLAB 2009 // for controlling and sending Control commands for CKT
d. Virtual Port Driver 6.9v // for generation of Pair of virtual ports on your system

BEST OF LUCK.
Engr Rana Muhammad Shakeel
[email protected]
+92-333-4962507
https://www.facebook.com/EngnrShakeel

FOR MY MORE SHORT PROJECTS:
https://uettaxila.academia.edu/EngrRanaMShakeel
plz like my page:
https://www.facebook.com/Electrical4Electronics
MATLAB Serial Communication, for quire contact: [email protected]

2 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

Circuit Diagram



SETTING FOR COMPIM:
MATLAB Serial Communication, for quire contact: [email protected]

3 Engr Rana M Shakeel, +92-333-4962507 | [email protected]



Virtual Port Driver 6.9v PORT settings
MATLAB Serial Communication, for quire contact: [email protected]

4 Engr Rana M Shakeel, +92-333-4962507 | [email protected]


You can also see these virtual ports from Control Panel-Device manger-Ports
Code for MATLAB LED GUI:
MATLAB Serial Communication, for quire contact: [email protected]

5 Engr Rana M Shakeel, +92-333-4962507 | [email protected]


CODE:
function varargout = LED(varargin)
% LED M-file for LED.fig
% LED, by itself, creates a new LED or raises the existing
% singleton*.
%
% H = LED returns the handle to a new LED or the handle to
% the existing singleton*.
%
% LED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LED.M with the given input
arguments.
%
MATLAB Serial Communication, for quire contact: [email protected]

6 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

% LED('Property','Value',...) creates a new LED or raises the
% existing singleton*. Starting from the left, property value
pairs are
% applied to the GUI before LED_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to LED_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 LED

% Last Modified by GUIDE v2.5 26-Nov-2013 19:21:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @LED_OpeningFcn, ...
'gui_OutputFcn', @LED_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 LED is made visible.
function LED_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 LED (see VARARGIN)

% Choose default command line output for LED
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

MATLAB Serial Communication, for quire contact: [email protected]

7 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

% UIWAIT makes LED wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = LED_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (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('COM1');
set(s,'BaudRate',9600);
fopen(s);
fprintf(s,'%s','g');
fclose(s)
delete (s)
clear s



% --- 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('COM1');
set(s,'BaudRate',9600);
fopen(s);
fprintf(s,'%s','b');
fclose(s)
delete (s)
clear s



Code for PIC 16F877A:
MATLAB Serial Communication, for quire contact: [email protected]

8 Engr Rana M Shakeel, +92-333-4962507 | [email protected]


// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections


unsigned int adc_rd; // Declare variables
char *text; //
char *error; //
char *g; //
char *b; //
char uart_rd; //


MATLAB Serial Communication, for quire contact: [email protected]

9 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

void introduction (void)
{


Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
text = " Serial COM "; // Define the first message
Lcd_Out(1,1,text); // Write the first message in the first line
text = "by PIC16F877A"; // Define the second message
Lcd_Out(2,1,text); // Define the first message
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text = "Engr Rana M"; // Define the first message
Lcd_Out(1,1,text); // Write the first message in the first line
Delay_ms(100);
text = " Shakeel "; // Define the second message
Lcd_Out(2,1,text); // Define the first message
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
text = "Enter : g or b"; // Define the first message
Lcd_Out(1,1,text);

}


void main ()
MATLAB Serial Communication, for quire contact: [email protected]

10 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

{
TRISD=0;
PORTD=0;
UART1_Init(9600); // Initialize hardware UART1 and establish communication at 9600 bps
// Initializes desired hardware UART module with the desired baud rate
Delay_ms (1000);


trisB=0x00;
portb=1;
adcon1=0x00;

Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)

Delay_ms(100);
introduction (void);
g = "g= Green LED "; // Define the GREEN LED message
b = "b= Blue LED "; // Define the BLUE LED message
do {
if(UART1_Data_Ready()) // data is ready read it
{ uart_rd=UART1_Read(); // READ DATA AND SAVE TO VARIABLE
if (uart_rd == 'g') // if i send g to MC it ON the LED D1
{
MATLAB Serial Communication, for quire contact: [email protected]

11 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

portd=0b00000001; Delay_ms(500);;
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
Lcd_Out(1,2,text);
Lcd_Out(2,2,g);
Delay_ms(500);
}
if (uart_rd == 'b') // if i send b to MC it ON the LED D2
{
portd=0b00100000;Delay_ms(500);;
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
Lcd_Out(1,2,text);
Lcd_Out(2,2,b);
Delay_ms(500);
}
}
}
while(1);
}


MATLAB Serial Communication, for quire contact: [email protected]

12 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

OUT PUT:

MATLAB Serial Communication, for quire contact: [email protected]

13 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

You might also like