Hallo beste mensen,
Alweer eentje die zijn LCD niet aan de gang krijgt?
jawel inderdaad.

Het vreemde is alleen dat mijn programma in pic simulator ide wel werkt.

paar dingen die wel goed zijn:
-Contrast is goed
-backlight is goed
-De poorten (kijk in de definitie lijst van het programma) zijn goed aangesloten (de opstelling in de
simulator is direct gekopieerd van de hardware opstelling)
PIC16F870 display type CFAH1602A-AGH-JP (built in LSI controller)

Nu denk ik dat mijn Busy Flag tijds instellingen in de simulator anders zijn dan op het echte display.
Maar om dingen even uit te sluiten wil ik iemand vragen
zo vriendelijk te zijn even over mijn code heen te kijken.
Immers ik ben nog lerende! Dank Dank Dank


#include <p16F870.inc>
	__config (_XT_OSC  & _WDT_OFF & _PWRTE_OFF & _CP_OFF)

	cblock 0x20
		DEL500US
		DEL1MS
		DEL5MS
		DEL10MS		
	endc

#define RS PORTC,0	
#define RW PORTC,1
#define EN PORTC,2
#define DB0 PORTB,0
#define DB1 PORTB,1
#define DB2 PORTB,2
#define DB3 PORTB,3
#define DB4 PORTB,4
#define DB5 PORTB,5
#define DB6 PORTB,6
#define DB7 PORTB,7

#define LCDDATA PORTB

org 0
    BSF		STATUS,RP0         	;Select Register page 1
    MOVLW	0x00              	;Set PORTB & C for output
    MOVWF	TRISB
	MOVWF   TRISC
    BCF		STATUS, RP0        	;Select Register page 0	

START
    CALL INIT_LCD
    CALL CLEAR_LCD
    MOVLW 'H'
    CALL WRITE_TEXT
    MOVLW 'E'
    CALL WRITE_TEXT
    MOVLW 'L'
    CALL WRITE_TEXT
    MOVLW 'L'
    CALL WRITE_TEXT
    MOVLW 'O'
    CALL WRITE_TEXT
    MOVLW ' '
    CALL WRITE_TEXT
    MOVLW 'W'
    CALL WRITE_TEXT
    MOVLW 'O'
    CALL WRITE_TEXT
    MOVLW 'R'
    CALL WRITE_TEXT
    MOVLW 'L'
    CALL WRITE_TEXT
    MOVLW 'D'
    CALL WRITE_TEXT
	BSF PORTC,4                ;ledje voor einde programma
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	BCF PORTC,4
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
    BSF PORTC,4
    GOTO $ 	;End program




WAIT_LCD
    ;switch banks to make input
    BSF		STATUS,RP0         	;Select Register page 1
    MOVLW	0x0FF              	;Set PORTB for input
    MOVWF	TRISB
    BCF		STATUS, RP0        	;Select Register page 0	
    BCF		EN 					;Start LCD command
    BCF		RS 					;It's a command
    BSF		RW 					;It's a read command
    BSF		EN 					;Clock out command to LCD
    MOVF	LCDDATA, W			;Move DATA(PORTB) to write register
    BCF		EN 					;Finish the command
    ANDLW	0x80                ;Check Busy flag, High = Busy
    BTFSC	LCDDATA,7          ;Test bit b(DB7) in DATA(f), skip if =0
    GOTO	WAIT_LCD
LCDNOTBUSY
    BCF		RW 					;Turn off RW for future commands
    BSF     STATUS, RP0     	;Select Register page 1
    MOVLW   0x00				;Set PORTB for output
    MOVWF   TRISB		       	
    BCF     STATUS, RP0     	;Select Register page 0
RETURN



INIT_LCD
	;POWER UP WAIT
	CALL DELAY10MS
	CALL DELAY10MS
	;as in instructions
	BCF EN
    BCF RS
	BCF RW
    MOVLW 0X38
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN

	CALL DELAY10MS

    MOVLW 0X38
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN
    MOVLW 0X38
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN

	CALL DELAY1MS



