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.

[PIC] Help with Automatic Room Light Controller with Visitor Counter using Pic16f84a

Status
Not open for further replies.

shegzzyy

Full Member level 2
Joined
Apr 28, 2013
Messages
132
Helped
12
Reputation
24
Reaction score
12
Trophy points
1,298
Activity points
2,016
I need urgent help in designing an automatic room light controller with pic16f84a in assembly language.The light in the room will be switched off when nobody is in the room and switches on when sombody enters the room.i also want to display the number of people in the room on a dual 7-segment display.To avoid complexity,the door entrance is narrow thus only one person can enter at a time.Can anyone help me with the code and circuit or guide me through the process?Thanks
 

You need two IR detectors at the door. Lets say one IR detector is inside the room (at the door frame) and another outside the room (also fixed to door frame). The IR pairs will be placed in opposite. If the first IR pair which is outside the room (door frame) detects entry and then the 2nd IR pair detects the entry then it means the person has entered the room. If reverse happens that is 2nd pair detects first and then 1st IR pair then it means a person has left the room. When person enters a room you increment a counter and if person leaves the room you decrement the same counter. If entry is detected then light is turned ON and if exit and no. of people count is 0 then light is turned OFF.
 

Hi,

This site gives Assembly and hardware details of 7 seg displays and IR sensors etc though you will have to build them together or keep searching if you want a ready made solution, though you won't learn much that way..
http://www.winpicprog.co.uk/pic_tutorial.htm
 
visit: **broken link removed**

hope its helps you.

Thanks for the link.that's the kind of project i wanted to do.the problem is that i dont understand c language, i dont have pic16f690, i want to display the result on a 7segment display and not on lcd.can you help me with some asm snipet with pic16f84a just to get me going.i understand the principle backing the project but writing the code is the problem.thanks
 

First try to understand the concept of the project. I hope you can be able to write your own program then. Its easy and simple. I described all clearly in that site.

Thanks.
 

First try to understand the concept of the project. I hope you can be able to write your own program then. Its easy and simple. I described all clearly in that site.

Thanks.

Yes you described it very well in the site and i understood the concept.But i dont understand c language so as to be able to use it to write my own code.thanks for your help
 

You understood the concept,And you know how to write program in assembly language.Then you can write your own program by using that concept.
Actually what is your problem?
 

I have uploaded the asm code and dsn file in the zip folder.it counts up and down on entry and exit.how do i make the led light when one person enters the room(i.e the 7segment reads 01)?the light will stay on till 99(i.e entry into the room reaches 99).the led will off when the number of people in the room >99 or when the number of people in the room is zero?how do i incorporate it into the code?thanks in advance.
 

Attachments

  • room power.asm.txt
    2.7 KB · Views: 79
  • room power628-1.zip
    24.1 KB · Views: 59
  • room power628-2.zip
    24.1 KB · Views: 60

Hi,


Have cleaned up the assembly code and the ISIS diagram and yes it does work.

However it is a very poor code example as there are no comments along side the code to show how the program works.

To add in extra functions to that code you first need to understand every line of that code and how it all works together.

That why I earlier suggested you start with some simple code and learn how to do it yourself, its probably the easier route plus you will have achieved something for yourself; learning how to program in Assembly.

Code:
	;room power control with counter

	list P = 16F628a		;microcontroller 
	#include <P16F628a.inc>	;registers for F628
	__CONFIG	_CP_OFF & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
 						 			
temp1		equ 20h	;for delay
temp2		equ 21h	;for delay
SwUp		equ 22h	;
SwDwn		equ	23h	;
units		equ	24h	;
tens		equ	25h	;
Sw_Flag		equ	26h	;
countt1     equ 27h
countt2     equ 28h
countt3     equ 29h


reset	org		00		
		goto	SetUp			;goto SetUp
			

table	addwf   PCL,F           ;add W to program counter 
        retlw   b'00111111'     
        retlw   b'00000110'     
        retlw   b'01011011'     
        retlw   b'01001111'    
        retlw   b'01100110'    
        retlw   b'01101101'     
        retlw   b'01111101'     
        retlw   b'00000111'    
        retlw   b'01111111'     
        retlw   b'01101111'     




