Welcome! Log In Create A New Profile

Advanced

BV4618

Posted by geoffers 
BV4618
December 09, 2013 10:05AM
Hi all,
I've got a bv4618 on the i2c bus of my 18f2523, got the display working no problem, the keypad has been tricky (I was sending a ack rarther than a nack!) However now I have it reading the number of presses no problem. (send 0x62 0x1b 0x10 then read).

However if I send 0x62 0x1b 0x11 and then read the keypad scan code it always comes back as FF no matter which button is pressed?! I've tried resetting the bv4618 but it makes no difference?
Any clues?
Thanks Geoff
Re: BV4618
December 09, 2013 05:03PM
Geoff,
you may have abbreviated the question so I will spell it out in case something is missed. Using I2C, you need to send a command and then read back the information sent by the BV4618, so to get the key scan code of the key pressed would be:

* send start condition
* send address 0x62
* send 0x1b
* send 0x11
* send stop condition
* send start with address 0x63 << read address
* read one byte
* send stop condition

The above on some systems are wrapped up in higher level statement but the fact is if that above is followed then it will return the key code. If you have got this and still no joy then I would re-look at the logic or even the key pad - is it connected to the correct pins - columns should short out rows.

The bv4618 will return 0 when there has been no key pressed for both command 0x10 and 0x11

Jim
Re: BV4618
December 11, 2013 09:56PM
Hi Jim,

Thanks for getting back to me so quickly, I'm afraid to say it was a typo, my fault,sorry! a movlw where there should be a movwf agggh! As a penace I've copied and pasted a bit of my programme, the nack stuck me for a bit, hope its help for someone!

;*******************Start bit subroutine**************************
;           This routine generates a Start condition
;           (high-to-low transition of SDA while SCL
;           is still high.
;*****************************************************************
BSTART
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    bsf     SSPCON2,SEN         ; Generate Start condition
bstart_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    bra     bstart_wait         ; If not, keep checking

    return

;*******************Restart bit subroutine**************************
;           This routine generates a Repeated Start
;           condition (high-to-low transition of SDA
;           while SCL is still high.
;*****************************************************************
BRESTART
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    bsf     SSPCON2,RSEN        ; Generate Restart condition
brestart_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    bra     brestart_wait       ; If not, keep checking

    return

;*******************Stop bit subroutine***************************
;           This routine generates a Stop condition
;           (low-to-high transition of SDA while SCL
;           is still high.
;*****************************************************************
BSTOP
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    bsf     SSPCON2,PEN         ; Generate Stop condition
bstop_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    bra     bstop_wait          ; If not, keep checking

    return



TX_BYTE
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    movf    datao,W             ; Copy datao to WREG
    movwf   SSPBUF              ; Write byte out to device
tx_wait

    btfss   PIR1,SSPIF          ; Check if operation completed
    bra     tx_wait             ; If not, keep checking  

    return
    
;-----------------------------------------------------------------
    
    
RX_BYTE
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
    bsf     SSPCON2,RCEN        ; Initiate reception of byte
rx_wait
    btfss   PIR1,SSPIF          ; Check if operation completed
    bra     rx_wait             ; If not, keep checking
    movf    SSPBUF,W            ; Copy byte to WREG
    movwf   datai               ; Copy WREG to datai
    bcf     PIR1,SSPIF          ; Clear SSP interrupt flag
	BSF		SSPCON2,ACKDT		;GENERATE NACK
    bsf     SSPCON2,ACKEN       ; Generate ACK/NO ACK bit   
rx_wait2
    btfss   PIR1,SSPIF          ; Check if operation completed
    bra     rx_wait2            ; If not, keep checking

    return
    
;--------------------------------------------------------------------

;I2C DISPLAY ROUTINE TEST BV4168

		;I2C DISPLAY TEST

		BSF		PORTC,2
		BCF		PORTC,5
		
		CALL	DBNC
		CALL	DBNC
		CALL	DBNC
		CALL	DBNC
		CALL	DBNC
		CALL	DBNC
		CALL	DBNC

		CALL	BSTART

		MOVLW	LCD			;LCD ADRESS
		MOVWF	datao
		CALL	TX_BYTE		;WAKE IT UP

		MOVLW	0X1B
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	0X30		;set number of lines to four
		MOVWF	datao
		CALL	TX_BYTE


		MOVLW	0X04		;TO FOUR
		MOVWF	datao
		CALL	TX_BYTE

		CALL	BSTOP

		CALL	BSTART

		MOVLW	LCD			;LCD ADRESS
		MOVWF	datao
		CALL	TX_BYTE		;WAKE IT UP


		MOVLW	0X1B		;LCD ADRESS
		MOVWF	datao
		CALL	TX_BYTE		;WAKE IT UP

		MOVLW	0X31		;NUMBER OF CHARACTERS
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	.20			;SET TO 20
		MOVWF	datao
		CALL	TX_BYTE
		
		CALL	BSTOP

		CALL	BSTART

		MOVLW	LCD			;LCD ADRESS
		MOVWF	datao
		CALL	TX_BYTE		;WAKE IT UP

		MOVLW	0X1B
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	0X01
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	0X01		;clear screen
		MOVWF	datao
		CALL	TX_BYTE

		CALL	BSTOP

		CALL	BSTART

		MOVLW	LCD			;LCD ADRESS
		MOVWF	datao
		CALL	TX_BYTE		;WAKE IT UP


		MOVLW	0X1B		;LCD ADRESS
		MOVWF	datao
		CALL	TX_BYTE		;WAKE IT UP

		MOVLW	0X25		;HOME CURSOR
		MOVWF	datao
		CALL	TX_BYTE

		CALL	BSTOP

		CALL	BSTART
		
		MOVLW	LCD
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	'H'
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	'E'
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	'L'
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	'L'
		MOVWF	datao
		CALL	TX_BYTE

		MOVLW	'O'
		MOVWF	datao
		CALL	TX_BYTE

		CALL	BSTOP

This is for a pic18f2523, using the onboard i2c module


Cheers Geoff



Edited 1 time(s). Last edit at 12/12/2013 09:47AM by jimeer.
Re: BV4618
December 12, 2013 09:52AM
Thanks for the post.
One of the reasons I don't use assembler any more but the main one is going back to the code after a few months, i.e maintenance.
Jim
Sorry, only registered users may post in this forum.

Click here to login