View Full Version : PIC16F628a Schmitt Trigger Input
yankee
- 6th March 2009, 13:38
How would I program and wire a circuit to use a toggle switch on RA5? I've been unable to get it to work.
~ Dave
Archangel
- 6th March 2009, 16:24
How would I program and wire a circuit to use a toggle switch on RA5? I've been unable to get it to work.
~ Dave
Hi Dave, . . . use a toggle switch . . . do you mean as an input or toggle as an output ? This chip will not output on RA5, so I will assume as an input. A simple if then loop to check port status will do fine. Schmitt trigger has higher and lower readings than TTL to switch say 1volt and 4 volt as opposed to about 1/2 supply voltage.
IF PortA.5 THEN
yankee
- 12th March 2009, 11:15
I haven't tried this yet. Does this look like it will work?
@ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
TRISA = %00000100 ' Make all port a pins inputs except for 5
TRISB = %00000000 ' Make port b pins outputs
B15 VAR PORTB.7
switch:
if porta.5 = 0 then cal
if porta.5 = 1 then main
goto switch
cal:
low B15
pause 3000 ' pause 3 seconds
HIGH B15
pause 3000
if porta.5 = 0 then cal
goto switch
main:
IC performs main routine
Archangel
- 12th March 2009, 16:54
I haven't tried this yet. Does this look like it will work?
@ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
TRISA = %00000100 ' Make all port a pins inputs except for 5
TRISB = %00000000 ' Make port b pins outputs
B15 VAR PORTB.7
switch:
if porta.5 = 0 then cal
if porta.5 = 1 then main
goto switch
cal:
low B15
pause 3000 ' pause 3 seconds
HIGH B15
pause 3000
if porta.5 = 0 then cal
goto switch
main:
IC performs main routine
I would probably do as follows:
@ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
PortA = %00000000 ' set ports to known state
PortB = %00000000 ' outputs will initialize in low state
TRISA = %00100000 ' Make all port a pins outputs except for 5
TRISB = %00000000 ' Change PortB from HI Q to Outputs that will initialize low
i VAR BYTE ' counter variable
cmcon = 7 ' disable comparators
Switch:
IF PortA.5 = 1 THEN Main
PortB.7 = 0
FOR i = 1 TO 30
pause 100 ' pause 100 ms 30 times
NEXT i
PortB.7 = 1
FOR i = 1 TO 30
pause 100
NEXT i
GOTO Switch
main:
' do your main stuff here
goto switch ' go back to switch and check
end
I would change the pauses in case you need to interrupt the code,
and remove redundant loops
yankee
- 18th March 2009, 14:05
Thanks Joe! That worked really slick. Now, I just have to figure out why your code works so well. I could definitely use a code for Dummies book. I'm not understanding the "FOR i = 1 TO 30."
~ Dave
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.