AMICUS18-COMPANION-SHIELD AMICUS, AMICUS18-COMPANION-SHIELD Datasheet - Page 30

Amicus18 Companion Shield

AMICUS18-COMPANION-SHIELD

Manufacturer Part Number
AMICUS18-COMPANION-SHIELD
Description
Amicus18 Companion Shield
Manufacturer
AMICUS

Specifications of AMICUS18-COMPANION-SHIELD

Silicon Manufacturer
Microchip
Core Architecture
PIC
Core Sub-architecture
PIC18
Features
USB Interface, In Circuit Serial Programming Interface
Kit Contents
Board
Silicon Family Name
PIC
Silicon Core Number
PIC18F25K20
Rohs Compliant
Yes
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With
PIC18F25K20 Microcontroller
In order to detect and debounce a switch that is pulled down to ground through a resistor, the following
code can be used. It’s essentially the same program as the pulled up version, but references to 0 now
reference 1, and vice-versa:
' Debounce a switch input (Pulled-Down)
' The LED will toggle On and Off whenever the switch is pressed
'
Main:
Crownhill AssociatesLimited 2009 - All Rights Reserved
Dim Switch_Count As Byte
Symbol DetectsInARow = 5
Symbol Switch_Pin = PORTB.4
Symbol LED = PORTB.0
Low LED
Input Switch_Pin
While 1 = 1
Wend
While Switch_Pin <> 0 : Wend
Switch_Count = 5
Repeat
Until Switch_Count >= DetectsInARow
Toggle LED
If Switch_Pin == 1 Then
Else
EndIf
DelayMS 1
Inc Switch_Count
Switch_Count = 0
Amicus18 Companion Shield
Version 1.0
' Monitor switch input for 5 highs in a row to debounce
' Holds the switch counter amounts
' The amount of counts to perform
' Pin where the switch is connected
' Pin where the LED is connected
' Extinguish the LED
' Make the switch pin a input
' Create an infinite loop
' Wait for switch to be released (Pulled Down)
' Pressed state detected ?
' Yes. So increment the counter
' Otherwise...
' Reset the counter
' Wait for 1ms
' Toggle the LED On/Off
' Do it forever
' Exit when 5 iterations have been performed
29
06-10-2009

Related parts for AMICUS18-COMPANION-SHIELD