14
MATLAB Serial Communication, for quire contact: [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 1 Engr Rana M Shakeel, +92-333-4962507 | [email protected]

Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

Embed Size (px)

DESCRIPTION

Project

Citation preview

Page 1: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

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

LED control by MATLAB and MASSAGE display on LCD, RS232 SERIAL COMMUNICATION, and PIC 16F877APIC16F877A is an easy micro controller for the beginners

Here in project:

1) How PIC switches to TWO LEDS from MATLAB Graphic User Interface2) HOW we use PIC in Serial communication3) 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 CONTROLLERb. Proteous 8 professional //For simulation of CKT and Design c. MATLAB 2009 // for controlling and sending Control commands for CKTd. 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

1 Engr Rana M Shakeel, +92-333-4962507 |

Page 2: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

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

Circuit Diagram

SETTING FOR COMPIM:

2 Engr Rana M Shakeel, +92-333-4962507 |

Page 3: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

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

Virtual Port Driver 6.9v PORT settings

3 Engr Rana M Shakeel, +92-333-4962507 |

Page 4: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

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

You can also see these virtual ports from Control Panel-Device manger-Ports

Code for MATLAB LED GUI:

4 Engr Rana M Shakeel, +92-333-4962507 |

Page 5: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

MATLAB Serial Communication, for quire contact: [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.%

5 Engr Rana M Shakeel, +92-333-4962507 |

Page 6: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

MATLAB Serial Communication, for quire contact: [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 EDITgui_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 LEDhandles.output = hObject;

% Update handles structureguidata(hObject, handles);

6 Engr Rana M Shakeel, +92-333-4962507 |

Page 7: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

MATLAB Serial Communication, for quire contact: [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 structurevarargout{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:7 Engr Rana M Shakeel, +92-333-4962507 |

Page 8: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

MATLAB Serial Communication, for quire contact: [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; //

8 Engr Rana M Shakeel, +92-333-4962507 |

Page 9: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

MATLAB Serial Communication, for quire contact: [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 ()

9 Engr Rana M Shakeel, +92-333-4962507 |

Page 10: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

MATLAB Serial Communication, for quire contact: [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

{

10 Engr Rana M Shakeel, +92-333-4962507 |

Page 11: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

MATLAB Serial Communication, for quire contact: [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);

}

11 Engr Rana M Shakeel, +92-333-4962507 |

Page 12: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

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

OUT PUT:

12 Engr Rana M Shakeel, +92-333-4962507 |

Page 13: Led Control by Matlab and Massage Display on Lcd Serial Communication and Pic 16f877a

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

13 Engr Rana M Shakeel, +92-333-4962507 |