SetUp		
		movlw	b'00001100'	
		banksel TRISA	
		movwf	TRISA		
		clrf	TRISB				;Make all RB output
		movlw	b'10000000'		
		movwf	option_reg
		banksel 0		
		clrf	units					
		clrf	tens			
		clrf	Sw_Flag
		movlw	0x00
		movwf 	PORTB
		movlw	07h				
		movwf	cmcon								
		goto 	Main									

Delay	movlw	0Ah
		movwf	temp2
		nop
		decfsz temp1,1
		goto 	$-2
		decfsz temp2,1
		goto 	$-4	
		retlw 	00
D_1000ms movlw .255
        movwf countt1
        movlw .255
        movwf countt2
        movlw .255
        movwf countt3
        decfsz countt1,1
        goto   $-1
        decfsz countt2,1
        goto $-1
		decfsz countt3,1
        goto $-1
        return
		
Up		btfsc	Sw_Flag,2
		retlw	00
		bsf		Sw_Flag,2
		incf	units,1
		movlw	0Ah		
		xorwf	units,0		
		btfss	status,2	
		retlw	00
		clrf	units
		incf	tens,1
		movlw	0Ah			
		xorwf	tens,0		
		btfsc	status,2	
		clrf	tens				
		retlw	00			
		
		
		
Dwn		btfsc	Sw_Flag,3
		retlw	00
		bsf		Sw_Flag,3
		decf	units,1
		movlw	0FFh		
		xorwf	units,0		
		btfss	status,2	
		retlw	00
		movlw	09
		movwf	units		
		decf	tens,1
		movlw	0FFh		
		xorwf	tens,0		
		btfsc	status,2	
		goto	$+2	
		retlw	00						
		clrf	tens
		clrf	units
		retlw	00			

Main	btfss	portA,2			
		call	Up				
		btfss	portA,3			
		call	Dwn				
		movlw	b'00000001'		 	
		movwf	portA	
		movf	units,0		
		call	table			
		movwf	portB			
		call	Delay	
		clrf	portB			
		movlw	b'00000010'		 	
		movwf	portA			
		movf	tens,0					
		call	table			
		movwf	portB			
		call	Delay			
		clrf	portB			
		btfsc	portA,2			
		bcf		Sw_Flag,2
		btfsc	portA,3			
		bcf		Sw_Flag,3				
		goto	Main		
		
		END
 

Attachments

  • 000040.jpg
    000040.jpg
    214.6 KB · Views: 81

@wp100 thanks for your help.how will i make the led on ra4 switch on when the counter>0 and switch off when counter<0 or >99?do i need another subroutine and counter for this?your help is highly appreciated
 

I Add this subroutine "output" to the code .but it didnt work.what could be the problem.thanks

- - - Updated - - -

I dont know what i'm doing wrong.the up down counter works fine but just cant light the led when counting up or down.the led should only be off when the display reaches 00 or else it should stay on.the subroutine i added didnt work also

- - - Updated - - -

I dont know what i'm doing wrong.the up down counter works fine but just cant light the led when counting up or down.the led should only be off when the display reaches 00 or else it should stay on.the subroutine i added didnt work also
 

Attachments

  • 2DigitUpDwn628a-MOD.ASM.txt
    5.5 KB · Views: 79

Hi,

As you are finding trying insert code into an existing routine is difficult even for an experienced coder, let alone someone who does not really know Assembly.

Though there are now some comments against the code it does not clearly show the path of the program loop and how it all interacts, particularly with a tight little 7 segment routine.

You have defined your needs 2 input switches to count in and out, a room light or led and a headcount display.

Each of those functions are covered by Nigels tutorials 1, 2 and 10

If you follow and learn the details of those tutorials then you will be able to do your own complete program, probably a lot quicker than trying to understand and modify the program code you have now.

Lesson 1 and 2 should only take a hour or so to set up and test out in ISIS or on hardware, the 7 segment a little longer, give it a go...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top