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 to PIC16f877 in assembly

Status
Not open for further replies.

budimanc

Newbie level 5
Joined
Mar 8, 2010
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Indonesia
Activity points
1,397
Hi, i had some problem with my program, when i compile its seems ok.
But when i tried simulate it in hardware simulation using proteus, the text doesnt appear. I'm using Port B as data dan Port A to control. Can you please check it.
The program is

Code:
;
 LIST P=16f877, c=100, n=55, st= OFF     ; pilih tipe prosesor
 include "p16f877.inc"  ; sertakan file penetapan nama-nama register
;	
Enbl 	equ 	0
RSel 	equ 	1
RW	 	equ 	2
RBPU 	equ 	7
lcdram1	equ	0x80 	; alamat DDRAM baris 1
temp 	equ 10h
	cblock 0x20
		tundacch,tundac5,karcch,index
		disp1:16 		; buffer tampilan brs 1 
		bufptr 		; pointer alamat buffer tampilan 
		lcdram 		; variabel untuk alamat DDRAM  
	endc
;
	org 	0x00	; awal program reset
	nop
   	goto 	start
;
;*******************************************************
;Rutin menginisialisasi PortA dan PortB.
InitPort:
 	bcf 	STATUS,RP1 	;
 	bcf 	STATUS,RP0 	;select bank0
 	clrf 	PORTA 	;buat semua Port_A rendah
 	bsf 	STATUS,RP0 	;select bank1
 	movlw 	B'00000110' 	;setel Port_A sebagai digital I/O 
 	movwf 	ADCON1 	;saat power-on reset port_A ana inputs
	clrf 	TRISA 	;buat semua Port_A output
	movlw 	B'00000000' 	;PORTB all outputs
 	movwf 	TRISB 	;
	bcf 	STATUS,RP0 	;select bank0
    	return
;***************************************************
;menerbitkan tundaan 1 mdet (1000 siklus) termasuk call
tunda1ms: 	movlw	d'199'	;
 	movwf	tundacch	;
tnd11:	nop
	nop	
	decfsz	tundacch,f	;
	goto 	tnd11	; lup 199*5
 	return
;***************************************************
;menerbitkan tundaan 5 mdet menggunakan tunda1ms
tunda5ms:
 	movlw	d'5'	;
 	movwf	tundac5	;
tnd15:	call	tunda1ms
	decfsz	tundac5,f	;
	goto 	tnd15	;  
 	return		;
;***************************************************


;menerbitkan pulsa Enable LCD
aktif_E:			;
	bsf  	PORTA,Enbl  	;bawa E ke logika 1
	nop  	  	;tunggu sesaat
	bcf  	PORTA,Enbl  	; kembalikan E ke 0
    	call 	tunda1ms   	; tunggu selama 1 mdet
    	return
;
;***********************************************
; menginisialisasi LCD
initlcd:
; modus komando
 	bcf 	PORTA,Enbl 	;bawa Enable ke rendah 
 	bcf 	PORTA,RSel 	;pilih reg Instr, RS=0
 	bcf 	PORTA,RW 	;pilih modus tulis RW=0
	call 	tunda1ms	;beri waktu bagi kontroler LCD utk init
;Function Set	
	movlw 	0x38
	movwf  	PORTB  
	call 	aktif_E  	; aktifkan Enable, beri waktu bagi kontroler
;Display OFF	
	movlw 	0x08	; kode mematikan tampilan, kursor dan kedip
	movwf  	PORTB  
	call 	aktif_E  	; aktifkan Enable, beri waktu bagi kontroler
;Display and Cursor ON	
	movlw 	0x0E	; kode hidupkan tampilan & kursor tanpa kedip
	movwf  	PORTB  	; 0000 1110
	call 	aktif_E  	; aktifkan Enable dan beri waktu bagi kontroler
;Entry Mode Set	
	movlw 	0x06	; kode tampilan diam - kursor bergerak kanan
	movwf  	PORTB  	; 0000 0110
	call 	aktif_E  	; aktifkan Enable dan beri waktu bagi kontroler
;Cursor/Display Shift
	movlw 	0x14	; kode tampilan diam - kursor bergerak kanan
	movwf  	PORTB  	; 0001 0100
	call 	aktif_E  	; aktifkan Enable dan beri waktu kontroler 
;Clear Display
	movlw 	0x01	; kode untuk membersihkan tampilan
	movwf  	PORTB  	; 0001 0001
	call 	aktif_E  	; aktifkan Enable dan beri waktu bagi kontroler
	Return
;
;**************************************
;mengisi buffer tampilan dengan blank
kosongbuf
	movlw 	D'16' 	; Set up counter
	movwf 	karcch
	movf 	bufptr,w 	; First PIC RAM address
	movwf 	FSR 	; Indexed addressing
	movlw 	0x20 	; kar spasi ASCII 
simpan:
	movwf 	INDF 	; Store blank character in PIC RAM
	decfsz 	karcch,f 	; Done?
	goto 	almtbrkt	; no
	return 		; yes
