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.

PIC18F452 ASCII string sort to LCD

Status
Not open for further replies.

kgavionics

Full Member level 3
Full Member level 3
Joined
Jun 12, 2012
Messages
167
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Activity points
2,481
Hi guys
I switched to PIC18F family and i'm enjoying very much this family,it has a lot of advantages over PIC16F family.

I wrote a simple program in assembly to display string on LCD:
Code:
;============================================================

	MOVLW 0X0
	MOVWF TBLPTRL ; LOOK UP TABLE LOW BYTE ADRESS
	MOVLW 0X02 
	MOVWF TBLPTRH  ; LOOK UP TABLE HIGH BYTE ADRESS
B7      TBLRD* ;TABLAT POINT TOWARD THE FIRST STRING 
	MOVF TABLAT,W ; COPY CHAR TO W
	BZ EXIT
	CALL dataw ;dataw is the function to send chars to LCD
	INCF TBLPTRL,F
	BRA B7
EXIT GOTO EXIT

ORG 0X200
MYDATA  DB "DISPLAY A STRING OF CHARS ON MY LCD*** BY Kgavionics**** " ,0
END
;============================================================
end ; END OF PROGRAM
;============================================================

the program is working, but there's a little issue, because there's no way to tell the LCD to write the first 16 chars on the first lines and to return to second line to write the remains chars using the command (0XC0 on HD44780).
Basically, can someone help me to write a function that count for 16 chars and display them on the first line and to write the remaining chars on the second line.i have a long solution by coping all string to RAM using indirect mode and then declare a counter to count chars,but i want to see if i can do it simpler than this.
thank you in advance
 

Use a counter and increment it after each character is printed. Then check everytime if counter is greater or equal to 16, if counter >= 16 then print on second line by using 0xC0 + (counter value - 16)

if(counter < 16) (0x80 + counter)
else if(counter >= 16) (0xC0 + (counter - 16))
 

Hi,

These routines might give you some ideas.

Also look at the 18F4520 range of chips, many more better features than the old 452.
 

Attachments

  • 18f_lcd.zip
    4.1 KB · Views: 75
Hi
Thank you guys, especially wp100 for the codes, the examples in attached file are great.
 

HI again
After taking a look to the file provided by wp100, i found that my algorithm not too long comparing it with the wp100 file.

here's my own function that copy the look up table to the RAM then the display routine sort the string to be dispalyed on LCD

Code:
;============================================================
; File name:PIC18F452_LCD_ROUTINE
; Date:
; Author:KGAVIONICS
; Processor:
; Reference circuit:
;============================================================
; Copyright notice:
;============================================================
; Program Description:
;
;===========================
; configuration switches
;===========================
list p=18f452	 	
#include P18F452.INC
	CONFIG WDT=OFF; disable watchdog timer
	CONFIG DEBUG = OFF; Enable Debug Mode
	CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging)
	CONFIG OSC = HS;
;=====================================================
; constant definitions

;=====================================================
;=====================================================
; PIC register equates
pcl  EQU 2
;=====================================================
;=====================================================
; variables in PIC RAM
;=====================================================

	counter1  EQU 01
	counter2   EQU 02
	number    EQU 03
	STCOUNT   EQU 04
;============================================================
; program
;============================================================

org 0X00 ; start at address


goto main



delay
	movlw	0x02
	movwf	counter2
loop1
	movlw	0xff
	movwf	counter1
loop2
 	nop
	decfsz counter1
	goto loop2
	decfsz counter2
	goto loop1
return
delaylong
	movlw	0xff
	movwf	counter2
loop1l
	movlw	0xff
	movwf	counter1
loop2l
 	nop
	decfsz counter1
	goto loop2l
	decfsz counter2
	goto loop1l
return
instw
PIC 	movwf	PORTB
	call delay
	bcf	PORTD,4
	call delay
	bsf	PORTD,5
	call delay
	bcf	PORTD,5
	call	delay
return
dataw
	movwf PORTB
	call delay
	bsf PORTD, 4
	call delay
	bsf PORTD, 5
	call delay
	bcf PORTD, 5 ;Transitional E signal
	call delay
return
DISPLAY
	LFSR 2,0X05
A9 	MOVF INDF2,W
	CALL dataw
	INCF FSR2L
	DECFSZ STCOUNT,F
	BRA A9
	MOVLW 0XC0
	CALL instw
	CALL delay
A10	MOVF INDF2,W
	CALL dataw
	INCF FSR2L
	MOVF INDF2,W
	BNZ A10
	
RETURN
main:
	
	movlw	0x00
	movwf	TRISB
	movwf	TRISD
	clrf	PORTD
	clrf	PORTB
	call delay
	call delay
start
	clrf PORTD ;Here RW is pulled down to ground
;LCD routine starts
	call delay
;give LCD module to reset automatically
;Fundtion for 8-bit, 2-line display, and 5x8 dot matrix

	
	movlw 0x38
	call instw
	call delay
	movlw b'00001000' ; display off, cursor off, blink off
	call instw
	call delay
	movlw b'00001100';display on
	call instw
	call delay
	movlw b'00000001' ; clear display
	call instw
	call delay
	
	movlw b'00000110' ; increment, no display shift
	call instw
	call delay
	MOVLW 0X10
	MOVWF STCOUNT
	LFSR 2,0X05
	LFSR 1,0X05
	MOVLW 0X0
	MOVWF TBLPTRL ; LOOK UP TABLE LOW BYTE ADRESS
	MOVLW 0X02 
	MOVWF TBLPTRH  ; LOOK UP TABLE HIGH BYTE ADRESS
B7      TBLRD* ;TABLAT POINT TOWARD THE FIRST STRING 
	MOVF TABLAT,W ; COPY CHAR TO W
	BZ EXIT
	MOVWF INDF1,0
	INCF  FSR1L,F
	INCF TBLPTRL,F
	BRA B7

EXIT 
CALL DISPLAY
KAIS GOTO KAIS
ORG 0X200
MYDATA  DB "    PIC18F452   ***LCD DEMO***                " ,0
END
;============================================================
end ; END OF PROGRAM
;============================================================
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top