Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Encoder Reading Problem

Status
Not open for further replies.

derser

Member level 1
Member level 1
Joined
Sep 24, 2008
Messages
33
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,502
Hello Friends.
I have to read encoder.I am using pic 18f252
PORTB and INTO,INT1 INT2 interrupt.
The controller goes to interrupt only once.
There is no other interrupts.What have to be the problem?
Bestregards:Barosov
 

Hello Eduardo.This is just a test program.For the first time I test an encoder,
I want to know how it behaves.I also use LCD-HD44780 on PORTC.
But do not pay attention to that.When the controller goes to interrupt, i just reset the flags.
Controller is working on 40Mgz
Code:
PORTA-command LCD,RS,RW,E
PORTB-encoder int0,int1,int2
PORTC LCD
		list		p=18F252
		#include	<p18F252.inc>
	__CONFIG _CONFIG1H,_HSPLL_OSC_1H
	__CONFIG _CONFIG2L,_BOR_OFF_2L
	__CONFIG _CONFIG2H,_WDT_OFF_2H
	__CONFIG _CONFIG4L,_STVR_OFF_4L &_LVP_OFF_4L
;**************************************************
w		equ		1
f		equ		0
;**************************************************
block_var	equ		0x000020
;**************************************************
		cblock		block_var
		flags
		coda_con
		send_con
		p_temp
		w_temp
		s_temp
		bsr_temp
		enc_con1
		enc_con2
		
		last_var
		endc
;***************************************************
#define	RS		PORTA,0
#define	RW		PORTA,1
#define	E		PORTA,2
;***************************************8
#define	line_b		PORTB,1
#define	line_a		PORTB,0
#define	sw_enc		PORTB,2
;****************************************
#define	lcd_ready	flags,0
;****************************************
lcd_line1	equ		0x80
lcd_line2	equ		0xC0
;****************************************
del_10ms	macro
		local		del_loop
		movlw		b'00000001'
		movwf		T0CON
		movlw		0x9E
		movwf		TMR0H
		movlw		0X57
		movwf		TMR0L
		bcf		INTCON,TMR0IF
		clrf		TMR0
		bsf		T0CON,TMR0ON
		;****************
del_loop	btfss		INTCON,TMR0IF
		bra		del_loop
		endm
;*******************************************
del_5ms	macro
		local		del_loop
		movlw		b'00000001'
		movwf		T0CON
		movlw		0xCF
		movwf		TMR0H
		movlw		0X2B
		movwf		TMR0L
		bcf		INTCON,TMR0IF
		clrf		TMR0
		bsf		T0CON,TMR0ON
		;***************
del_loop	btfss		INTCON,TMR0IF
		bra		del_loop
		endm
;*********************************************
coda_del	macro
		local		del_loop
		movlw		.33
		movwf		coda_con
del_loop	decfsz		coda_con
		bra		del_loop
		endm
;*********************************************
		org		0x000000
 		bra		start
		;*****************8
		org		0x000008
		bra		high_int
		;******************
		org		0x000018
		bra		low_int
;*********************************************
high_int	nop
		btfss		INTCON,INT0IF
		call		int0_work
		;*********************
		btfss		INTCON3,INT1IF
		call		int1_work
		;*********************
		btfss		INTCON3,INT2IF
		call		int2_work
		;**********************
		retfie 	FAST
		
int0_work	movf		PORTB
		clrf		PORTB
		bcf		INTCON,INT0IF
		return
		;*********************
int1_work	movf		PORTB
		clrf		PORTB
		bcf		INTCON3,INT1IF
		return
		;**********************
int2_work	movf		PORTB
		clrf		PORTB
		bcf		INTCON3,INT2IF
		return
;********************************************


;********************************************
low_int	movwf		w_temp
		swapf		STATUS,w
		movwf		s_temp
		movf		BSR,WREG
		movwf		bsr_temp
		retfie
;*********************************************
start		lfsr		FSR0,block_var
clr_1		clrf		POSTINC0
		movlw		low	last_var
		cpfseq		FSR0L
		bra		clr_1
clr_2		clrf		POSTINC0
		movlw		high	last_var
		cpfseq		FSR0H
		bra		clr_2
;*********************************************
config_ports	clrf		PORTA
		clrf		LATA
		movlw		b'11111000'
		movwf		TRISA
		movlw		0x07
		movwf		ADCON1
		;********************
		clrf		PORTB
		clrf		LATB
		movlw		.255
		movwf		TRISB
		;*******************
		clrf		PORTC
		clrf		LATC
		clrf		TRISC
;*********************************************
		bcf		INTCON,INT0IF
		bsf		INTCON,INT0IE
		bcf		INTCON2,INTEDG0
		;********************
		bcf		INTCON3,INT1IF
		bsf		INTCON3,INT1IE
		bsf		INTCON3,INT1IP
		bcf		INTCON2,INTEDG1
		;*********************
		bcf		INTCON3,INT2IF
		bsf		INTCON3,INT2IE
		bsf		INTCON3,INT2IP
		bcf		INTCON2,INTEDG2
;**********************************************
		bsf		RCON,IPEN
		bsf		INTCON,GIEH
		bsf		INTCON,GIEL
		bcf		INTCON2,RBPU
;***********************************************
		del_10ms
		;************************
		movlw		b'00111100'
		movwf		PORTC
		coda_del
		call		send
		;************************
		movlw		b'00001110'
		movwf		PORTC
		coda_del
		call		send
		;************************
		movlw		b'00000001'
		movwf		PORTC
		coda_del
		call		send
		;*************************
		del_5ms
		;*************************
		movlw		b'00000110'
		movwf		PORTC
		coda_del
		call		send
		;*************************
		bsf		lcd_ready
;**************************************************
		bra		$


Code:
;*****************************************		
send		bsf		E
		coda_del
		bcf		E
		coda_del
		;******************
		movlw		.83
		movwf		send_con
send_loop	decfsz		send_con
		bra		send_loop
		btfss		lcd_ready
		return
		bcf		RS
		coda_del
		;******************
bf_loop	setf		TRISC
		bsf		RW
		coda_del
		bsf		E
		coda_del
		movf		PORTC,WREG
		movwf		p_temp
		bcf		E
		coda_del
		btfsc		p_temp,7
		bra		bf_loop
		bcf		RW
		coda_del
		clrf		TRISC
		return
;****************************************
		end
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top