BCD Switch

Electron

New Member
Hi,I am an oldie??
I have an 18M2 and Hex switch coded 1-2-4-8 Positive Logic.
I need to set up the 18M2 as follows:-
Port B B0 to B3 as Input to read code switch
Port B4 as Input for count input to count pulses 5 Secs Duration every 2 Hours
Port B5 as Output.
I need to store a variable for Code switch setting
I need to store a variable for the Input pulses on B4
I need to compare the 2 Variables and make B5 high.
I am finding this a little hard and need a little bit of code
to help out
Thank you
electron
 

westaust55

Moderator
Welcome to the PICAXE forum.

For the first requirement:

Symbol Hex_Sw = b5

DirsB = %00100000 ; set PortB as inputs and B.5 as an output

Hex_Sw = PinsB AND $0F ; fetch the state of the Port B pins and mask to keep only the lower 4 bits.


But we need some further information to help build up a complete code:
1. How offer do you need to scan for a change to the Hex thumb wheel switch?
2. Can you explain about the pulses on pin B.4 more.
(A) is there a series of pulses o Ed a 5 sec duration to be counted, or
(B) pulses each of 5 sec duration with one every 2 hours, or
(C) some other sequence.

3. What are the conditions for making pin B.5 high or low?
Use the HIGH B.5 and LOW B.5 statements to set the pin to the desired stated.
Note that with HIGH and LOW commands the initials DirsB commands is not essential.
 
Last edited:

Electron

New Member
Reply re BCD Swich

Thank you for your early reply westaust55
hope these answers are satisfactory
Answers: Code Switch Inputs are Port B.0 1
B.1 2
B.2 4
B.3 8
--------------------------------------
Pulse Input B.4 [or any other port will do]
--------------------------------------
Output B.5 [or any other port will do]
Conditions
----------
Scan Code Switch only at Power On.
1.There will be a single positive 5V pulse with a duration of 5 Seconds Every 2 Hours
on input B.4
I just need to count on the positive edge of this pulse
3.There will be a series of these pulses incrementing until the
pulse INPUT variable on B.4 = Hex._Sw. Variable, then Port B.5 to go high.
and stay high.
This is the End of the sequence, the project is acting as a long duration one-shot timer.
I only need to have one sequence where the input pulse count = the code switch setting.
and program ends.
I would sincerely like to take this opportunity to thank you for your time
electron
 

nick12ab

Senior Member
One way you can count the pulses on the pulse input is like so:
Code:
	pinB4temp = pinB.4
	if lastInput = 0 and pinB4temp = 1 then
		inc pulseCounter
	end if
	lastInput = pinB4temp
pulseCounter is a byte variable, lastInput and pinB4temp are bit variables.

So you fully understand how this works, I'll give you the exercises of working out why there's a pinB4temp variable, and if there's an alternative way that doesn't need that.

The code above goes in the main program loop (it must run at least every 5 seconds, but there's no consequence if it runs more often than that).

Finally, when replying to a post in a thread, you can do so in that thread (using the button shown below), there's no need to create a new thread.
 

Attachments

Top