I recently posted an idea to control your home appliances using 8051 microcntroller here. For simulation of this post see the links below. The same can be implemented. But the respective changes will take place as follows:
The IDE used is now MPLAB X IDE.
Compiler is XC8.
Microcontroller is PIC16F887
Programmer is PICKIT3
The block diagram is as shown here:
The circuit i created in proteus as follows:
I have used external HS crystal of 20MHz. So i need to mention that while setting the configuration bits.
For the application and steps to simulate is almost similar as in 8051. You can refer to my previous post. The program is changed now. But is also written in C this time as shown below.
#include <xc.h>
#include <GenericTypeDefs.h>
#include “usart_pic16.h”
// Configuration Byte
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#define Light RC3
#define Plug RC4
#define Fan RC5
void main()
{
//Initialize USART with baud rate 9600
USARTInit(9600);
TRISCbits.TRISC3 = 0;
__delay_ms(100);
TRISCbits.TRISC4 = 0;
__delay_ms(100);
TRISCbits.TRISC5 = 0;
Light = 0;
Plug = 0;
Fan = 0;
while(1)
{
//Get data waiting in USART
uint8_t n= USARTDataAvailable();
// If some data arrives
if(n!=0)
{
//Read it
char ch=USARTReadData();
__delay_ms(100);
if(ch == ‘0’) // ‘0’ means ASCII key ‘0’ same as 0x30 in HEX and 48 in e=decimal. Same you can see below for ‘1’,’2′,’3’…
{
Light = 1;
}
if(ch == ‘1’)
{
Light = 0;
}
if(ch == ‘2’)
{
Plug = 1;
}
if(ch == ‘3’)
{
Plug = 0;
}
if(ch == ‘4’)
{
Fan = 1;
}
if(ch == ‘5’)
{
Fan = 0;
}
if(ch == ‘6’)
{
Light = 1;
Fan = 1;
Plug = 1;
}
if(ch == ‘7’)
{
Light = 0;
Fan = 0;
Plug = 0;
}
}
}
}
The snapshot for the Visual BASIC app is shown below.
The code for setting com port and baudrate is as follows:
Private Sub Form_Load()
MSComm1.CommPort = 1
‘ 9600 baud, no parity, 8 data bits, 1 stop bit
MSComm1.Settings = “9600,N,8,1”
‘ Disable DTR
MSComm1.DTREnable = False
‘open the port
MSComm1.PortOpen = True
End Sub()
Dont forget to close com port at closing form:
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
You can configure each option button shown in the software as below:
Private Sub Option1_Click()
MSComm1.Output = Chr$(48)
End Sub
Here ’48’ means ASCII key ‘0’ or 0x30 in HEX. In program for PIC controller Corrosponding hex code is decoded for particular pins.
You can download simulation files here. Click here to Download
The full simulation video is provided here.
you’re truly a excellent webmaster. The website loading speed is amazing. It sort of feels that you are doing any unique trick. In addition, The contents are masterwork. you have done a great process on this subject!
I have read a few good stuff here. Certainly worth bookmarking for revisiting. I wonder how much effort you put to create such a great informative web site.
My relatives every time say that I am wasting my time here at web, but I know I am getting familiarity daily by reading thes pleasant articles.|