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.

correct or not???

Status
Not open for further replies.

shen_gks

New Member
:confused: .. my program is like below:



list p=16F877A ; list directive to define processor
#include <p16F877A.inc> ; processor specific variable definitions

__CONFIG 0X3F32


ORG 0x200 ; processor reset vector
goto main ; go to beginning of program

main


BCF STATUS,RP1
BSF STATUS,RP0 ;SWITCH TO BANK 1
CLRF TRISB ;SET PORTB AS OUTPUT
BSF TRISA,2 ;SET RA2 AS INPUT
BSF TRISA,3 ;SET RA3 AS INPUT
BSF TRISA,4 ;SET RA4 AS INPUT
BCF STATUS,RP0 ;BANK 0

CLRF PORTB ;SET ALL 8 PIN IN PORTB TO LOW(0)

;the main program begin here

START
BTFSS PORTA,2 ;check signal at pushbutton1, if press then goto following line, else skip the following line
CALL RED ;button1 pressed, program execute the operation in subroutine RED
BTFSS PORTA,3 ;check signal at pushbutton2, if press then goto following line, else skip the following line
CALL GREEN ;button2 pressed, program execute the operation in subroutine GREEN
BTFSS PORTA,4 ;check signal at pushbutton3, if press then goto following line, else skip the following line
CALL YELLOW ;button3 pressed, program execute the operation in subroutine YELLOW
GOTO START ;no any button being pressed, program keep looping to check the pushbuttons' signal

RED
BSF PORTB,4 ;ON YELLOW LED
BSF PORTB,5 ;ON GREEN LED
BCF PORTB,6 ;OFF RED LED
RETURN

GREEN
BSF PORTB,4 ;ON YELLOW LED
BCF PORTB,5 ;OFF GREEN LED
BSF PORTB,6 ;ON RED LED

RETURN

YELLOW
BCF PORTB,4 ;OFF YELLOW LED
BSF PORTB,5 ;ON GREEN LED
BSF PORTB,6 ;ON RED LED
RETURN


END ; directive 'end of program'

can somebody help me to check it ma ?? as after i burn i the hardware i can gtt what i want. actually the output i want is very simple. like i press the pushbutton port A2, the subroutine red will operate and after i press other button i will go to other subroutine. hope somebody will reply me. thank a lot.
:D
 
PLEASE use Code tags when posting code. Simply click on the # in the menu before pasting your code.

Code:
	list	p=16F877A	; list directive to define processor
	#include <p16F877A.inc>	; processor specific variable definitions

	__CONFIG 0X3F32


	ORG	0x200		; processor reset vector
	goto	main		; go to beginning of program

main	BCF	STATUS,RP1
	BSF	STATUS,RP0	;SWITCH TO BANK 1
	CLRF	TRISB		;SET PORTB AS OUTPUT
	BSF	TRISA,2		;SET RA2 AS INPUT
	BSF	TRISA,3		;SET RA3 AS INPUT
	BSF	TRISA,4		;SET RA4 AS INPUT
	BCF	STATUS,RP0	;BANK 0

	CLRF	PORTB		;SET ALL 8 PIN IN PORTB TO LOW(0)

;the main program begin here

START	BTFSS	PORTA,2		;check signal at pushbutton1, if press then goto following line, else skip the following line
	CALL	RED		;button1 pressed, program execute the operation in subroutine RED
	BTFSS	PORTA,3		;check signal at pushbutton2, if press then goto following line, else skip the following line
	CALL	GREEN		;button2 pressed, program execute the operation in subroutine GREEN
	BTFSS	PORTA,4		;check signal at pushbutton3, if press then goto following line, else skip the following line
	CALL	YELLOW		;button3 pressed, program execute the operation in subroutine YELLOW
	GOTO	START		;no any button being pressed, program keep looping to check the pushbuttons' signal

RED	BSF	PORTB,4		;ON YELLOW LED
	BSF	PORTB,5		;ON GREEN LED
	BCF	PORTB,6		;OFF RED LED
	RETURN

GREEN	BSF	PORTB,4		;ON YELLOW LED
	BCF	PORTB,5		;OFF GREEN LED
	BSF	PORTB,6		;ON RED LED
	RETURN

YELLOW	BCF	PORTB,4		;OFF YELLOW LED
	BSF	PORTB,5		;ON GREEN LED
	BSF	PORTB,6		;ON RED LED
	RETURN

	END			; directive 'end of program'
 
I checked your program with MPLAB and it runs all the way through and loops.
It should go from Start to goto start and loop until a button is pushed.
Try changing the BTFSS to BTFSC all three of them and retry.
 
shen_gks said:
START
BTFSS PORTA,2 ;check signal at pushbutton1, if press then goto following line, else skip the following line
CALL RED ;button1 pressed, program execute the operation in subroutine RED
BTFSS PORTA,3 ;check signal at pushbutton2, if press then goto following line, else skip the following line
CALL GREEN ;button2 pressed, program execute the operation in subroutine GREEN
BTFSS PORTA,4 ;check signal at pushbutton3, if press then goto following line, else skip the following line
CALL YELLOW ;button3 pressed, program execute the operation in subroutine YELLOW
GOTO START ;no any button being pressed, program keep looping to check the pushbuttons' signal
You have to disable analog functions of the PIC. Configure the ADCON1 register properly (see section 11 in the datasheet). Also add a debounce routine to your code.
Are you using pull-up resistors? Why not add a schematic?

EDIT: typo corrected.
 
Last edited:
reply

what is denounce routine ?? i am a PIC fresh user.can u explain to me ?and i use pull up resistor for input. on the other hand, i use active low for out put.

i have upload sk20 (start kit). it fix with my PIC16f877a. beside it have sk20 info.

thnak a lot.
 
shen_gks said:
what is denounce routine ?? i am a PIC fresh user.can u explain to me ?
I think he meant debounce. Google for [URL="https://www.google.ca/search?q=pic+debounce]pic debounce[/URL]. You'll find lots of info.
 
Last edited:
Setting a bit one after the next line like this is not a good idea.Specially for bit oriented commands.It will work some times but sometimes not So its not good anymore.

Code:
	BSF	PORTB,4		;ON YELLOW LED
	BSF	PORTB,5		;ON GREEN LED
	BCF	PORTB,6		;OFF RED LED

Use image registers or move literals like this.
Code:
	movlw	b'00110000'
	movwf	PORTB

For more informations please refer Read Modify Write.
 
i has add MOVLW B'00000110'
MOVWF ADCON1
to configure port A but when i press the button. it still can loop to other subroutine, it only stop at a subroutine. it is any wrong with the BTFSS command?have i need add or make changing to the program. thank a lot...
 
The ADCON1 register is in Bank 1. You should add 'BANKSEL' directives, like in the code below.

Code:
   BANKSEL ADCON1
   MOVLW   B'00000110' 
   MOVWF   ADCON1
   BANKSEL PORTA
 
confusing...

i am confusing. actually my program will blinking when i press the button or will on when i press it and stay on untill i press other button??
But the output i want is the led on when i press and stay on until i press other button.
thank for reply..:confused: :confused:
 

Attachments

  • guy10.asm
    6.5 KB · Views: 134
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top