Discussion in "PIC Microcontroller Discussion" started by    pappuneelam    May 1, 2011.
Sun May 01 2011, 11:59 am
#1
Halo!

The below mentioned ASM code is for 4 bit LCD display with 16F876A. Using RB0,RB1,RB2 for RS,R/W,E and RC0,1,2,3 for DB4,DB5,DB6,DB7 of LCD.

My problem is that the code is working on OshonSoft simulator with only 'A 0', i.e. where as it should print 'R1'. Moreover, there is a blank space between A and 0. Its taking the MSB of the A first and then taking 0000 in the next sending of LSB.

Also, not getting any display over with PIC16F876A & LCD panel.

I tried in vein, but not geting any solution. Please help me.

PappuNeelam
********
; 4 bit interface with LCD 16x2, using PIC 16F876A
; using PORT B: RB0, RB1 & RB2 as RS, R/W & E line
; using PORT C: RC0, RC0, RC2 RC3 as DB4, DB5, DB6 & DB7 
  
	__CONFIG H'39B1'	; set the configuration word

; ***************** Set up the constants **************************
	
	STATUS 	equ 03h
	TRISA	equ 85h
	TRISB	equ 86h
	TRISC	equ 87h
	PORTA	equ 05h	
	PORTB	equ 06h
	PORTC	equ 07h
	
	COUNT1  equ 20h  	;counter1 for delay loop
	COUNT2  equ 21h  	;counter2 for delay loop
	COUNT3	equ 22h		;counter3 for delay loop
	COUNT4	equ 23h		;counter4 for delay loop
	COUNT5	equ 24h		;counter5 for delay loop
	COUNT6	equ 25h		;counter6 for delay loop
	COUNT7  equ 26h  	;counter2 for delay loop
	COUNT8	equ 27h		;counter3 for delay loop	

; *******Ports setup *******

	org 	00h
	bsf	STATUS,5	; shift to Bank1
	movlw	00h
	movwf	TRISB		; set PortB to output mode
	movlw	00h
	movwf	TRISC
	bcf	STATUS,5	; return to Bank0		

; ******Turn the Port pins *******

	Start
			call	Delay			
			call	Init				

			movlw	05h
			movwf	PORTC
			call	Data_control
			call	Delay1
			movlw	02h
			movwf	PORTC
			call	Data_control
			call	Delay1
			
			movlw	03h
			movwf	PORTC
			call	Data_control
                        movlw	01h
			movwf	PORTC
			call	Data_control


			call	Loop
				
			
; ******** Command & Data Function ********	
	Command_control	
	movlw	04h
	movwf	PORTB	; use RB0,RB1,RB2 for RS,R/W,E
	call	Delay1
	movlw	00h
	movwf	PORTB
	return

; ******** Data Function *********

	Data_control	
	movlw	05h
	movwf	PORTB	; use RB0, RB1, RB2 for RS,R/W,E
	call	Delay1
	movlw	01h
	movwf	PORTB	
	return

;********* Functions Definitions********
Init		
movlw	20h
movwf	PORTC				 
call	Command_control	
call	Delay1
movlw	00h
movwf	PORTC				 
call	Command_control	
call	Delay1
movlw	0Fh
movwf	PORTC				 
call	Command_control	
call	Delay1
return 

;************* Delay subroutine - 4mS interval *****************************
	Delay
	loop1   decfsz	COUNT1,1	; decrease 1 from 255
            goto	loop1    
	loop2	decfsz	COUNT2,1	; decrease 1 from 255
            goto	loop2    
	loop3	decfsz	COUNT3,1	; decrease 1 from 255
            goto	loop3    
	loop4	decfsz	COUNT4,1	; decrease 1 from 255
            goto	loop4   
	loop5	decfsz	COUNT5,1	; decrease 1 from 255
			goto	loop5
	loop6   decfsz	COUNT6,1	; decrease 1 from 255
            goto	loop6    
	loop7	decfsz	COUNT7,1	; decrease 1 from 255
            goto	loop7    
	loop8	decfsz	COUNT8,1	; decrease 1 from 255
            goto	loop8    
			return

;************* Delay1 subroutine - 1.5mS interval *****************************
	Delay1
	loop9   decfsz	COUNT1,1	; decrease 1 from 255
            goto	loop9         
	loop10	decfsz	COUNT2,1	; decrease 1 from 255    
            goto	loop10
			return	
	
	Loop
	loop13	decfsz	COUNT1,1	; decrease 1 from 255    
        goto	loop13
	incfsz	COUNT1,1	; decrease 1 from 255    
        goto	loop13
	return
			
			
	end			; end of the program	 
	  
	

Attachment
Sun May 01 2011, 03:14 pm
#2
Sorry;

Its displaying 'P 0' (not 'A 0'), instead of 'R1'. There is a blank space between P and 0.

PappuNeelam

Mon May 02 2011, 11:05 am
#3
I do not see any data moved to LCD in your program
Mon May 02 2011, 02:28 pm
#4
; ******Turn the Port pins *******

Start
call Delay
call Init

movlw 05h
movwf PORTC
call Data_control
call Delay1
movlw 02h
movwf PORTC
call Data_control
call Delay1

