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.

Help me please to learn assemply good

Status
Not open for further replies.

alalbeet

New Member
hi my dear friends

i want to make a micro controller program in assembly language and 16f84 pic

this program is when i click the button on RB4 it will drive a motor in a direction to open as example a door and there are two limit switches in the two ends of the door

so

when the RB4 is on the motor will be on until the limit switch gives one then stop the motor and make a delay time and then close the door until the second limit switch gives one then the motor will be off

i made the following program as follows but there are an error please help me

PHP:
  LIST    P=PIC16F84
    #INCLUDE "P16F84.INC"
    __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

	W_TEMP EQU 4Bh
	STATUS_TEMP EQU 4Ah
	COUNT1 	EQU H'0C'
	COUNT2 	EQU H'0D'

	ORG 0X00
	goto MAIN
	org 0X04
	goto ISR

MAIN
    	bsf INTCON, 7
    	BSF INTCON, 3
    	BSF STATUS, 5
		MOVLW 	H'FE'		;RESET COUNT1 TO 254
		MOVWF 	COUNT1		;	
		MOVLW 	H'FE'		;RESET COUNT2 TO 254
		MOVWF 	COUNT2	
    	MOVLW 0X00
    	MOVWF TRISB
    	BcF STATUS, 5
    	CLRF PORTB
ISR
    	MOVWF W_TEMP
    	MOVF STATUS, 0
    	MOVF STATUS_TEMP
    	BCF INTCON, 0
		BTFSS PORTB, 4
		retfie
		CLRF PORTB
		MOVLW B'00000001'
		xorwf PORTB,1
		BSF PORTB,2
LOOP1	BTFSS PORTB,6
		GOTO LOOP1
		CLRF PORTB
		CALL DELAY
LOOP2	CLRF PORTB
		MOVLW B'00000010'
		xorwf PORTB,1
		BTFSS PORTB,7
		GOTO LOOP2
		CLRF PORTB
RETFIE
DELAY
LOOP3	CLRWDT
	DECFSZ 	COUNT1,1
	GOTO 	LOOP3
	DECFSZ	COUNT2,1
	GOTO	LOOP3	
	RETURN		
	END
 
Can you comment your code It would help you don't have any pins on portb set as input
Code:
        MOVLW   b'11111000'      ;this make's <7-3>inputs and <2-0> outputs
        banksel TRISB                ; put you in the right bank
        MOVWF TRISB               ; set up your inputs and outputs
        banksel PORTB               ;swiches to bank0
        Clrf      PORTB               ; start with PORTB clear


Take a look at this site **broken link removed**
 
Last edited:
- you must use the ISR as a subroutine (you are doing in sequentially)

- you must keep the registers like this :
Code:
ISR:

 movwf w_temp      ;copy W to temp register could be in any bank
 swapf STATUS,W    ;swap status to be saved into W
 bcf   STATUS,RP0  ;change to bank 0 regardless of current bank
 movwf status_temp ;save status to bank 0 register
                     
 
 ;............ your code for this service goes here


 swapf status_temp,W ;register into W, sets bank to original state
 movwf STATUS      ;move W into STATUS ;register
 swapf w_temp,F    ;swap W_TEMP
 swapf w_temp,W    ;swap W_TEMP into W

 retfie

- post the schematic of your circuit, it'll be easier to help you
 
I made the program with no interrupt and made your advices but :-

i need a small thing in it

i said that
when the RB4 is on the motor will be on until the limit switch gives one then stop the motor and make a delay time and then close the door until the second limit switch gives one then the motor will be off

and my program repeat the delay more than once and the motor speed has been decreased

plz help me
 
Last edited:
Post your new code. If you had a button at the door and 2 limit switches you could try something like this
Code:
CSwitch:
        btfss  PORTB,4       ;checks to see if button is pressed an high
        call    checksw       ;if button pressed do this
        btfss  PORTB,3       ;checks to see it limit1 switch is high door closed
        call    limit1            ;if limit1 is reached do this
        btfss  PORTB,2       ;checks to see if limit2 switch is high door open
        call    limit2            ;if limit2 is reached do this
        goto  CSwitch

checksw
          btfss PORTB,3      ; see if door is closed if high go to PORTB 6
          bsf    PORTB,7       ;put  what you want to happen like turn on motor put motor rev
          bsf    PORTB,6      ;put motor fwd
          return 
limit1
          bcf    PORT,6       ;stop motor
          return
limit2   
          bcf    PORT,7       ;stop motor
          return
 
Last edited:
the new code is as follows
PHP:
  LIST    P=PIC16F84
    #INCLUDE "P16F84.INC"
    __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

	W_TEMP EQU 4Bh
	STATUS_TEMP EQU 4Ah
	COUNT1 	EQU H'0C'
	COUNT2 	EQU H'0D'

	ORG 0X00
	goto MAIN
	org 0X04
	goto MAIN

MAIN
    	BSF STATUS, 5
		MOVLW 	H'FE'		;RESET COUNT1 TO 254
		MOVWF 	COUNT1		;	
		MOVLW 	H'FE'		;RESET COUNT2 TO 254
		MOVWF 	COUNT2	
    	MOVLW 0XF0
    	MOVWF TRISB
    	BcF STATUS, 5
    	CLRF PORTB
ISR
		CLRF PORTB
    	MOVWF W_TEMP
    	MOVF STATUS, 0
    	MOVF STATUS_TEMP
		BTFSS PORTB, 4
		GOTO ISR
		CLRF PORTB
		MOVLW B'00000001'
		xorwf PORTB,1
		BSF PORTB,2
LOOP1	BTFSS PORTB,6
		GOTO LOOP1
		CLRF PORTB
LOOP2	CLRF PORTB
		MOVLW B'00000010'
		xorwf PORTB,1
		BTFSS PORTB,7
		GOTO LOOP2
		CLRF PORTB
goto ISR
DELAY
LOOP3	CLRWDT
	DECFSZ 	COUNT1,1
	GOTO 	LOOP3
	RETURN		
	END
 
alalbeet Do you have a wiring diagram of how you want this to work. and you still need to
;;comment your code to let people no what your thinking is going to happen. I'll write a code to read the button and 2 limit switches and let's see what we can make it do.
 
Take a look at this alalbeet
 

Attachments

  • doorc.PNG
    doorc.PNG
    84.6 KB · Views: 165
In LOOP2
switch RB1 turn on/off (4cycs On 2cycs Off) many time, so it just give you about %70 of power so your motor speed downto %70 as normal.
speed should the same as open, if you move label LOOP2 down to line

Code:
LOOP2     BTFSS PORTB,7
 
In LOOP2
switch RB1 turn on/off (4cycs On 2cycs Off) many time, so it just give you about %70 of power so your motor speed downto %70 as normal.
speed should the same as open, if you move label LOOP2 down to line

Code:
LOOP2     BTFSS PORTB,7

thank you all for your replying

thank you me dear friend five0 very very very much the program now is ok
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top