• 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.

Plz help as soon as possible :( :(

Status
Not open for further replies.

goldfish300

New Member
well im working on a project for the p16f628A and the program should do the followeing

if pb1(puch button) =1 > left

if pb2 =1>right

if pb3 =1 > Motor goes in full speed
=0 > motor goes in half speed
i have just wrote the code but can't get it right so plz who can help me i will post the code (.asm) and the picture with the files needed

Code:
#INCLUDE	"P16F628A.INC"

#DEFINE	PB1	PORTA,0
#DEFINE	PB2	PORTA,1
#DEFINE	PB3	PORTA,2
#DEFINE	SW	PORTA,3
	
	ORG		0X000
	GOTO	MAIN

MAIN
	CALL	SETUP
	CALL	SETUP_PWM_1	
	GOTO	LOOP

				 

LOOP	
	BTFSC	PB1
	CALL	       MOTOR_STOP
	BTFSC	PB2
	CALL	        MOTOR_LEFT
	BTFSC	PB3
	CALL   	MOTOR_RIGHT	
	BTFSC	SW
	CALL	        HIGH_SPEED	
	BTFSC	SW
	CALL          HALF_SPEED
	GOTO	LOOP

MOTOR_STOP
	CLRF	CCPR1L
	BCF		PB1
	BCF		PB2
	RETURN

MOTOR_LEFT
	BSF		PB1
	BCF		PB2
	RETURN

MOTOR_RIGHT
	BCF		PB1
	BSF		PB2
	RETURN

HALF_SPEED
	MOVLW	D'125'
	MOVWF	CCPR1L
	RETURN	

HIGH_SPEED
	MOVLW	D'255'
	MOVWF	CCPR1L
	RETURN

SETUP_PWM_1
	BSF		STATUS, RP0		
	MOVLW	D'255'			
	MOVWF	PR2			
	BCF		TRISB, 3		
	BCF		STATUS, RP0		
	MOVLW	B'00000110' 	
	MOVWF	T2CON			
	MOVLW	B'00001100'	
	MOVWF	CCP1CON				 
	RETURN	
		
SETUP
	CLRF	PORTB
	BSF		STATUS, RP0
	CLRF	TRISB
	BCF		STATUS, RP0
	RETURN
END
the image

 

Attachments

Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top