Working PIC16F88 using sensors and switches


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What do you want it to do if both switches are pushed at the same time?

    Keep in mind that it is nearly impossible to push them both at the same time, one will always be first.

    And are these momentary switches? And do you have pull up resistors on the switch pins (maybe a 10K going to 0 volts)?
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You are also aware that multiple pauses (one in each channel) will affect the time delay in the other channels? Therefore if one channel is on, the loop will have a 50mS delay... if four channels are on then your loop time will be 200mS and your delay will be a lot longer than expected. It would be easier to stick to one delay which is either ON or OFF depending if it is needed...

    There is still one dissadvantage here... if a momentary pulse arrives during the 50mS Pause, then it would be missed... but then you can increase the Count time and proportionately decrease the Pause (eg count to 1000 and Pause for 5mS, or Count to 5000 and Pause for 1mS etc etc) - not forgetting to change your variables to WORDS from BYTES if you're going to do this...

    Also, if you alias the PORTS as I have done, it makes the program more understandable, and if you have to change I/O's (usually at PCB layout time!!!) then it is done just ONCE in your program, not a dozen times throughout your code where it could easily be missed.


    Code:
    	SwitchA var PortA.0
    	SwitchB var PortA.3
    	SensorA var PortA.1
    	SensorB var PortA.2
    	LEDA var PortB.2
    	LEDB var PortB.0
    
    	TRISA=%11111111
    	TRISB=%00000000
    
    	Low LEDA
    	Low LEDB
    
    	i=100
    	j=100
    
    Loop: 
    	'
    	'	Read Inputs
    	'	-----------
    	If SwitchA=1 then i=0
    	If SensorA=1 then i=0
    	If SwitchB=1 then j=0
    	If SensorB=1 then j=0
    
    	'
    	'	Process Outputs
    	'	---------------
    	If i < 100 then 
    		High LEDA
    		else
    		Low LEDA
    		endif
    	If j < 100 then 
    		High LEDB
    		else
    		Low LEDB
    		endif
    
    	'
    	'	Update Counters & Timer
    	'	-----------------------
    	If i < 100 then i=i+1
    	If j < 100 then j=j+1
    	If ((i+j)<200) then Pause 50
    	Goto Loop

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts