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.

Picdem2 lcd problem help

Status
Not open for further replies.

Ilia Gildin

Junior Member level 3
Joined
Sep 27, 2014
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
184
hello
i have writen the following code
Code:
;******************************************************************************
;                                                                             *
;   This file is a basic code template for code generation on the             *
;   PIC18F46K22. This file contains the basic code building blocks to build   *
;   upon.                                                                     *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on features    *
;   of the assembler.                                                         *
;                                                                             *
;   Refer to the respective data sheet for additional information on the      *
;   instruction set.                                                          *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:         xxx.asm                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required:                                                          *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Notes:                                                                   *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Revision History:                                                        *
;                                                                             *
;******************************************************************************

;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------

     LIST      P=PIC18F46K22          ; list directive to define processor
     #INCLUDE <P18F46K22.INC>         ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the 
; .asm file. The lables following the directive are located in the respective 
; .inc file.  See the data sheet for additional information on configuration 
; word settings.
;
;------------------------------------------------------------------------------

     ;Setup CONFIG11H
     CONFIG  FOSC = INTIO67, PLLCFG = OFF, PRICLKEN = OFF, FCMEN = OFF, IESO = OFF
     ;Setup CONFIG2L
     CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
     ;Setup CONFIG2H
     CONFIG WDTEN = OFF, WDTPS = 1
     ;Setup CONFIG3H
     CONFIG MCLRE = EXTMCLR, CCP2MX = PORTC1, CCP3MX = PORTE0, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTC0
     ;Setup CONFIG4L
     CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
     ;Setup CONFIG5L
     CONFIG CP0 = OFF, CP1 = OFF, CP2=OFF, CP3=OFF
     ;Setup CONFIG5H
     CONFIG CPB = OFF, CPD = OFF
     ;Setup CONFIG6L
     CONFIG WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
     ;Setup CONFIG6H
     CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
     ;Setup CONFIG7L
     CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
     ;Setup CONFIG7H
     CONFIG EBTRB = OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Refer to datasheet for available data memory (RAM) organization
;
;------------------------------------------------------------------------------

    CBLOCK 0x60 ; Sample GPR variable register allocations
        MYVAR1  ; user variable at address 0x60
        MYVAR2  ; user variable at address 0x61
        MYVAR3  ; user variable at address 0x62
    ENDC

W_TEMP         EQU        0x000  ; w register for context saving (ACCESS)
STATUS_TEMP    EQU        0x001  ; status used for context saving 
BSR_TEMP       EQU        0x002  ; bank select used for ISR context saving

#define LCD_RS	PORTD,RD4			; LCD RS bit
#define LCD_RW	PORTD,RD5			; LCD R/W bit
#define LCD_EN	PORTD,RD6			; LCD Enable bit

LCD_PORT	equ		PORTD			; LCD Interface PORT

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 18F46K22 has 256 bytes of non-volatile EEPROM starting at 0xF00000
; 
;------------------------------------------------------------------------------

DATAEE    ORG  0xF00000 ; Starting address for EEPROM for 18F46K22

    DE    "MCHP"        ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RES_VECT  ORG     0x0000            ; processor reset vector
          GOTO    START             ; go to beginning of program

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRH      ORG     0x0008

          ; Run the High Priority Interrupt Service Routine
          GOTO    HIGH_ISR             

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRL      ORG     0x0018
          
          ; Run the High Priority Interrupt Service Routine
          GOTO    LOW_ISR             

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

HIGH_ISR  

          ; Insert High Priority ISR Here

          RETFIE  FAST

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

LOW_ISR
          ; Context Saving for Low ISR
          MOVWF   W_TEMP              ; save W register
          MOVFF   STATUS, STATUS_TEMP ; save status register
          MOVFF   BSR, BSR_TEMP       ; save bankselect register

          ; Insert Low Priority ISR Here

          ; Context Saving for Low ISR
          MOVFF   BSR_TEMP, BSR       ; restore bankselect register
          MOVF    W_TEMP, W           ; restore W register
          MOVFF   STATUS_TEMP, STATUS ; restore status register
          RETFIE

;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START
	CLRF TRISD
	Clrf ANSELD
