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.

lcd(16x2) on 4 bits on PIC16F72 in assembly- lcd not working

Status
Not open for further replies.

navneet_2040

Newbie level 3
Joined
Dec 8, 2008
Messages
4
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,397
lcd d4-d7 portb assembler download

i am trying to run my lcd(16x2) on 4 bits on PIC16F72 in assembly.
but i am not getting any display on lcd.
i am using portb lower 4 bits to send data on 4 higher bits of lcd,
please give me code.
 

code is with comments now..it can be understood by anyone no

;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PICmicro PIC16F72. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: lcd.asm *
; Date: 9-12-08 *
; File Version: *
; *
; Author: Navneet Kumar *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************


list p=16f72 ; list directive to define processor
#include <p16f72.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDTEN_OFF & _BODEN_OFF & _PWRTEN_ON & _RC_OSC

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






;***** VARIABLE DEFINITIONS
w_temp EQU 0x20 ; variable used for context saving
w_temp1 EQU 0xA0 ; reserve bank1 equivalent of w_temp
status_temp EQU 0x21 ; variable used for context saving







;**********************************************************************
ORG 0x000 ; processor reset vector

goto main ; go to beginning of program


ORG 0x004 ; interrupt vector location

movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
movwf status_temp ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


bcf STATUS,RP0 ; ensure file register bank set to 0
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt




main

; remaining code goes here, main code is starting from here, 16x2 lcd


bsf STATUS,RP0 ; we select bank1 to put values in TRIS registers
movlw 0x00
movwf TRISB ; setting portb as output, b0 to b3 are connected to lcd data pins d4-d7
movlw 0x00
movwf TRISC ; setting portc as output
; RS is at PORtC,6
; EN is at PORTC,7
; R/W pin is at ground,so i am not using it


start:
bcf STATUS,RP0 ; we come in bank0 again


movlw 0x28 ; 28 is we want to send to lcd pin for 4 bit initialization
movwf 0x23 ; 0x23 is the memory location we use to store the data
call command1 ; the data on 0x23 is sent to lcd as command

call delay ; we call delay

movlw 0x01 ; 01 is we want to send to lcd
movwf 0x23 ; 0x23 is the memory location we use to store the data
call command1 ; the data on 0x23 is sent to lcd as command

call delay

movlw 0x0c ; 0c is we want to send to lcd
movwf 0x23 ; 0x23 is the memory location we use to store the data
call command1 ; the data on 0x23 is sent to lcd as command

call delay

movlw 0x80 ; 80 is we want to send to lcd,as starting address
movwf 0x23 ; 0x23 is the memory location we use to store the data
call command1 ; the data on 0x23 is sent to lcd as command

call delay

movlw #"A" ; character A is we want to send to lcd pin for 4 bit initialization
movwf 0x23 ; 0x23 is the memory location we use to store the data
call data1 ; we call data1 now because we are sending data now to lcd

call delay

movlw #"B" ; character B is we want to send to lcd pin for 4 bit initialization
movwf 0x23 ; 0x23 is the memory location we use to store the data
call data1 ; we call data1 now because we are sending data now to lcd

call delay



loop: ; endless loop,after coming here the lcd should show AB characters on display
goto loop



command1:
movlw 0x02 ; 2 is taken into 0x33 memory location for counter to go for 2 times
movwf 0x33

movf PORTB,w ; save to contents of portb to w
andlw 0xf0 ; mask upper 4 bits as we use lower 4 bits to send data on lcd
movwf 0x24 ; save that value to memory location 0x24


s1:
movf 0x23,w ; now put the value in 0x23 to w
andlw 0xf0 ; save the higher 4 bits,put in w,data in 0x23 reamins unchanged
movwf 0x29 ; put it in memory location 0x29
swapf 0x29,w ; swap it and put it in w
iorwf 0x24,w ; now OR it with the upper higher bits we saved of portb
movwf PORTB ; put that on portb, so lower 4 bits of portb have higher nibble of data
bcf PORTC,6 ; RS is cleared as to show that it is command
bsf PORTC,7 ; EN is set
call delay
call delay
bcf PORTC,7 ; EN is cleared
call delay
swapf 0x23,F ; now we get lower nibble of data
decf 0x33,F ; count is decremented
btfss STATUS,Z ; we check the count
goto s1 ; we go again to s1 and send the lower nibble of data on portb as we did for higher nibble
return


data1:
movlw 0x02 ; same as command1 , here RS is set high,other logic is same as command1
movwf 0x33

movf PORTB,w
andlw 0xf0
movwf 0x24
g1:
movf 0x23,w
andlw 0xf0
movwf 0x29
swapf 0x29,w
iorwf 0x24,w
movwf PORTB
bsf PORTC,6
bsf PORTC,7
call delay
call delay
bcf PORTC,7
call delay
swapf 0x23,F
decf 0x33,F
btfss STATUS,Z
goto g1
return

delay: ; this delay is enough that the lcd requires

movlw 0x0d
movwf 0x21

here:
decf 0x21,F
btfss STATUS,Z
goto here1
goto end1
here1:
movlw 0x0f
movwf 0x20
go1:
decf 0x20,F
btfss STATUS,Z
goto go1
goto here
end1: nop
return
END
 
Re: lcd not working

Hi Navneet,
Understanding someone else's code is as tough as reading other's mind. Your code lacks comments and others may not like to invest lot of thier valuable time to understand your code and help you.

A few posts down your post there is an identical post. He is also having your same problem, but see the clarity of his coding. There are some suggestions given there, but no confirmation yet as to whether he has solved his problem. Those comments are also applicable to your case. So please have a look at the post below and most likely you will be able to help yourselves.

The post reference is :


Regards,
Laktronics
 

my code

you are right ..that my code is difficult to understand for others as i have not given any comments.. so i am going to include as many comments as possible so that the person who reads it will understand it easily... i will post the new code very soon.. thanx.
 

Re: my code

u told that u r using lcd in 4 bit mode. ok once see lcd command 0x28. ie 0x28 is to set lcd in 4 bit mode so first send upper nibble and then lower nibble.
0x28= 0 0 1 0 1 0 0 0
bit positions are 7 6 5 4 3 2 1 0 in ur microcontroller data bits r b3 to b0. so first right shift ur higher nibble 4 times and send to lcd and send lower nibble without shifting
 

Re: lcd d4-d7 portb assembler download

Hy,
what ever u done that is incorrect.
you can use only 4 lines of lcd with microcontroller to send data as well as command.
To define data/command is done by RS pin of LCD.
here I give u a sample code for this.

Thanks.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top