Hey, I'm doing a little project to run a pump based on a couple of float switch inputs.. It is pretty basic but so is my PIC programming ability thus far... Here is my code so far, you can see where I stopped as I am having trouble figuring out how to use btfss or btfsc to read the digital inputs which will be either high or low, IE float switch up or down. The main goal is to have a float at the top of the tank and another half way down, the pump will turn on when both floats are HIGH however won't turn off until both floats are LOW so as to avoid the pump coming on and off all the time.
Hope someone can help
Cheers
Code:
list P=12F675
#include P12F675.inc
;Program Configuration Register
__CONFIG _CPD_OFF & _CP_OFF & _BODEN_OFF& _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
; GPIO Pins = xx543210
; Definitions
#define GPTRIS B'00000110' ; Set GP1 and GP2 to input all other as output
#define IN1 B'00000010' ;Digital Input GP1
#define IN2 B'00000100' ;Digital Input GP2
#define OUT1 B'00000001' ;Digital Output GP0
;-----------------------------------------------------------
; Program Memory
;-----------------------------------------------------------
ORG 0x000 ; RESET Vector
nop
; goto INITALIZE
INITALIZE
bsf STATUS, RP0
call 0x3FF
movwf OSCCAL
; GPIO Ports, Store GPTRIS Value into TRISIO direction register
movlw GPTRIS
movwf TRISIO ; Write to TRISIO
; Interupt on Change Register IOCB
; GPIO Pins = xx543210
movlw B'00000000' ; IOCB Disabled on all ports
movwf IOCB
; Peripheral Interrupt Enable Register PIE1
clrf PIE1 ; Peripheral Interupts Disabled
;----------------------------------------
; Analog-to-Digital Converter (A/D) Module (Section 7.0) (PIC12F675 Only)
;
; The analog-to-digital converter (A/D) allows conversion of an analog
; input signal to a 10-bit binary representation of that signal. The
; PIC12F675 has four analog inputs multiplexed into one sample and hold
; circuit. There are two registers to control the functions of the A/D
; module:
; A/D Control Register (ADCON0)
; Analog Select Register (ANSEL)
;
; Note: When using GPIO pins as analog inputs, ensure the TRISIO register
; bits are set (= 1) for input.
; Ports= xxx4x210
; movlw b'00000000' ; Disable Analog input
; movwf ANSEL
CLRF ANSEL ; disable analog
CLRF ADCON0 ; disable ADC
;----------------------------------------
; Comparator Module (Section 6.0)
;
; The PIC12F629/675 devices have one analog comparator. The inputs to
; the comparator are multiplexed with the GP0 and GP1 pins. There is
; an on-chip Comparator Voltage Reference that can also be applied to
; an input of the comparator. In addition, GP2 can be configured as
; the comparator output. The Comparator Control Register (CMCON)
; contains bits to control the comparator. The Voltage Reference
; Control Register (VRCON) controls the voltage reference module.
; CM2:CM0 = 111 - Comparator Off (lowest power) OFF
movlw b'00000111' ; Comparator inputs grounded
movwf CMCON
;----------------------------------------
; Start Main Program
;----------------------------------------
CHECKLEVEL
movlw b'00000000' ;ensure outputs low
movwf GPIO
; movf IN1,w ;place IN1 (GP1) status into w
; sublw
; btfsc f,b
Hope someone can help
Cheers
Last edited: