Sida 2 av 2

Postat: 24 februari 2007, 21:34:43
av sodjan
> Vad har 00, som du skickar två gånger med RS på, för funktion då?

Jag kommer inte att försöka förklara (eller förstå!) koden mer än så här.
Jag tror att den ska fungera, men den är inte speciellt snygg och du får
använda det om du vill...

Postat: 25 februari 2007, 09:39:15
av v-g
Gå till icecaps sida ladda ner pdf som han säger på sidan 14 står der sedan TYDLIGT hur du skall göra.

Postat: 25 februari 2007, 13:28:57
av sodjan
Icecap's dokument är naturligtsvis bra och "exakt".
För en beskrivning i lite mer nybörjarformat, se t.ex dessa PFD'er :

http://www.epemag.wimborne.co.uk/lcd1.pdf
http://www.epemag.wimborne.co.uk/lcd2.pdf

Postat: 3 mars 2007, 17:41:01
av eriikh
Efter mycket läsande i dokumenten ni länkade till och lite felsökning i min kod (se %¤&#½!) så har jag nu lyckats få min display att fungera :D

Jävlar vilken enorm känsla jag fick när den började skriva ut tecknen :tårta: :)

Jag lägger ut den färdiga koden här för er andra som vill få igång eran display:

Kod: Markera allt

; LCD Test Program v1.0 made by Erik Henriksson
; This program is ment to run at a PIC16F628A @ 20MHz .
; It can be run at any pic with 8 io-pins if you make some small changes.
; Pinmap is: 
; RB0-3 = D4-7
; RS    = 6
; RW    = 7
; EN    = 5
; The control pins is easy to change. See "Alias declarations".
; If you want to run at 4MHz you have to change the delays to speed the code up. If
; you aren't in a hurry you can drive without any changes.
; 
; Feel free to copy but write my name in your project and send me a mail so I can see
; how popular the code is. =)
; Email address is: eriikh(-at-)hotmail(-dot-)com
; (Change to the real address, the extra characters is only for spam removing.)
;
; Enjoy!
;
;*********************************************
; Start of program
;*********************************************
; CONFIG, INCLUDE & LIST
;*********************************************
	__CONFIG 0x036A 
	INCLUDE p16f628a.inc
	LIST p=16f628A
;*********************************************
; End
;*********************************************
; What to do when reset
;*********************************************
	Org 0x001
	Goto Start
;*********************************************
; End
;*********************************************
; Alias declarations
;*********************************************
ISR		Equ 0x004
En		Equ 5
RS		Equ 6
RW		Equ 7
;*********************************************
; End of Alias declarations
;*********************************************
; Variable declaration
;*********************************************
;Avalible RAM in bank0: 0x0020-0x06F
;
; Delay variables
d1		Equ 0x020
d2		Equ 0x021
d3		Equ 0x022
d4		Equ 0x023
; Lcd variables
Hi_bits	Equ 0x024
Lo_bits	Equ 0x025
tmp 	Equ	0x026

;*********************************************
; End of Variable declaration
;*********************************************
; Timer interrupt
;*********************************************
	Org isr
	Retfie
; Do nothing
;*********************************************
; End of Timer interrupt
;*********************************************
; Subroutines
;*********************************************
Delay_5ms ; Make a delay of exactly 5ms = 25000cykles
			;24993 cycles
	movlw	0x86
	movwf	d1
	movlw	0x14
	movwf	d2
Delay_5ms_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_5ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return

;******

Delay_160us ; Make a delay of exactly 160us = 800cykles
			;793 cycles
	movlw	0x9E
	movwf	d1
	movlw	0x01
	movwf	d2
Delay_160us_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_160us_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return

;******

Enable
	bsf portb, En ; pulse the LCD Enable high
	nop
	nop
	nop
	nop
	nop
	bcf portb, En ; pulse the LCD Enable low
	nop
	nop
	nop
	nop
	nop
	return

;******

SendCmd4bit
; Send W to lcd trought 4bit interface
; You must set RS first if you are sending a command
	clrf hi_bits ; Set hi_bits to zero
	clrf lo_bits ; Set lo_bits to zero
	clrf portb ; Set portb to zero
; Load W into lo_bits and hi_bits
	movwf tmp
	movwf hi_bits
	movwf lo_bits
;lo_bits preparation
	movlw 0x0F
	andwf lo_bits, 1 ; Remove the high bits and store in lo_bits
