Car Backseat Table System using PIC Micro-controller
First of all select any micro-controller which is available and have external interrupts.
I am using PIC-16f1789 in car backseat tray table
Identify signals to operate the system
To operate Car back seat table using micro-controller we need 3 signals for each table.
- One signal from open and close command to each table
- Detect open position of each table
- Detect close position of each table
Electrical specifications for PIC 16f1789 |
Port A is used for interrupt input.Connections will be as follows.
- port A,1 connect with open/close button for table 1.
- port A,2 connect with open/close button for table 2.
- port A,3 connect with open position sensor for table 1.
- port A,4 connect with close position sensor for table 1.
- port A,5 connect with open position sensor for table 2.
- port A,6 connect with close position sensor for table 2.
- port B,1 to one pin of motor 1.
- port B,2 to other pin of motor 1.
- port B,3 to one pin of motor 2.
- port B,4 to other pin of motor 2.
pin diagram of PIC 16f1789 |
Give on/off signal from micro-controller to the motor through transistors as shown below
Car backseat table using pic micro-controller |
Here is complete code .
#include "p16F1789.inc"
; CONFIG1
; __config 0xFFE4
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
; CONFIG2
; __config 0xFEFF
__CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_ON
ORG 000H
GOTO MAIN
ORG 0004H
BTFSS INTCON,IOCIF
RETFIE
GOTO TABLE_SELECT
ORG 0020H
TABLE_SELECT
BANKSEL INLVLA
BTFSC IOCAF,2
GOTO STOP_M1
BTFSC IOCAF,3
GOTO STOP_M1
BTFSC IOCAF,4
GOTO STOP_M2
BTFSC IOCAF,5
GOTO STOP_M2
BTFSC IOCAF,0
GOTO TABLE_1
BTFSC IOCAF,1
GOTO TABLE_2
RETFIE
TABLE_1
BANKSEL PORTA
BTFSS PORTA,2 ;SENSOR TO READ OPEN POSITION CONNECTED TO PIN 3 OF PORTA//
GOTO OPEN_M1
BTFSS PORTA,3 ;SENSOR TO READ CLOSE POSITION CONNECTED TO PIN 4 OF PORTA//
GOTO CLOSE_M1
RETFIE
TABLE_2
BANKSEL PORTA
BTFSS PORTA,4 ;SENSOR TO READ OPEN POSITION CONNECTED TO PIN 5 OF PORTA
GOTO OPEN_M2
BTFSS PORTA,5 ;SENSOR TO READ CLOSE POSITION CONNECTED TO PIN 6 OF PORTA
GOTO CLOSE_M2
RETFIE
OPEN_M1 ; turns on motor to open table 1
BANKSEL LATA
BSF LATB,0
BCF LATB,1
BANKSEL INLVLA
BCF IOCAF,0
;add
RETFIE
CLOSE_M1 ; reverses the motor to close table 1
BANKSEL LATA
BCF LATB,0
BSF LATB,1
BANKSEL INLVLA
BCF IOCAF,0
RETFIE
OPEN_M2 ; turns on motor to open table 2
BANKSEL LATA
BSF LATB,2
BCF LATB,3
BANKSEL INLVLA
BCF IOCAF,1
RETFIE
CLOSE_M2 ; reverses the motor for table 2
BANKSEL LATA
BCF LATB,2
BSF LATB,3
BANKSEL INLVLA
BCF IOCAF,1
RETFIE
STOP_M1 ;stop motor for table 1
BANKSEL LATA
BCF LATB,0
BCF LATB,1
BANKSEL INLVLA
BCF IOCAF,2
BCF IOCAF,3
RETFIE
STOP_M2 ;stop motor for table 2
BANKSEL LATA
BCF LATB,2
BCF LATB,3
BANKSEL INLVLA
BCF IOCAF,4
BCF IOCAF,5
RETFIE
MAIN
BANKSEL INTCON ; selecting bank
BSF INTCON,GIE ; enable global interrup
BSF INTCON,PEIE ; enable periphiral interrupt
BSF INTCON,IOCIE ; enable interrupt on change
BANKSEL TRISA ; bank select
MOVLW B'11111111' ; port A as input
MOVWF TRISA
BANKSEL INLVLA
MOVLW B'00111111'
MOVWF IOCAP ; selecting interrup on change pins for positive edge interrup
MOVLW B'00000011'
MOVWF IOCAN ; selecting interrup on change pins for negative edge interrup
HERE
GOTO HERE
END
Comments
Post a Comment