movlw 03h
movwf PORTC
call Data_control
movlw 01h
movwf PORTC
call Data_control


call Loop

************

Through this, i`m getting prints in the LCD of OshonSoft simulator. Inspite of getting 'R1', its displaying 'P--0' & having a two blank spaces between P & 0.

PappuNeelam
Mon May 02 2011, 10:02 pm
#5
try this..
movlw 'R'
;then call lcd function

movlw '1'
;call lcd data function
Tue May 03 2011, 11:10 am
#6
Mr. Ajay,

I tried with your suggestion. But, now its printing nothing, except blanks. Its now taking LSB of R[52]0101 0010 as MSB of Blank space [0010 0000]. And I tried with S[53]0101 0011, but printing is '0'.

I thing, there is some wrong in my ASM code.

Wed May 04 2011, 10:55 pm
#7
can you post your updated code?
Fri May 06 2011, 06:30 pm
#8

; Program for LCD HD44780 display
; Using XT 4Mhz

;****************************************************************

;Declaration and Configuration of the processor
PROCESSOR PIC16F876A
#include <P16F876A.inc>
__CONFIG H'39B1' ; set the configuration word

; ************* Macros & Constants ***********
BANK0 macro
Bcf STATUS,RP0 ;Select memory bank 0
Endm
BANK1 macro
Bsf STATUS,RP0 ;Select memory bank 1
Endm

COUNT1 equ 20h ;counter1 for delay loop
COUNT2 equ 21h ;counter2 for delay loop
COUNT3 equ 22h ;counter3 for delay loop
COUNT4 equ 23h ;counter4 for delay loop
COUNT5 equ 24h ;counter5 for delay loop


; ********* Ports setup ************
ORG 00h
goto Main

Main
BANK1
movlw 00h
movwf TRISB ; set PortB to output mode
movlw 00h
movwf TRISC
BANK0

; *************Sending Data to LCD***************

call Delay
call Init

movlw 'R'
movwf PORTC
call Data_control
call Delay

call Loop

; ************** Command Function *************
Command_control
movlw 04h
movwf PORTB ; use RB0,RB1,RB2 for RS,R/W,E
call Delay1
movlw 00h
movwf PORTB
return

; ************** Data Function ****************
Data_control
movlw 05h
movwf PORTB ; use RB0, RB1, RB2 for RS,R/W,E
call Delay1
movlw 01h
movwf PORTB
return

;************** Initialise Function ************
Init
movlw 20h
movwf PORTC ; Function Set for 4 bits, 2 lines, 5x7 dots
call Command_control
call Delay

movlw 02h
movwf PORTC
call Command_control
call Delay
movlw 00h
movwf PORTC
call Command_control
call Delay
return

;************* Delay subroutine :2mS *****************************
Delay
loop1 decfsz COUNT1,1 ; decrease 1 from 255
goto loop1
loop2 decfsz COUNT2,1 ; decrease 1 from 255
goto loop2
loop3 decfsz COUNT3,1 ; decrease 1 from 255
goto loop3
loop4 decfsz COUNT4,1 ; decrease 1 from 255
goto loop4
return

;************* Delay1 subroutine :1mS ****************
Delay1
loop5 decfsz COUNT1,1 ; decrease 1 from 255
goto loop5
loop6 decfsz COUNT2,1 ; decrease 1 from 255
goto loop6
return

; *********** Hold the Program ******************

Loop
loop7 decfsz COUNT1,1 ; decrease 1 from 255
goto loop7
incfsz COUNT1,1 ; increase 1 to 1
goto loop7
return


end ; end of the program

Sat May 07 2011, 12:26 am
#9
Your 4-bit initialization of LCD is not right. I suggest you to visit tutorial section and read about 4-bit mode of LCD. That will give you a clear idea of where you're doing wrong.
Mon May 09 2011, 05:57 pm
#10
Mr. Ajay,

As per ur suggestion, I changed my Initialisation section for 4 bits. and its now working well on Simulator. But, I haven`t checked on physical devices. I will try on weekends. Thanks a LOT !!!!!!!!

But, no instruction/commeands are working or any effects on the code, like.. 0Fh, 0Eh,01h,C0h.

The 0Fh, 0Eh are need to be in Initialisation subroutine, but no effect.
The 01h,C0h are need after printing any data.


; Program for LCD HD44780 display
; Using XT 4Mhz
; Using PIC16F876A 

;*****************PORT Pins *********************************
; Using RA1,RA2 [PORTA] for RS & R/W pins of LCD
; Using RB0 [PORTB] for E pins of LCD
; Using RC0,RC1,RC2,RC4 for D4,D5,D6 & D7 pins of LCD
;************************************************************
; Declaration and Configuration of the processor
	PROCESSOR PIC16F876A
	#include <P16F876A.inc>
		
	__CONFIG H'39B1'			; set the configuration word