;input all the settings
	BSF PORTA,0
    MOVLW 0X38	;8BIT 2 LINE FONT TYPE 5X8 DOTS = 00111000
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN
    CALL WAIT_LCD
			;The LCD command 0X38 is really the sum of a number of option bits. 
			;The instruction itself is the instruction 20h ("Function set"). However, 
			;to this we add the values 10h to indicate an 8-bit data bus plus 
			;08h to indicate that the display is a two-line display.

    MOVLW 0X0F    ;DISPLAY ON, CURSOR ON, BLINKING ON 00001111
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN
    CALL WAIT_LCD

	CALL CLEAR_LCD

    MOVLW 0X06	;CURSOR MOVE RIGHT, CURSOR SHIFT ON 00000111	
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN
    CALL WAIT_LCD
			;The command 06h is really the instruction 04h plus 02h 
			;to configure the LCD such that every time we send it a 
			;character, the cursor position automatically moves to the right.
    RETURN


CLEAR_LCD
      BCF RS
      MOVLW 0x01
      MOVWF LCDDATA
      BSF EN
	  NOP
      BCF EN
      CALL WAIT_LCD
      RETURN


WRITE_TEXT:
      BSF RS
      MOVWF LCDDATA  	;Move character placed in write register to DATA
      BSF EN
	  NOP
      BCF EN
      CALL WAIT_LCD
      RETURN


;mili -3 0.001
;micro -6 0.000001
; 1 clock cycle 1uS

;***********************************  a delay 500US
DELAY500US
	MOVLW	D'166'			;1cycle - 166 X 3 INSTURCTIONS = 498 cycles (1 cycle 1 us)
	MOVWF	DEL500US		;1cycle
DELAY500US_LOOP	
	DECFSZ	DEL500US, F	;1cycle
	GOTO	DELAY500US_LOOP	
	RETURN

;***********************************  a delay 1mS
DELAY1MS
	MOVLW	D'002'			;2 TIMES 500US IS 1 MS
	MOVWF	DEL1MS
DELAY1MS_LOOP
	CALL	DELAY500US
	DECFSZ	DEL1MS
	GOTO	DELAY1MS_LOOP
	RETURN

;***********************************  a delay 5mS
DELAY5MS
	MOVLW	D'005'			;5 TIMES 1 MS IS 5 MS
	MOVWF 	DEL5MS
DELAY5MS_LOOP
	CALL	DELAY1MS
	DECFSZ	DEL5MS
	GOTO	DELAY5MS_LOOP
	RETURN	

;***********************************  a delay 5mS
DELAY10MS
	MOVLW	D'2'			;2 TIMES 5 MS IS 10 MS
	MOVWF 	DEL10MS
DELAY10MS_LOOP
	CALL	DELAY5MS
	DECFSZ	DEL10MS
	GOTO	DELAY10MS_LOOP
	RETURN	

end

[Bericht gewijzigd door bumpers op ]

MOVLW 0x00 ;Set PORTB & C for input
MOVWF TRISB
MOVWF TRISC

, je commentaar zegt dat je ze als input wil

je commentaar maakt het al moeilijker , maar ik vermoed dat je effectief uitgangen wil

Daar kwam ik 5 seconden nadat ik gepost had ook achter.
Het dienen inderdaad outputs te zijn.
Niet echt netjes, maar ben veel aan het rommelen geweest, dus dat zal er nog even door geslipt zijn.

Fijn dat je mee denkt iig!

Groet,

Move /S&I, titel onthelpt, hulp krijg je hier wel, daar hoef je niet om te vragen in een titel ;)

En gebruik code-tags, zie de FAQ.

[Bericht gewijzigd door Henry S. op ]

Kijk zelfs in forums kan ik nog dingen leren!