;hi_bits preparation
	movlw 0xF0
	andwf hi_bits, 1 ; Remove the low bits
	swapf hi_bits, 1 ; Swap (=switch) low and high bits
;Send the bits
;Hi:
	movfw hi_bits ; Move hi_bits to W
	addwf portb, 1 ; Add the bits instead of moving them so you can set RS before if you want. Store in portb
	call Enable
	call delay_160us ; lcd busy delay
	movfw hi_bits ; Add hi_bits again to W, the delay_160ms is using it (W). (%¤&#½!)
	subwf portb, 1 ; Store in portb
;Lo:
	movfw lo_bits ; Move hi_bits to W
	addwf portb, 1 ; Add the bits so you can set RS before if you want . Store in portb
	call Enable ; Set enable for 3,2us
	call delay_160us ; lcd busy delay
	movfw lo_bits ; Add lo_bits again to W, the delay_160ms is using it (W).
	subwf portb, 1 ; Store in portb
;Done
	return

;*******

SendText4bit
; Send W to lcd trought 4bit interface
; This is for sending text so RS is Enabled
	clrf hi_bits ; Set hi_bits to zero
	clrf lo_bits ; Set lo_bits to zero
	clrf portb ; Set portb to zero
; Enable RS
	bsf portb, RS
; Load W into lo_bits and hi_bits
	movwf tmp
	movwf hi_bits
	movwf lo_bits
;lo_bits preparation
	movlw 0x0F
	andwf lo_bits, 1 ; Remove the high bits and store in lo_bits
;hi_bits preparation
	movlw 0xF0
	andwf hi_bits, 1 ; Remove the low bits
	swapf hi_bits, 1 ; Swap (=switch) low and high bits
;Send the bits
;Hi:
	movfw hi_bits ; Move hi_bits to W
	addwf portb, 1 ; Add the bits instead of moving them so you can set RS before if you want. Store in portb
	call Enable
	call delay_160us ; lcd busy delay
	movfw hi_bits ; Add hi_bits again to W, the delay_160ms is using it (W). (%¤&#½!)
	subwf portb, 1 ; Store in portb
;Lo:
	movfw lo_bits ; Move hi_bits to W
	addwf portb, 1 ; Add the bits so you can set RS before if you want . Store in portb
	call Enable ; Set enable for 3,2us
	call delay_160us ; lcd busy delay
	movfw lo_bits ; Add lo_bits again to W, the delay_160ms is using it (W).
	subwf portb, 1 ; Store in portb
;Done
	return
;*********************************************
; End of Subroutines
;*********************************************
; Start
;*********************************************
Start
	Clrf porta ; Init porta
	Clrf portb ; Init portb

	Banksel trisb ; Select bank1

	Movlw 0x00 ; Data direction value, 0 = output
	Movwf trisb ; Write to trisb
	Movlw 0xFF
	Movwf trisa
	Banksel portb ; Select bank0
;*********************************************
; End of Start
;*********************************************
; Main
;*********************************************
	Call delay_5ms
	Call delay_5ms
	Call delay_5ms
	Call delay_5ms ; Wait for lcd to start
	Movlw 0x03
	Movwf portb
	Call Enable ; Send 0x03
	Call delay_5ms
	Call Enable ; Send 0x03
	Call delay_160us
	Call Enable ; Send 0x03
	Call delay_160us
	Movlw 0x02
	Movwf portb
	Call Enable ; Send 0x02
	Call delay_160us

	Movlw 0x28 ; Interface length is: 4bit, 2 lines, 5x7
	Call SendCmd4bit
	Movlw 0x10 ; Turn off the display
	Call SendCmd4bit
	Movlw 0x01 ; Clear the display
	Call SendCmd4bit
	Movlw 0x06 ; Shift cursor on every written byte
	Call SendCmd4bit
	Movlw 0x0F ; Turn display on, cursor on, cursor blinking on
	Call SendCmd4bit
;Init done
	Movlw 0x45 ; Send "E"
	Call SendText4bit
	Movlw 0x72 ; Send "r"
	Call SendText4bit
	Movlw 0x69 ; Send "i"
	Call SendText4bit
	Movlw 0x6B ; Send "k"
	Call SendText4bit
	Movlw 0x21 ; Send "!"
	Call SendText4bit

;*********************************************
; End of Main
;*********************************************
; End of Program
;*********************************************
	END