; ************* Macros & Constants ***********
	BANK0 	macro 
			Bcf 	STATUS,RP0 ;Select memory bank 0 
			Endm
	BANK1 	macro 
			Bsf 	STATUS,RP0 ;Select memory bank 1
			Endm
		 
	COUNT1  equ 20h  	;counter1 for delay loop
	COUNT2  equ 21h  	;counter2 for delay loop
	COUNT3	equ	22h		;counter3 for delay loop
	COUNT4	equ	23h		;counter4 for delay loop
	COUNT5	equ	24h		;counter5 for delay loop
	COUNT6  equ 25h  	;counter6 for delay loop
	COUNT7  equ 26h  	;counter7 for delay loop
	COUNT8	equ	27h		;counter8 for delay loop
	COUNT9	equ	28h		;counter9 for delay loop
	COUNT10	equ	29h
		

; ********* Ports setup ************
	ORG 	00h
	goto	Main

Main
	BANK1
	movlw	00h
	movwf	TRISA				; set PortA to output mode
	movlw	00h
	movwf	TRISB				; set PortB to output mode
	movlw	00h
	movwf	TRISC				; set PortC to output mode
	BANK0

; *************Sending Data to LCD***************

	;variable counter = 1

	;call	Loop_Long

	call	Delay				; Power Up the LCD controller
	call	Init				; Initialize the LCD Controller 


	movlw	05h					; Print 'P'
	movwf	PORTC
	call	Data_control
	movlw	00h
	movwf	PORTC
	call	Data_control

	movlw	04h					; Print 'A'
	movwf	PORTC
	call	Data_control
	movlw	01h
	movwf	PORTC
	call	Data_control
	
	movlw	05h					; Print 'P'
	movwf	PORTC
	call	Data_control
	movlw	00h
	movwf	PORTC
	call	Data_control

	call	Sc_Clear			; Clear the LCD Screen
	
	call	Loop			
			
; ************** Command Function *************	
	Command_control	
			movlw	00h
			movwf	PORTA
			movlw	01h
			movwf	PORTB
			call 	Delay2
			movlw	00h
			movwf	PORTB
			return

; ************** Data Function ****************
	Data_control	
			movlw	02h
			movwf	PORTA		; use RB0,RB1 for RS,R/W
			movlw	01h
			movwf	PORTB		; Data of PORTC move to LCD	
			call	Delay2		; Delay of 1.5 mS 
			movlw	00h			
			movwf	PORTB
			movlw	00h
			movwf	PORTA		
			return

;************** Initialise Function ************
	Init
		
		movlw	03h
		movwf	PORTC			 
		call	Command_control
		
		movlw	03h
		movwf	PORTC			 
		call	Command_control
		
		movlw	03h
		movwf	PORTC			 
		call	Command_control
		
		movlw	02h
		movwf	PORTC				; Function Set for 4 bits, 2 lines, 5x7 dots
		call	Command_control	
		call	Delay
		
		movlw	02h					; Entry mode : 4 bits, 2 lines
		movwf	PORTC				 
		call	Command_control	
		call	Delay1	
		movlw	08h
		movwf	PORTC				 
		call	Command_control	
		call	Delay1

		movlw	00h					; Enable Display / Cursor
		movwf	PORTC				 
		call	Command_control	
		call	Delay1	
		movlw	08h
		movwf	PORTC				 
		call	Command_control	
		call	Delay1

		movlw	00h					; Cursor Blink
		movwf	PORTC				 
		call	Command_control	
		call	Delay1	
		movlw	0Eh
		movwf	PORTC				 
		call	Command_control	
		call	Delay1
			
		return 

;************* Delay subroutine :5mS *****************************
	Delay
	loop1   decfsz	COUNT1,1	; decrease 1 from 255
            goto	loop1    
	loop2	decfsz	COUNT2,1	; decrease 1 from 255
            goto	loop2    
	loop3	decfsz	COUNT3,1	; decrease 1 from 255
            goto	loop3    
	loop4	decfsz	COUNT4,1	; decrease 1 from 255
            goto	loop4  
	loop5   decfsz	COUNT5,1	; decrease 1 from 255
            goto	loop5    
	loop6	decfsz	COUNT6,1	; decrease 1 from 255
            goto	loop6    
	loop7	decfsz	COUNT7,1	; decrease 1 from 255
            goto	loop7    
			return

;************* Delay subroutine :1.5mS ****************
	Delay1
	loop9   decfsz	COUNT1,1	; decrease 1 from 255
            goto	loop9 			        
	loop10	decfsz	COUNT2,1	; decrease 1 from 255    
            goto	loop10
			return

;************* Delay Subroutine : 350 uS ***************
	Delay2
			movlw	7Dh
			movwf	COUNT1	
	loop8   decfsz	COUNT1,1	; decrease 1 from 255
            goto	loop8	
			return

; *********** Hold the Program ******************

	Loop
	loop11	decfsz	COUNT1,1	; decrease 1 from 255
			goto	loop11
			incfsz	COUNT1,1	; increase 1 to 1
			goto	loop11
			return

; *********** Clear the screen ******************
	Sc_Clear
		movlw	00h
		movwf	PORTC				 
		call	Command_control	
		call	Delay1	
		movlw	01h
		movwf	PORTC				 
		call	Command_control	
		call	Delay1
		return				
			
		end			; end of the program	 
	  
	

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am