Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Automatic Room Light Controller with visitor counter for single door

Status
Not open for further replies.
htc.h is Hi Tech C Compiler header file. You have to include that file in your program if you are use Hi Tech C Compiler.

The following is mikroC code for LCD. It is for Lcd control and data port settings.

Code:
// 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
 

can you do the programme using "
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;
"

without using "htc.h"?
please modify this programmed given below by "TS3TYusing" using
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;




please help me....
 

Do you want this code to be written in mikroC PRO code

Code:
#include <htc.h>
__CONFIG(0x3FF1);
 
#ifndef _XTAL_FREQ
    #define _XTAL_FREQ 4000000
#endif
 
// HD44780 controller based LCD display drivers for PIC10/12/16
// Driver is a personal work I made, you can download the LCD driver from:
// [url]https://www.edaboard.com/blog/1817/[/url]
#include "HD44780.h"
#include "HD44780.c"
 
#define sA RA0
#define sB RA1
#define sL RA2
 
void main(void){
    // TRIS registers
    TRISA = 0x03; // RA0 and RA1 are inputs
    TRISB = 0x00;
 
    // assuming sensors are variables sA and sB, and lights switch is sL
    unsigned int People=0;  // counter for people inside the room
    char AllowNextCount=0;  // boolean indicating if allowing next count or not
    short int InOut;        // 1 = entering; -1 = exiting
    
    // Initializing LCD
    LCD_Initialize();
    
    // Set data on display the first time
    LCD_Clear();
    LCD_WriteString("Counter: ");
    LCD_WriteNumber(People);
    LCD_WriteString("\nLights:  ");
    LCD_WriteNumber(sL);
    
    while (1){
        if ((sA==0) && (sB==1)){
            // entering
            InOut = 1;
        }
        
        if ((sA==1) && (sB==0)){
            // exiting
            InOut = -1;
        }
        
        if ((sA==1) && (sB==1) && (AllowNextCount==1)){
            // only when both sensors are touched validate the people counter
            People += InOut;
            
            if (People > 0) sL = 1; // Turn/keep lights on as long as People greather than 0
            else sL = 0;            // otherwise, turn them off
            
            // count once then block counting until the same person has finished entering/exiting
            AllowNextCount=0;
            
            // Update data on display
            LCD_Clear();
            LCD_WriteString("Counter: ");
            LCD_WriteNumber(People);
            LCD_WriteString("\nLights:  ");
            LCD_WriteNumber(sL);
        }
        
        if ((sA==0) && (sB==0)){
            // it gets 0;0 only when someone has finished entering/exiting
            // or at turn on; so now allow to counting again
            AllowNextCount=1;
        }
    }
}
 

Here are the files

Code:
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;

//__CONFIG(0x3FF1);

#define sA PORTA.F0
#define sB PORTA.F1
#define sL PORTA.F2

//assuming sensors are variables sA and sB, and lights switch is sL
unsigned int people = 0;              // counter for people inside the room
char AllowNextCount = 0;              // boolean indicating if allowing next count or not
short int InOut;
unsigned char str_people[17], str_sL[17];                    // 1 = entering; -1 = exiting
    
void main(void){
    // TRIS registers
    TRISA = 0b00000011;                       // RA0 and RA1 are inputs
    TRISB = 0x00;
    ADCON1 = 0b10000111;
    CMCON = 0x07;

    // Initializing LCD
    LCD_Init();

    // Set data on display the first time
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);
    Lcd_Out(1,1,"Counter: ");
    IntToStr(people, str_people);
    Lcd_Out(1,11,str_people);
    LCD_Out(2,1,"Lights:  ");
    IntToStr(sL ,str_sL);
    LCD_Out(2,11,str_sL);

    while (1){
        if ((sA==0) && (sB==1)){
            // entering
            InOut = 1;
        }

        if ((sA==1) && (sB==0)){
            // exiting
            InOut = -1;
        }

        if ((sA==1) && (sB==1) && (AllowNextCount==1)){
            // only when both sensors are touched validate the people counter
            people += InOut;

            if (people > 0) sL = 1; // Turn/keep lights on as long as People greather than 0
            else sL = 0;            // otherwise, turn them off

            // count once then block counting until the same person has finished
            //entering/exiting
            AllowNextCount=0;

            // Update data on display
            Lcd_Out(1,1,"Counter: ");
            IntToStr(people, str_people);
            Lcd_Out(1,11,str_people);
            LCD_Out(2,1,"Lights:  ");
            IntToStr(sL ,str_sL);
            LCD_Out(2,11,str_sL);
        }

        if ((sA==0) && (sB==0)){
            // it gets 0;0 only when someone has finished entering/exiting
            // or at turn on; so now allow to counting again
            AllowNextCount=1;
        }
    }
}
 

Attachments

  • mmahfuj.rar
    60.5 KB · Views: 58
  • sim ss 22.jpg
    sim ss 22.jpg
    218.4 KB · Views: 77

Please explain me about these library code:
what means by "htc.h"?
(...)
Why don't you use these code to initialize LCD? :>
1) htc.c is the base HiTech-C functions library and definitions that permits to program PIC 10/12/16 ICs using their compiler. Without that library the HiTech-C compiler wouldn't be able to find some data types definitions and constants (like RA0, PORTA ect). It's just a standard library to include as you would do with standard C where you include the stdio library.
2) I'm not using the code you showed me for the LCD because the HiTech-C compiler doesn't have an LCD driver included (probably the pro version has it, but I'm using the free Lite version). This is why I had to find an LCD driver to be used with the HiTech-C compiler - I've found some on the web but I didn't like them, so I wrote my own. that's all.
If you feel you know how to use the mikroC LCD driver then feel free to remove the LCD driver I made and use your own functions instead.
 

Not with the lcd driver I made. You have to manually set the output pins for either the 7 segments or for a BCD to 7 segment decoder.
 

hello..can i ask u something?what good software use to build the cct?can u suggest to me??bcoz there are missing component in software that i use...can u help me..
 

Repeat, please?
 

Repeat, please?

what software need use to test the circuit either the circuit function or not??the software i use now is isis but the component still not enough to build the circuit..can u suggest me the other software??:)
 

Well, simulating PICs need to actually use a HEX file with the PIC program. Microchip offers an IDE called MPLAB which can compile assembler language with the integrated assembler compiler, or C code using other compilers; but you can find other IDEs that can do the same or have even more advanced functionality.
Once you compiled it the PIC program the IDE produces an output file with .hex extension. In the PIC properties in ISIS you have to set this hex file in the Program File field, then the simulation will run that program.

p.s. The "repeat please" was because of SMS language, please don't use it again :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top