ประโยชน์ของโปรแกรม
…สามารถนำไปเป็นต้นแบบของลิฟท์ที่ใช้ภายในครัวเรือนขนาดเล็กโดยทั่วไป ข้อดีคือรูปแบบที่ใช้งานง่ายและระบบไม่มีความซับซ้อนมากอุปกรณ์ที่ใช้มีราคาถูก อีกทั้งยังสามารถนำไปติดตังกับลิฟท์ของอาคารทั่วไปหรืออาคารสำนักงานขนาดเล็กได้
อุปกรณ์ที่ใช้
1.ไมโครคอนโทรลเลอร์ PIC16F1939
2.มอเตอร์
3.เซเว่นเซกเมนต์ คอมมอนแคโทด
4.ทรานซีตเตอร์
5.แอลซีดีขนาด 16x2
6.ตัวต้านทาน 1000 โอห์ม
หลักการทำงานของโปรแกรม
…หลักการทำงานโดยทั่วไปคือผู้ใช้จะเป็นคนเลือกว่าผู้ใช้อยู่ที่ชั้นใดผู้ใช้ก็จะต้องกดฉันนั้น จากนั้นประตูลิฟท์ก็จะเปิดออกรอให้ผู้ใช้เข้าไปประตูลิฟท์ก็จะปิด หลังจากนั้นลิฟท์จะรอคำสั่งว่าผู้ใช้จะไปที่ชั้นใด สมมติว่าผู้ใช้อยู่ชั้นหนึ่งและต้องการจะขึ้นไปชั้นสองก็จะกดที่ชั้นสอง โปรแกรมก็จะสั่งให้มอเตอร์ของลิฟท์นั้นทำงานและขึ้นไปยังชั้นสองขณะที่ลิฟท์กำลังขั้นมอเตอร์กำลังหมุนก็จะมีเซเว่นเซกเมนต์บอกตำแหน่งว่า ลิฟท์ขณะนั้นด้วย
Code of program
#include <16F1939.h>
#include <stdlib.h>
#include<stdio.h>
#include<math.h>
#include "LCD_PIC16F1939.h"
#fuses HS,PLL,NOWDT,NOPROTECT,NOLVP // X-TAL 8MHz+PLL(x4)
#fuses INTRC_IO,PLL,NOWDT,NOPROTECT,NOLVP
#use delay(clock=32000000)
#define DSP_7SEG(x) output_d(x)
#define SW1 input(PIN_C5)
#define SW2 input(PIN_C4)
#define SW3 input(PIN_C2)
#define SW4 input(PIN_C3)
#define LCD_TYPE 2
#define MOTOR_ON output_high(PIN_A1)
#define MOTOR_OFF output_low(PIN_A1)
#define LED5_ON output_high(PIN_A4)
#define LED5_OFF output_low(PIN_A4)
#define LED6_ON output_high(PIN_A5)
#define LED6_OFF output_low(PIN_A5)
#define LED7_ON output_high(PIN_A6)
#define LED7_OFF output_low(PIN_A6)
void lcd_send_data(BYTE lcd_dat);
void lcd_send_command(BYTE lcd_cmd);
BYTE lcd_read_data(void);
BYTE lcd_read_command(void);
void lcd_init(void);
void lcd_set_cursor(BYTE cursor);
void lcd_putc(char c);
char lcd_getc(BYTE cursor);
void main(void)
{///void main
set_tris_a(0x07);
set_tris_b(0x03);
set_tris_c(0xFF);
set_tris_d(0x00);
lcd_send_command(0x01);
setup_oscillator(OSC_8MHz|OSC_PLL_ON);
lcd_init();
while(1)
{ ///while1
MOTOR_OFF;
DSP_7SEG(0x00);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT ON<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc,">>>>ON LINE<<<<");
/////////////////////
if(SW1!=0)
{
delay_ms(120);
if(SW1!=0)
{
while(!SW4)
{
DSP_7SEG(0x06);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<< ");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
delay_ms(3000);
//////////////////set lip1 /////////////////
if(SW2!=0)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT UP<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ^^^^ ^^^^ ");
MOTOR_ON;
delay_ms(2000);
DSP_7SEG(0x06);
delay_ms(600);
DSP_7SEG(0x5B);
delay_ms(600);
while(!SW4)
{
MOTOR_OFF;
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<< ");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
delay_ms(3000);
DSP_7SEG(0x5B);
} }}
if(SW3!=0)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT UP<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ^^^^ ^^^^ ");
MOTOR_ON;
delay_ms(2000);
DSP_7SEG(0x06);
delay_ms(600);
DSP_7SEG(0x5B);
delay_ms(600);
DSP_7SEG(0x4F);
delay_ms(600);
while(!SW4)
{
MOTOR_OFF;
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<< ");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
DSP_7SEG(0x4F);
}}}}}
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");}}
///////////// CLASS 2 TO 1 AND 3 START //////////////
if(SW2!=0)
{ delay_ms(120);
if(SW2!=0)
{ while(!SW4)
{
DSP_7SEG(0x5B);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<< ");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
//////////////////set lip2 /////////////////
/////////////// CLASS 2 TO 1 START //////////////
if(SW1!=0)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT DOWN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," vvvv vvvv ");
delay_ms(2000);
MOTOR_ON;
DSP_7SEG(0x5B);
delay_ms(600);
DSP_7SEG(0x06);
delay_ms(600);
while(!SW4)
{
MOTOR_OFF;
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(3000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<<");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
DSP_7SEG(0x06);
}
}
}
///////////// CLASS 2 TO 1 END //////////////
///////////// CLASS 2 TO 3 START /////////////
if(SW3!=0)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT UP<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ^^^^ ^^^^ ");
delay_ms(2000);
MOTOR_ON;
DSP_7SEG(0x5B);
delay_ms(600);
DSP_7SEG(0x4F);
delay_ms(600);
while(!SW4)
{
MOTOR_OFF;
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(3000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<<");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
DSP_7SEG(0x4F); } }}
///////////// CLASS 2 TO 3 END /////////////
} }
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");}}
///////////// CLASS 2 TO 1 AND 3 END //////////////
///////////// CLASS 3 TO 1 AND 2 START //////////////
if(SW3!=0)
{
delay_ms(120);
if(SW3!=0)
{ while(!SW4)
{
DSP_7SEG(0x4F);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(3000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<<");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
//////////////////set lip3 /////////////////
//////////////// CLASS 3 TO 1 START ////////////
if(SW1!=0)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT DOWN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," vvvv vvvv ");
delay_ms(2000);
MOTOR_ON;
DSP_7SEG(0x4F);
delay_ms(600);
DSP_7SEG(0x5B);
delay_ms(600);
DSP_7SEG(0x06);
delay_ms(600);
while(!SW4)
{MOTOR_OFF;
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(3000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<<");
delay_ms(2000);
while(!SW4)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
DSP_7SEG(0x06);
} }
}
//////////////// CLASS 3 TO 1 END ////////////
//////////////// CLASS 3 TO 2 START ////////////
if(SW2!=0)
{
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT DOWN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," vvvv vvvv ");
delay_ms(2000);
MOTOR_ON;
DSP_7SEG(0x4F);
delay_ms(600);
DSP_7SEG(0x5B);
delay_ms(600);
while(!SW4)
{
MOTOR_OFF;
delay_ms(2000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT OPEN<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," <<<<<< >>>>>>");
delay_ms(3000);
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc,">>>>LIFT CLOSE<<<<");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," >>>>>> <<<<<<");
delay_ms(2000);
while(!SW4)
{lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");
DSP_7SEG(0x5B);
} }}} }
lcd_send_command(0x01);
lcd_set_cursor(0x00); // Start Line(1)
printf(lcd_putc," ");
lcd_set_cursor(0x40); //// Start Line(2)
printf(lcd_putc," ");}}}///while1
} ///End void main