almtbrkt:	incf 	FSR,f 	; Bump FSR to next buffer space
	goto 	simpan
;
;*****************************************
; Rutin pengiriman teks dari buffer ke LCD
tampilcd:
	bcf 	PORTA,Enbl 	; E line low
	bsf 	PORTA,RSel 	; RS line low for control
	call 	tunda1ms 	; Delay
	movlw 	D'16' 	; pencacah karakter
	movwf 	karcch
; Get display address from local variable pic_ad
	movf 	bufptr,w 	; alamat awal buffer teks
	movwf 	FSR 			; 
getkar:
	movf 	INDF,w 	; ambil karakter dari buffer
	movwf 	PORTB
	call 	aktif_E 	;kirimkan ke LCD
	decfsz 	karcch,f 	; turunkan pencacah
	goto 	karbrkt 	; sampai habis
	return
karbrkt:	incf 	FSR,f                   ; Bump pointer
	goto 	getkar
;
;**********************************************
; Memilih alamat DDRAM untuk baris tampilan LCD
; alamat buffer ada di variabel lcdram
baristpl:
	bcf 	PORTA,Enbl 	; aktifkan E (E= 0)
	bcf 	PORTA,RSel 	; pilih IR (RS= 0)
	call 	tunda1ms 	; tunggu 1 ms
; pilih alamat pertama baris 
	movf	lcdram,w	; alamat dan bit komando
	movwf 	PORTB
	call 	aktif_E 	; Pulse and delay
; pilih reg data DR
	bsf 	PORTA,RSel 	; pilih reg data (RS= 1)
	call 	tunda1ms 	; tunggu 1 ms
	return
;
;***********************************************************
; Subrutin membawa teks pesan dari mem program ke buffer RAM 
; input: bufptr= alamat buffer
; 		 w= offset di buffer
; local: psn1= rutin pencatu pesan dengan 0 sbg terminator
; 		index= variabel indeks tabel
bawapsn1:
	movwf 	index 	; atur indeks buffer 
	movf 	bufptr,w 	; 
	addwf 	index,w 	; 
	movwf 	FSR 	; muat ke FSR
; mulai pembacaan tekes dari indeks ke 0
	movlw 	0 			; 
	movwf 	index 	; awali index dengan 0
ambilkar:		; w digunakan sepagai penunjuk
	call psn1 		; ambil karakter dari tabel
	andlw 	0x0ff	; Test apakah 0 (terminator)
	btfsc 	STATUS,Z 	; Test zero flag
	goto 	endpsn1 	; End of string
; simpan karakter di w ke buffer 
	movwf 	INDF 	; buffer ditunjuk FSR
	incf 	FSR,f 	; arahkan ke buffer berikut
;  
	movf 	index,w 	; naikkan indeks dan muat ke w
	addlw 	1 	; untuk karakter berikutnya
	movwf 	index 	; 
	goto 	ambilkar 	; ulangi
endpsn1: 	return
; Rutin membawa teks pesan brs-1 dari mem program ke buffer di file reg
psn1:	addwf 	PCL,f 	; ambil elemen ke-w
	retlw 	' '
	retlw 	' '
	retlw 	' '
	retlw 	' '
	retlw 	'E'
	retlw 	'm'
	retlw 	'b'
	retlw 	'e'
	retlw 	'd'
	retlw 	'd'
	retlw 	'e'
	retlw 	'd'
	retlw 	' '
	retlw 	' '
	retlw 	' '
	retlw 	' '
	retlw 	 0

start:
   	call 	InitPort 	;initialize port B
 
	call 	tunda1ms
	call 	initlcd
	call 	tunda5ms	;beri waktu untuk lcd untuk initialisasi  
; Simpan alamat awal buffer teks tampilan PIC
	movlw 	disp1 	; alamat awal buffer teks tampilan PIC
	movwf 	bufptr 	; muat ke variabel penunjuk
;awali buffer tampilan blank
	call 	kosongbuf  	;kosongkan buffer tampilan PIC
;
; Bawa teks ASCII ke buffer tampilan di PIC
	movlw 	d'1' 	; Offset tampilan
	call 	bawapsn1	; pindahkan teks ke buffer
; Setel alamat DDRAM untuk baris-1
	movlw	lcdram1	; tunjuk alamat DDRAM baris-1
	movwf	lcdram 	
	call 	baristpl	;setel alamat DDRAM
	call 	tampilcd	;tampilkan teks
; 

loop: goto 	loop
;
End
[/code]
 

Hi,

It might be easier to check your proteus .dsn first as the fault may be in that - can you post it together with the .hex file.
 

    budimanc

    Points: 2
    Helpful Answer Positive Rating
eh i just got the solution, i just having a small mistakes in my proteus.
Now i'm trying to generate text in lcd using cgram, but i dont know how.
can you please modify this above program using cgram just to show A word using CGRAM not DDRAM
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top