PICers, Sorry to rehash an old topic but I CAN'T get this HD44780 LCD programme to work with a 16F84. Tried everything. What drives me nuts is that the same programme in a 16C57 works fine. Well, damn - what's going on? Anybody got ideas?? Any help/advice/insights MUCH appreciated! Thanx - Ian title lcdtst01 ; ;CCT CONFIGURATION : ------ ------ ; DAT_C, 74C922 => RA2 |1 --- 18| RA1 <= DAT_B, 74C922 ; DAT_D, 74C922 => RA3 |2 17| RA0 <= DAT_A, 74C922 ; BATT TEST => T0CKI/RA4 |3 16| OSC1/CLKIN <= 2MHz XTAL ; +5 VDC -> /MCLR |4 15| OSC2/CLKOUT <= 2MHz XTAL ; GND -> Vss |5 16F84 14| Vdd <- +5 VDC ; 74C922, DA <- INT/RB0 |6 13| RB7 -> LCD EN ; NC <- RB1 |7 12| RB6 -> LCD DT ; NC <- RB2 |8 11| RB5 -> LCD CK ; NC <- RB3 |9 10| RB4 -> NC ; --------------- LIST p=16F84, F=INHX8M, R=HEX errorlevel 0, -302, -305 ;302="register in operand not in " ;305="Using Default Destination" __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC include "p16f84.inc" include "asc2lcd.inc" ;The LCD alpha-numeric assignments ;********************************************************* ;VECTOR ASSIGNMENTS ;********************************************************* pic84 equ 0x01FD ;MAX memory address ;********************************************************* ;LCD pin assignments ;********************************************************* EN equ 7 CH equ 6 CK equ 5 RS equ 3 ;Bit #4 in LCDFLAGS determines Command\Character for ;the LCD ;********************************************************* ;FLAG REGISTER assignments ;********************************************************* VT equ 2 ;VALID TRANSMISSION from 74C922 to RB0 ;********************************************************* ;MACROS ;********************************************************* BANK_0 MACRO bcf STATUS,RP0 ;RP0=STATUS.b5 bcf STATUS,RP1 ;RP1=STATUS.b6 ENDM BANK_1 MACRO bsf STATUS,RP0 bcf STATUS,RP1 ENDM ;********************************************************* ;REGISTER ASSIGNMENTS ;BANK #0 ;********************************************************* CBLOCK 0x00C w_ ;Stores w during interrupts STATUS_ ;A 'dummy' STATUS register PCLATH_ FSR_ flags ;A 'decision' register Keydata ;Holds DATA NIBBLE from the 74C922 count_00 count_01 count_02 count_03 ;LCD registers. temp ;Holds HEX data prior to conversion to ASCII w2 ;Dummy w register used by nib_tx charac ;Data for the LCD LCDflag ;Flags R/W, cursor status etc d10000 ;ASCII digits d1000 d100 d10 d01 count count_10 ;PAGE #1 count registers, available for count_11 ;up to 3-loop counters count_12 count_13 ENDC ;******************************************************** ;Begin the MAIN PROGRAMME ;******************************************************** ;PAGE org 0x00 start goto main org 0x04 int movwf w_ ;Start interrupt routine movf STATUS,0 bcf STATUS,0 ;Put registers into known page movwf STATUS_ movf PCLATH,0 ;Save PCLATH movwf PCLATH_ movf FSR,0 movwf FSR_ b1 nop ;Do nothing for now nop int_ret movlw b'00011000' ;Reset the INTCON bits BUT ... movwf INTCON ;.. let the PIC set GIE upon retfie movf FSR,0 movwf FSR movf PCLATH_ movwf PCLATH movf STATUS_,0 ;Return from interrupt swapf w_ ;Flip & laod the w register swapf w_,w ;without affecting the STATUS reg. retfie ;************************************************************* ;Initialise the PIC84's PORTS. ; ;PIN ASSIGNMENTS ;RB0 .. INPUT. Reads DR (Active High) from 74C922 ;RB1 .. NC ;RB2 .. NC ;RB3 .. NC ;RB4 .. NC ;RB5 .. OUTPT to 74164 (CK) ;RB6 .. OUTPT to 74164 (Data B = CH) ;RB7 .. OUTPT to LCD (EN) ; ;RA0 .. INPUT. Reads DAT_A from 74C922 ;RA1 .. INPUT. Reads DAT_B from 74C922 ;RA2 .. INPUT. Reads DAT_C from 74C922 ;RA3 .. INPUT. Reads DAT_D from 74C922 ;RA4 .. INPUT. NC. ; ;************************************************************* init clrf PORTB BANK_1 movlw b'00000001' ;All except RB0 to be OUTPTs movwf TRISB BANK_0 movlw 0x0F1 ; Make sure OUTPTs are OFF movwf PORTB clrf PORTA BANK_1 movlw 0x01F movwf TRISA BANK_0 movlw 0x01F ;PORTA to be all INPUTs movwf PORTA ;Bits 0,1,2,3,4 set to "1" retlw 0x00 ;********************************************************* ;LCD ROUTINES ; ; LCDtx4 .. a routine to drive the HC44780 LCD in 4-bit ; mode via a 3-wire interface. ; ; Data byte must already be in the CHARAC when the ; routine is called. Data format ... D7 D6 D5 D4 RS x x x ;This routine shifts a NIBBLE of Data into the LCD but does so ;using a BYTE count. Data must be in the HIGH NIBBLE of the ;charac register. ;************************************************************ lcdtx4 movlw 0x08 IFDEF DEBUG goto lcdout ENDIF movwf count bcf STATUS,C bcf PORTB,CK nop ;Rest between bit ops. bsf PORTB,CH ;Initialise the Data port. rotate rlf charac,1 ;Rotate the the Data thru CARRY, MSB first. btfss STATUS,C ;Data bit = 1? bcf PORTB,CH ;No - send a zero nop ;Rest between bit ops. bsf PORTB,CK ;Clock the bit thru nop nop ;Rest between bit ops. bcf PORTB,CK decfsz count,1 ;Stepped down thru 8 bits? goto rotate-1 ;No - keep clockin' nop ;Rest between bit-ops. bsf PORTB,EN ;Enable the LCD and nop nop nop nop ;transfer the Data. bcf PORTB,EN nop lcdout bcf PORTB,CH ;Leave PORTB in a defined state. All LOW. retlw 0x00 ;Return to calling routine in PAGE #1 ;************************************************************** ;NIB_TX takes a Data byte and puts the LS nibble into the HIGH ;nibble of the charac register. Data byte must be in the w register. ;NIB_TX checks RS of the LCDflags register to determine CHARACTER or ;COMMAND mode for the LCD ;***************************************************************** nib_tx movwf w2 ;w2 a VIRTUAL w register.. NOT w_ movlw b'11110000' ;Isolate the upper nibble and andwf w2,0 ;retrieve it in w. movwf charac ;Stash the processed byte in charac btfsc LCDflag,RS ;RS=0? COMMAND mode? bsf charac,3 ;No - set RS line for CHARACTER mode. call lcdtx4 ;and send it to the LCD. IFNDEF DEBUG call DLY160 ;Wait 160 us till the LCD settles ENDIF swapf w2,1 ;Invert the H & L nibbles movlw b'11110000' andwf w2,0 ;Isolate the new upper 4 digits movwf charac ;and store in charac register. btfsc LCDflag,RS ;RS=0? COMMAND mode? bsf charac,3 ;No - set RS line for CHARACTER mode. call lcdtx4 ;Send'em to the LCD IFNDEF DEBUG call DLY160 ;Wait 160 uS till the LCD settles. ENDIF retlw 0x00 ;Go back to page #1 calling routine ;**************************************************************** ;DLY160 ... a one-loop, 160 usec (2.0MHz xtal) delay routine ;Both LCD delay routines are called from PAGE #1 and return there. ;DRTE : July 14, 1999 ;***************************************************************** DLY160 movlw 0x05F ;0x050 Calculate C1= 4F (d79) for T=160 us) movwf count_11 decfsz count_11,1 goto $-1 retlw 0x00 ;**************************************************************** ;DLY_5 ... A two-loop, 5-m sec (2.0 MHz xtal) delay routine. ;Both LCD delay routines are called from PAGE #1 and return there. ;DRTE : July 14, 1999 ;**************************************************************** DLY_5 movlw 0x01F ;0x0F calculate C2=$0A (d10) for T = 5 msec movwf count_12 movlw 0x0FF movwf count_11 decfsz count_11,1 goto $-1 decfsz count_12,1 goto $-5 retlw 0x00 ;********************************************************** ;Main Programme .. begin from upper half of Bank #0. Turn ;the interrupts OFF till we're configured. ;********************************************************** main ;bcf INTCON,GIE ;Switch off interrupts while we ... BANK_0 call init ;Initialise the ports ;*********************************************************** ;Power up and configure the LCD ;*********************************************************** pwr_up clrf LCDflag bcf LCDflag,RS ;Clear RS.. COMMAND mode ENABLED IFNDEF DEBUG call DLY_5 ;Wait 15 ms after switch-on call DLY_5 call DLY_5 call DLY_5 ENDIF movlw b'00110000' ;Write 0x03 to the LCD three movwf charac ;times with suitable delays call lcdtx4 ;RS=0 for COMMAND instructions IFNDEF DEBUG call DLY_5 ENDIF movlw b'00110000' movwf charac call lcdtx4 IFNDEF DEBUG call DLY160 ENDIF movlw b'00110000' movwf charac call lcdtx4 IFNDEF DEBUG call DLY160 ENDIF movlw b'00100000' ;4 bit interface movwf charac call lcdtx4 IFNDEF DEBUG call DLY160 ENDIF ;*************************************************************** ;The following instrucs require 2 only NIBBLE WRITES to the LCD. ;Pass the parameters to the NIB_TX subroutine in w. NIB_TX will ;call the lcd_tx4 subroutine. BEWARE the nest level!! ;*************************************************************** movlw b'00101000' ;Write FUNCTION SET call nib_tx IFNDEF DEBUG call DLY160 ENDIF movlw b'00001110' ;Write ON/OFF call nib_tx IFNDEF DEBUG call DLY160 ENDIF movlw b'00000110' ;write ENT MODE call nib_tx IFNDEF DEBUG call DLY160 ENDIF movlw b'00000011' ;Return Cursor & LCD to home call nib_tx IFNDEF DEBUG call DLY160 ENDIF ;************************************************************ ;Then display a "WAKE UP" message ... ;************************************************************ wakeup movwf charac IFNDEF DEBUG call DLY_5 ENDIF clrf LCDflag bsf LCDflag,RS ;Set RS=1 for CHARACTER mode. ;Enable the 4 bit operating mode. movlw lcd_I ;Load 'I' = B'01001001' call nib_tx IFNDEF DEBUG call DLY160 ENDIF movlw lcd_A ;Load 'A' = B'01000001' call nib_tx IFNDEF DEBUG call DLY160 ENDIF movlw lcd_N ;Load 'N' = B'01001110' call nib_tx IFNDEF DEBUG call DLY160 ENDIF setint nop ;Forget interrupts till the LCD works! ;BANK_1 ;movlw 0x0D ;movwf OPTION_REG ;BANK_0 ;clrf TMR0 ;movlw b'10011000' ;Enable the interrupts ;movwf INTCON ;clrf flags ;Initialise the flags goto wakeup ;Hold it here end -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body