Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
How PIC switches to TWO LEDS from MATLAB Graphic User Interface
HOW we use PIC in Serial communication
How LCD is used with PIC
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
b. Proteous 8 professional
c. MATLAB 2009
commands for CKT
d. Virtual Port Driver 6.9v
your system
BEST OF LUCK.
Engr Rana Muhammad Shakeel
Engnr.shakeel@gmail.com
+92-333-4962507
https://www.facebook.com/EngnrShakeel
https://www.facebook.com/Electrical4Electronics
Circuit Diagram
You can also see these virtual ports from Control Panel-Device manger-Ports
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
%
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);
6
// Declare variables
char *text;
//
char *error;
//
char *g;
//
char *b;
//
char uart_rd;
//
Lcd_Cmd(_LCD_CLEAR);
text = " Serial COM ";
Lcd_Out(1,1,text);
text = "by PIC16F877A";
Lcd_Out(2,1,text);
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text = "Engr Rana M";
Lcd_Out(1,1,text);
Delay_ms(100);
text = " Shakeel ";
Lcd_Out(2,1,text);
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text = "Enter : g or b";
Lcd_Out(1,1,text);
void main ()
{
TRISD=0;
9
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_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(100);
introduction (void);
g = "g= Green LED ";
b = "b= Blue LED ";
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
{
portd=0b00000001; Delay_ms(500);;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,text);
10
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_Out(1,2,text);
Lcd_Out(2,2,b);
Delay_ms(500);
}
}
}
while(1);
}
11
OUT PUT:
12
13