Ik heb een aanpassing toegevoegd: hetvolgende
Heb even getest, de check busyflag werkt (gesimuleert).


    MOVF	LCDDATA, W	    ;Move DATA(PORTB) to write register
    BCF		EN 		    ;Finish the command
    ANDLW	0x80                ;Check Busy flag, High = Busy

    	MOVWF   CHKBUSY
        BTFSC	CHKBUSY,7          ;Test bit b(DB7) in DATA
    GOTO	WAIT_LCD

Ik heb verder getest met een ledje op poort RC4
blijkbaar blijft hij in de WAIT_LCD hangen.

[Bericht gewijzigd door bumpers op ]

Hierbij gaat het ledje wel!


    MOVF	LCDDATA, w			
    BSF PORTC,4
    CALL DELAY10MS
    BCF		EN 				

Hierbij niet?


    MOVF	LCDDATA, w			
    BCF		EN 				
    BSF PORTC,4
    CALL DELAY10MS

Wat gaat er fout???

[Bericht gewijzigd door bumpers op ]

Je bent de http://www.circuitsonline.net/images/f_edit.gif vergeten te gebruiken, het is niet echt netjes je eigen topic steeds te kicken. ;)

Was ik zeker aan het editen.

Maar gesimuleert doet WAIT_LCD het wel, maar in
de praktijk niet, heb mijn schema na gekeken alles
is correct aangesloten.

Maar enig idee? wat nu de oorzaak is?

[Bericht gewijzigd door bumpers op ]

Okay, krijg iets op het display maar nog lang niet
wat het zou moeten zijn, graag hulp!

Er zou "Hello world" moeten komen te staan, maar wat
ik nu krijg is "HMLLO(_OZLL"
Ik krijg iets op mijn scherm omdat ik de hele wait_lcd
routine skip (zit ergens iets niet lekker)


	LIST	p=16F870
	#include <p16F870.inc>
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__config (_XT_OSC  & _WDT_OFF & _PWRTE_OFF & _CP_OFF)

	cblock 0x20
		DEL500US
		DEL1MS
		DEL5MS
		DEL10MS	
		CHKBUSY	
	endc

#define RS PORTC,0	
#define RW PORTC,1
#define EN PORTC,2
#define DB0 PORTB,0
#define DB1 PORTB,1
#define DB2 PORTB,2
#define DB3 PORTB,3
#define DB4 PORTB,4
#define DB5 PORTB,5
#define DB6 PORTB,6
#define DB7 PORTB,7

#define LCDDATA PORTB

	org 0
    BSF		STATUS,RP0         	;Select Register page 1
    MOVLW	0x00              	;Set PORTB & C for output
    MOVWF	TRISB
	MOVWF   TRISC
    BCF		STATUS, RP0        	;Select Register page 0	

START
    CALL INIT_LCD
    CALL CLEAR_LCD
    MOVLW 'H'
    CALL WRITE_TEXT
;    MOVLW 'E'
	MOVLW 'E'
    CALL WRITE_TEXT
    MOVLW 'L'
    CALL WRITE_TEXT
    MOVLW 'L'
    CALL WRITE_TEXT
    MOVLW 'O'
    CALL WRITE_TEXT
    MOVLW ' '
    CALL WRITE_TEXT
    MOVLW 'W'
    CALL WRITE_TEXT
    MOVLW 'O'
    CALL WRITE_TEXT
    MOVLW 'R'
    CALL WRITE_TEXT
    MOVLW 'L'
    CALL WRITE_TEXT
    MOVLW 'D'
    CALL WRITE_TEXT
	BSF PORTC,4
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	BCF PORTC,4
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
	CALL DELAY10MS
    BSF PORTC,4
    GOTO $ 	;End program




WAIT_LCD
    ;switch banks to make input
