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.

[PIC] Initialization of P18F4520

Status
Not open for further replies.

dsnarindra

Newbie level 4
Joined
Jan 21, 2016
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
48
Hi,
I am new for PIC(P18f4520) architecture, So, my problem is that i am unable to understand how to configure the controller for the purpose of i/o operation basically used for 2*16 lcd display.
I am used p18f54520 with external frequency 20Mhz.
 

Hi,

Sorry, but we can´t see how the display is connected...
I2C, SPI, parallel 4 bit mode, parallel, 8 bit mode, memory mapped, bit bang mode?

Usually you need to connect some pins of the display with some pins of the microcontroller. Tell us exactely how you did it.

It´s very common to connect a display to a PIC. So i am very sure that you will find software where you can see how others did it.
Then try to do the same with your software.
Test it. If something does not work, then give a detailed error descroption, your code and your schematic..
And some additional information, like what compiler / language you are using.

Then we will have the chance to help you.

Klaus
 

Dear
KlausST
I am sorry to give that information.
The lcd is connected parallel with p18f4520 as details given below.
Data- PORTB
Rs-RD6
EN- RD7
RW- GND
Code:
#INCLUDE	p18F4520.inc
R1		EQU		81H
R2		EQU		82H

LCD_DATA	EQU		PORTB
LCD_CTRL	EQU		PORTD

RS		EQU		RD6
EN		EQU		RD7
	
		ORG		00H
CALL		LDELAY
		CALL		LDELAY
		CALL		LDELAY
		CALL		LDELAY
		NOP
		NOP
		CLRF PORTB 
		CLRF LATB 
		MOVLW 0Fh
		MOVWF ADCON1
		MOVLW 0x00 
		MOVWF TRISB 
		CLRF PORTD 
		CLRF LATD
		MOVLW 0x00
		MOVWF TRISD 
               BCF		LCD_CTRL,EN
		NOP
		CALL		LDELAY
             MOVLW	0x38
		CALL		COMMAND
		CALL		LDELAY
		CALL		LDELAY
		CALL		LDELAY
		CALL		LDELAY
		MOVLW		0x0E
		CALL		COMMAND
		CALL		LDELAY
		CALL		LDELAY
		MOVLW		0x001
		CALL		COMMAND
		CALL		LDELAY
		CALL		LDELAY
		MOVLW		0x06
		CALL		COMMAND
		CALL		LDELAY
		CALL		LDELAY
		MOVLW		0x86
		CALL		COMMAND
		CALL		LDELAY
		CALL		LDELAY
		MOVLW		 A'G'
		NOP
		CALL		DATA_DISPLAY
		CALL		LDELAY
		CALL		LDELAY
		MOVLW	 A'S'
		NOP
		CALL		DATA_DISPLAY
		CALL		LDELAY
		CALL		LDELAY
	
HERE	BRA		HERE
;-----------------------------------------------------------------------------
COMMAND	
		NOP
		NOP
		MOVWF 		 LCD_DATA
		
		BCF		LCD_CTRL,RS
		;BCF		LCD_CTRL,RW
		BSF		LCD_CTRL,EN
		CALL		SDELAY
		CALL		LDELAY
		BCF		LCD_CTRL,EN
		NOP
		RETURN
;------------------------------------------------------------------------------

DATA_DISPLAY	
		NOP
		NOP
		MOVWF		LCD_DATA
		BSF		LCD_CTRL,RS
		;BCF		LCD_CTRL,RW
		BSF		LCD_CTRL,EN
		CALL		SDELAY
		CALL		LDELAY
		BCF		LCD_CTRL,EN
		NOP
		RETURN
;-------------------------------------------------------------------------------

;-------------------------------------------------------------------------------	
LDELAY		MOVLW		D'200'
		MOVWF		R1
D1		MOVLW		D'200'
		MOVWF		R2
D2		NOP
		NOP
		DECF		R2,F
		BNZ		D2
		DECF		R1,F
		BNZ		D1
		RETURN
;--------------------------------------------------------------------------------
SDELAY		MOVLW		D'50'
		MOVWF		R1
D4		MOVLW		D'50'
		MOVWF		R2
D3		DECF		R2,F
		BNZ		D3
		DECF		R1,F
		BNZ		D4
		RETURN
;----------------------------------------------------------------------------------


		END
 

You should be writing to the LAT register and not the PORT to avoid RMW problems.
Also PIC devices do have a bit of a learning curve and they are not the simplest things to get set up. However once you know how to do this then they are very easy to use.
For example, the CONFIG settings are critical and you do need to spend some time getting to understand that they configure the device at power-up and also can affect other parts of the operation. You also should spend a bit of time understanding how to configure the oscillator to make sure that the device is running at the speed you think it is.
Personally I recommend that you start with the simple "flash a LED" program which will make sure that all of the above is sorted out and the LED is flashing at the rate you expect. Once you have that going, then you can add in the LCD code knowing that the fundamentals are working.
The timing when initialising many LCDs is important and if the various delay functions you have written do not 'delay' as you expect then the LCD initlisation may not be effective.
Susan
 

can you suggest me some document regarding PIC18F4520 configuration.
 

Is there some reason you are using assembler in preference to a high level language?

If your concern is speed or efficiency a modern compiler will do almost as good a job
as hand crafted assembler - with all the advantages and still allow you to fine tune if you
need to.
If you used the "official" toolchain from microchip or (my own preference) Mikroe C
you would benefit from a good IDE and vast quantities of help and documentation.
The IDE then makes configuring much easier.





If you used the "official" toolchain
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top