Search Projects

Blogroll

Final year degree project for engineers DAC0800 based project circuit diagram and interfacing with pic mirocontroller Final year projects based on microcontrollers on programmable peripheral interface 8255
Microcontroller based different projects abstract and source code
PIC 16f877 microcontroller projects Motion control
PIC16f877 motor controller and other light projects
Tutorials of microcontroller PIC16f877, A step by step easy to use self learning rapidex

Thursday, April 15, 2010

Interface of Lights and Switches with microcontroller

AS we have discussed the interface of LED in two post in past. Now we will focus our intensions on the interface of switches.we have built a simple beginner’s circuit, let’s add some input components to the circuit. The simplest input device is a switch. Figure illustrates the circuit. The output devices, namely the LEDs, are connected to the PORTB pins, and the input devices, the switches, are connected to the PORTA pins. This keeps our code quite simple. Also,the LEDs and the switches are arranged in a logically symmetrical order and in our code,we map each switch to an LED. To keep code simple, let’s map switch on PORTA0 pin
to the LED on PORTB0 and so on. What we want to do is to simply record the state of the switches and copy the state to the corresponding LED. So if we press a switch, thereby putting a logic “0” on the corresponding PORTA pin, we output logic “0” on the matching LED on the PORTB pin. Thus a LED will glow if you press the corresponding switch, and when you release the switch, the LED will stop glowing.The code shows how to read a switch and light up an LED. However, the switch interfacing is not proper. Typically, a switch, being a mechanical device, doesn’t make a clean contact when it is pressed or released. A bounce occurs when a switch is pressed. The bounce can last for several milliseconds as illustrated in the figure. Comparatively, the processor executes instructions much faster, up to 1000 times faster or even more. Given such a disparity, if a program were to read a switch and decide to take some action if it is pressed, then even for a single-switch press, it will end up taking the action many, many times. One cure for this problem is to use external damping components such as an RC delay circuit. A better, cost-saving method,
which is more elegant, is to provide the damping in software. This software damping scheme is called debouching the switch. The processor reads the switch input pin, and when it detects a change of logic from “1” to “0”. After this period, the logic on the switch has stabilized to “0”. The processor then reads the switch input again to ensure that it is still pressed. The processor then enters a software loop and monitors the switch input pin till the switch is released again. The release of the switch is characterized by the logic at the pin changing from logic “0” to logic “1”. After detecting this logic change, the processor again calls a delay routine to timeout the signal bounce on the switch and again checks if the switch has stabilized to a logic value “1”. If so, the program concludes that the particular switch was pressed and released and then can take any action as necessary.
Device 16F84
Xtal = 4
symbol led1=portb.0 'define pin for led1
symbol led2=portb.1 'define pin for led2
symbol led3=portb.2 'define pin for led3
symbol led4=portb.3 'define pin for led3
symbol pb1=PORTa.0 'define pin for push button
symbol pb2=PORTa.1 'define pin for push button
symbol pb3=PORTa.2 'define pin for push button
symbol pb4=PORTa.3 'define pin for push button
symbol pb5=PORTa.4 'define pin for push button
TRISA = %11111111 ' Make PORTB all outputs
TRISB = 000000
dim edge1 as bit 'define a single bit of ram
dim edge2 as bit
dim edge3 as bit
dim edge4 as bit
dim edge5 as bit
loop:
if pb1=1 and edge1=0 then 'check if button pressed for rising edge
led1=led1 ^ 1 'toggle led1
edge1=1 'set for rising edge
elseif pb1=0 then 'check button for clear rising edge bit
edge1=0 'clear rising edge bit
endif
if pb2=1 and edge2=0 then 'check if button pressed for rising edge
led2=led2 ^ 1 'toggle led2
edge2=1 'set for rising edge
elseif pb2=0 then 'check button for clear rising edge bit
edge2=0 'clear rising edge bit
endif
if pb3=1 and edge3=0 then 'check if button pressed for rising edge
led3=led3 ^ 1 'toggle led2
edge3=1 'set for rising edge
elseif pb3=0 then 'check button for clear rising edge bit
edge3=0 'clear rising edge bit
endif
if pb4=1 and edge4=0 then 'check if button pressed for rising edge
led4=led4 ^ 1 'toggle led2
edge4=1 'set for rising edge
elseif pb4=0 then 'check button for clear rising edge bit
edge4=0 'clear rising edge bit
endif
if pb5=1 and edge5=0 then 'check if button pressed for rising edge
led1=led1 ^ 1
delayms 100
led1=led1 ^ 1
delayms 100
led2=led2 ^ 1
delayms 100
led2=led2 ^ 1
delayms 100
led3=led3 ^ 1
delayms 100
led3=led3 ^ 1
delayms 100
led4=led4 ^ 1
delayms 100
led4=led4 ^ 1
delayms 100
edge5=1 'set for rising edge
elseif pb5=0 then 'check button for clear rising edge bit
edge5=0 'clear rising edge bit
endif
goto loop 'return back to check again


Interface of Lights and Switches with microcontroller,LED interfacing with microcontroller,push button interface
Tags:-
push button switch,illuminated push button switch,push button start,
teknic push button,push button locks,telemecanique push button,
push button station,emergency stop push button,Using Push Buttons with PIC and switch debouncing example,Momentary Pushbutton Switch Implementation with PIC Microcontroller,push button interfacing : 8051 Microcontroller Projects AVR PIC ,How do i set off a pushbutton switch using a microcontroller ,Keypad - Tutorial Microcontroller ,Interfacing microcontrollers to external devices Embedded PIC Microcontroller Projects Tutorial - Push Button PIC MICROCONTROLLER PROJECTS TUTORIAL Microcontroller - Adding a button Push-buttons - Pic-tutorial - Tutorials Embedded PIC Microcontroller Projects Tutorial - PushButton Experimenting with PIC Microcontrollers Push Button Interrupt Usage in PIC 16bit Microcontrollers Counting on Seven Segment using the Push Button Debouncing buttons How to connect 4 buttons Keypad to Microcontroller Advanced PIC microcontroller projects How to control digital pot without using microcontroller

No comments:

Post a Comment

Hi: This is PICINF.blogspot.com comments section. Here you are requested to write your question or problems in detail. Write the question in such a way that, it have all necessary information, sothat i can understand and reply.If you want to send pictures and codes then e-mail me (rghkk@hotmail.com).Thanks.