Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

RA0 input, 16F690

Status
Not open for further replies.

ibwev

Member
I am trying to recreate the following scenario.

Setup is the following:

RA1-Motion Sensor (I am using a button), RA0 Activate System button, RA5 Buzzer RB5-Red alarm set, RB4-Green system off

The following is what program should do:

Green light blinks 1/10 of a second while system unarmed (RA1 has not been pressed)
Once RA1 is pressed, green light stops blinking and red light starts blinking at 1/10 second intervals
If RA1 is pressed (motion sensor), alarm sounds on RA5

My problem follows:

1) When ANSEL <1,0> is set and TRISA <1,0> is set, the MPLab Simulator can not set RA0 high.
2) When ANSEL <1,0> is cleared and TRISA <1,0> is set, the MPLab Simulator will set RA0 high.

When PIC16F690 is programmed using example number 2 from above, RA0 does not appear to accept a 5 volt input. It does not switch the blinking green light to a blinking red light.

What am I doing wrong?
 

Attachments

  • Alarm.asm
    6.8 KB · Views: 150
Your code has some bugs I wouldn't use the timer for bounce
Have a look at this
Code:
Init
		bcf		STATUS,RP1
	bsf 	STATUS,RP0	;Bank 1 for OSCCON and Option+reg
	
	movlw	b'01110110'	;2MHz internal oscillator
	movwf	OSCCON

	movlw	b'1111'		;wdt max prescale
	movwf	OPTION_REG	;wftcon pg 190

	banksel TRISA       ; set's to right bank
	clrf 	TRISA 		;clears the bank
	banksel TRISB
	clrf 	TRISB
	banksel ANSEL
	clrf	ANSEL		;set's digtal I/O
	banksel	ANSELH		; there two for this chip
	clrf	ANSELH		; this set'e the AN9 to 11 digtal I/O 
	clrf	ADCON0
	banksel TRISA
	movlw 	b'00000011'  ; this set's your pins as input and output
	movwf	TRISA
	banksel TRISB
	movlw	b'00000000' ; set's all output
	movwf 	TRISB
	banksel PORTB
	clrf 	PORTB
That set's you up right
I would use a delay for debouncing
 
Last edited:
You need to redo this part I't not really doing what you want it to do

Code:
start

ButtonTest
	btfss	PORTA,RA0	;has alarm button been pressed
	goto	AlarmButton
	goto	ButtonLoop
AlarmButton
	bsf		PORTB,4	;turn on unactive light
	call	ButtonBounce	;keep light on for tenth of a second
	clrf	PORTB	;turn light off until wtd resets
greenoff
	btfss	PORTA,0	;test ra0 keep light off
	goto	greenoff
	goto	ButtonLoop
ButtonLoop
	call	ButtonBounce	;make button safe to test
	goto	ButtonLoop
	bsf		PORTB,5	;has to be "RB#"
						;turn on red light to show button has been pressed	
	call	ButtonBounce	;alarm light on for tenth of a second
lightsoff
	clrf	PORTB	;turn off lights for remaining cycle
	btfss	PORTA,1	;has motion sensor been activated,
	goto	lightsoff
	call	ButtonBounce	;has sensor been active long enough
	goto	lightsoff
Alarm
	clrf	WDTCON		;Sound alarm indefinitly
	bsf		PORTA,5	;sound alarm
	goto	Alarm
ButtonBounce
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top