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.

need help in MPLAB IDE

Status
Not open for further replies.

emperror123

New Member
as i understand the question is mean they have active low switch connected to RB3 and when it is pressed, active high led will on for 1 second, in between 1 sec, any switch press will not happen anything. 2nd is LED in RA1 will on / off 0.25second will be in ISR. both use RC oscillator and 800kHz

now i am require to modified the below coding to add RB0 as switch and RB7 as out put but unfortunate unable to function after i been modified, how should i do? and it need to use INTCON, INTE to do it

Code:
list p=16F84A
	#include p16f84a.inc

	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

W_ISR_TEMP equ 12
STATUS_ISR_TEMP equ 13
d1 equ 21
d2 equ 22

		org 00
		goto start

		org 04
	movwf	W_ISR_TEMP	
	swapf	STATUS,W			
	clrf	STATUS				
	movwf	STATUS_ISR_TEMP	

	bcf			INTCON,T0IF
	
	btfss	PORTA,1
	goto 	ledon
	bcf		PORTA,1
	goto	isrend
	
ledon	bsf	PORTA,1


isrend	swapf	STATUS_ISR_TEMP,W
	movwf	STATUS			
	swapf	W_ISR_TEMP,F	
	swapf	W_ISR_TEMP,W
	retfie	
				


timer	bcf PORTA, 1
		call delay
		bsf PORTA, 1
		call delay
		goto timer

start	bsf STATUS, RP0
		movlw b'00001000'
		movwf TRISB
		clrf TRISA
		movlw	B'00000110'  	; set up timer0 , bits 0-2 prescaler 1:128,  bit3 prescaler to Timer 0, bit5  using main internal clock 800khz/4 = 200khz !
		movwf	OPTION_REG
		bcf STATUS, RP0

		bsf	INTCON,T0IE		;	enable interrupts
		bsf INTCON, INTE
BSF INTCON,GIE

loop        btfsc PORTB, 0
              call delay3
              bcf PORTB, 7
	bsf	 PORTB,4
		call delay1
		bcf PORTB, 4
		CALL delay1
		goto loop




delay		movlw	0x0F
	movwf	d1
	movlw	0x28
	movwf	d2
Delay0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay0

			;2 cycles
	goto	$+1
	return 

delay1	movlw	0x3F
	movwf	d1
	movlw	0x9D
	movwf	d2
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay0

			;2 cycles
	goto	$+1
	return     

delay3       bsf PORTB, 7
                ; delay code omitted, due to i not sure nid add in since it doesnt mention it
                return
		end

after i modified my RA1 will keep blinking non stop which is i set 0.25 on / off
 
Last edited:
<Edited previous post out because this one is better>

Bear with me, it's been a while since I've done assembly.

Don't forget to set TRISB, 0 to enable it as an input.

For your loop, you are better off doing this:

Code:
loop          btfsc PORTB, 0
		call button1
		btfsc PORTB, 3
		call button2
		goto loop

button1	<turn on LED1>
		<delay 1s>
		<turn off LED1>
		<wait until the button is released and debounce if needed>
		<return>

button2	<turn on LED2>
		<delay 1s>
		<turn off LED2>
		<wait until the button is released and debounce if needed>
		<return>

You can also remove the 'timer' function as it is never called.
 
Last edited:
I don't know, post your code!

If it is the same as your first code, then the only time PORTB, 7 gets turned on is in your 'timer3' routine. Then it is immediately turned off again in the next instruction.
 
it is as same as my 1st code

The only time PORTB, 7 gets turned on is in your 'timer3' routine. Then it is turned off again immediately after returning.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top