;    BSF		STATUS,RP0         	;Select Register page 1
;    MOVLW	0xFF              	;Set PORTB for input
;    MOVWF	TRISB
;    BCF		STATUS, RP0        	;Select Register page 0	
;    BCF		EN 					;Start LCD command
;    BCF		RS 					;It's a command
;    BSF		RW 					;It's a read command
;    BSF		EN 					;Clock out command to LCD
;    MOVF	LCDDATA, W			;Move DATA(PORTB) to write register
;	MOVWF	CHKBUSY
;    BCF		EN 					;Finish the command
;    ANDLW	0x80                ;Check Busy flag, High = Busy
;    BTFSC	CHKBUSY,7          ;Test bit b(DB7) in DATA(f), skip if =0
;    GOTO	WAIT_LCD
;LCDNOTBUSY
;    BCF		RW 					;Turn off RW for future commands
;    BSF     STATUS, RP0     	;Select Register page 1
;    MOVLW   0x00				;Set PORTB for output
;    MOVWF   TRISB		       	
;    BCF     STATUS, RP0     	;Select Register page 0
	CALL DELAY10MS
	RETURN




INIT_LCD
	;POWER UP WAIT
	CALL DELAY10MS
	CALL DELAY10MS

	;as in the datasheet instructions
	BCF EN
    BCF RS
	BCF RW
    MOVLW 0X30
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN

	CALL DELAY10MS

    MOVLW 0X30
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN

	CALL DELAY1MS

    MOVLW 0X30
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN

	CALL DELAY1MS

;input all the settings
	BSF PORTA,0
    MOVLW 0X38	;8BIT 2 LINE FONT TYPE 5X8 DOTS = 0011 1000
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN

	CALL DELAY10MS
    ;CALL WAIT_LCD

    MOVLW 0X08    ;DISPLAY OFF
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN
    ;CALL WAIT_LCD

	CALL DELAY10MS
	CALL CLEAR_LCD

    MOVLW 0X06	;CURSOR MOVE RIGHT, CURSOR SHIFT ON 00000111	
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN
    
	CALL DELAY10MS
    ;CALL WAIT_LCD

    MOVLW 0X0F    ;DISPLAY ON , blink etc
    MOVWF LCDDATA
    BSF EN
	NOP
    BCF EN
    ;CALL WAIT_LCD
    
	RETURN


CLEAR_LCD
      BCF RS
      MOVLW 0x01	;Clear LCD display
      MOVWF LCDDATA
      BSF EN
	  NOP
      BCF EN
	  
 	  CALL DELAY10MS
      ;CALL WAIT_LCD
      RETURN


WRITE_TEXT:
      BSF RS
      MOVWF LCDDATA  	;Move character placed in write register to DATA
      BSF EN
	  NOP
      BCF EN
      CALL WAIT_LCD
      RETURN


;mili -3 0.001
;micro -6 0.000001
; 1 clock cycle 1uS

;***********************************  a delay 500US
DELAY500US
	MOVLW	D'166'			;1cycle - 166 X 3 INSTURCTIONS = 498 cycles (1 cycle 1 us)
	MOVWF	DEL500US		;1cycle
DELAY500US_LOOP	
	DECFSZ	DEL500US, F	;1cycle
	GOTO	DELAY500US_LOOP	
	RETURN

;***********************************  a delay 1mS
DELAY1MS
	MOVLW	D'002'			;2 TIMES 500US IS 1 MS
	MOVWF	DEL1MS
DELAY1MS_LOOP
	CALL	DELAY500US
	DECFSZ	DEL1MS, f
	GOTO	DELAY1MS_LOOP
	RETURN

;***********************************  a delay 5mS
DELAY5MS
	MOVLW	D'005'			;5 TIMES 1 MS IS 5 MS
	MOVWF 	DEL5MS
DELAY5MS_LOOP
	CALL	DELAY1MS
	DECFSZ	DEL5MS, f
	GOTO	DELAY5MS_LOOP
	RETURN	

;***********************************  a delay 5mS
DELAY10MS
	MOVLW	D'2'			;2 TIMES 5 MS IS 10 MS
	MOVWF 	DEL10MS
DELAY10MS_LOOP
	CALL	DELAY5MS
	DECFSZ	DEL10MS, f
	GOTO	DELAY10MS_LOOP
	RETURN	

	end