d1     EQU 0x80
d2     EQU 0x81
d3     EQU 0x82		
LCD_DATA    EQU 0x83
	BSF 	PORTD,RD7 ;power on		
	call	delay_45ms
	bSf 	LCD_EN ; enable for write to lcd
	NOP
	NOP	
	bcf 	LCD_RS
	bcf		LCD_RW
	movlw 	B'00100000';FUNCTION SET 1
	movwf 	LCD_DATA
	swapf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN ; enable for write to lcd	
	call	delay_5ms
	bsf 	LCD_EN ; enable for write to lcd	
	nop
	nop
	bcf 	LCD_RS
	bcf		LCD_RW
	movlw 	B'00101000';FUNCTION SET 2
	movwf	LCD_DATA
	swapf	LCD_DATA,F
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN ; enable for write to lcd
	call	delay_200us
	bsf 	LCD_EN ; enable for write to lcd	
	nop
	nop
	bcf 	LCD_RS
	bcf		LCD_RW
	swapf	LCD_DATA,F;entry2 continue
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN	; enable for write to lcd	
	call	delay_5ms
	bsf 	LCD_EN	; enable for write to lcd	
	nop
	nop
	bcf 	LCD_RS
	bcf		LCD_RW
	movlw 	B'00001110' ;display on/off
	movwf	LCD_DATA
	swapf	LCD_DATA,F
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN	; enable for write to lcd	
	call	delay_200us
	bsf 	LCD_EN ; enable for write to lcd	
	nop
	nop
	bcf 	LCD_RS
	bcf		LCD_RW
	swapf	LCD_DATA,f ;display on/off continue
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN ; enable for write to lcd	
	call	delay_5ms
	bsf 	LCD_EN ; enable for write to lcd	
	nop
	nop
	bcf 	LCD_RS
	bcf		LCD_RW
	movlw 	B'00000110' ;entry mode
	movwf	LCD_DATA
	swapf	LCD_DATA,F
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN ; enable for write to lcd		
	call	delay_200us
	bsf 	LCD_EN ; enable for write to lcd	
	nop
	nop
	bcf 	LCD_RS
	bcf		LCD_RW
	swapf	LCD_DATA,F ;entry mode continue
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN ; enable for write to lcd	
	call	delay_5ms	
;end init
;write H
	bsf 	LCD_EN
	bsf 	LCD_RS
	bcf		LCD_RW
	movlw 	B'01001000' ;A'H'
	movwf	LCD_DATA
	swapf	LCD_DATA,F
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN ; enable for write to lcd	
	call	delay_200us
	bsf 	LCD_EN ; enable for write to lcd	
	nop
	nop
	bsf 	LCD_RS
	bcf		LCD_RW
	swapf	LCD_DATA,F ;A'H' continue
	movlw 	0xF0 ;CLEAR LCD DATA
	andwf	PORTD,F
	movlw 	0x0F
	andwf	LCD_DATA,W
	iorwf	PORTD,F
	bcf 	LCD_EN ; enable for write to lcd	
	call	delay_5ms	
	bsf 	PORTD,RD6 ; enable for write to lcd	

delay_45ms	
	movlw D'2'
	movwf d3
op
	movlw D'9'
	movwf d2
ty
	movlw D'208'
	movwf d1
ui
	decfsz d1
	goto ui
	decfsz d2
	goto ty
	decfsz d3
	goto op
	return	

delay_5ms
	movlw D'1'
	movwf d3
op1
	movlw D'2'
	movwf d2
ty1
	movlw D'210'
	movwf d1
ui1
	decfsz d1
	goto ui1
	decfsz d2
	goto ty1
	decfsz d3
	goto op1
	return

delay_200us
	movlw D'1'
	movwf d3
op2
	movlw D'1'
	movwf d2
ty2
	movlw D'13'
	movwf d1
ui2
	decfsz d1
	goto ui2
	decfsz d2
	goto ty2
	decfsz d3
	goto op2
	return
	end
I use the PICDEM2 PLUS black board with the P18F46K22 microcontroller and unfortunately the screen blinks and does not writing 'H'
please help :)
 

What POWER ? Are you Powering the LCD from PIC ?

yes as the schematics of the picdem 2 shows the vcc pin is connected through the n-p-n transistor to RD7
again thank you very much for your help
 

For all output pins you have to use LATx and LATxbits.LATxx.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top