This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C1C374.F2CDF0D0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Here you go. Sorry if posting files on-list is bad everyone, but it's only 4k. :) It contains 16F870 code to get a HD44780 display initialized and cleared. And looking back at it (somewhat old), my macros are ugly, but the code works and it'd be easy to adapt. :) nick@veys.com | www.veys.com/nick > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Haris I. Volos > Sent: Monday, March 04, 2002 11:45 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Initialising an HD44780 compatible LCD > > > Thanks for the responce, by this time I have seen some > responce from the LCD but somewhere I miss something, so I > would like to see your code to take some ideas. > > Haris > ----- Original Message ----- > From: "Nick Veys" > To: > Sent: Saturday, March 02, 2002 11:05 PM > Subject: Re: [PIC]: Initialising an HD44780 compatible LCD > > > > I've gotten it working on a F870 if you'd like the code. > Couldn't get > > it to work in a 628 when I tried it a few months ago (but > only gave it > > about an hour of time ;) ) Even got a plethora (yes, a > plethora) for > > macro functions for the 870 written to do spiffy stuff. > > > > nick@veys.com | www.veys.com/nick > > > > > At 08:07 PM 3/2/02 +0200, you wrote: > > > I would be grateful if you can sent me the minimal code > required to > > > just display a single character on the LCD to verify that is > > > working, also that will give me a very good starting point to > > > proceed further my own to implement more complicated functions of > > > the LCD. > > > > -- > > http://www.piclist.com hint: To leave the PICList > > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > > > > > > > -- > http://www.piclist.com hint: The list server can filter out > subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics ------=_NextPart_000_0007_01C1C374.F2CDF0D0 Content-Type: application/octet-stream; name="hdd4780.asm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="hdd4780.asm" LIST R=3DDEC INCLUDE "p16f870.inc" __CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON & _LVP_OFF CBLOCK 0x20 DELAY,DELAYTMP ; storage used in delay loops ENDC #define LCD_RS PORTB,2 ; LCD RS Line #define LCD_RW PORTB,1 ; LCD R/_W Line #define LCD_E PORTB,0 ; LCD E Strobe Line #define LCD_DATA PORTC ; LCD Data Port #define LCD_BUSY PORTC,7 ; LCD Busy Line #define LCD_BUSY_TRIS TRISC,7 ; LCD Busy Line Direction Bit BANK0 macro ; Switch to BANK0 bcf STATUS,RP1 bcf STATUS,RP0 endm BANK1 macro ; Switch to BANK1 bcf STATUS,RP1 bsf STATUS,RP0 endm BANK2 macro ; Switch to BANK2 bsf STATUS,RP1 bcf STATUS,RP0 endm BANK3 macro ; Switch to BANK3 bsf STATUS,RP1 bsf STATUS,RP0 endm DELAY_MILLI macro TIME ; 0-255 millisecond delay macro movlw TIME movwf DELAY call DELAY_MS endm DELAY_MICRO macro TIME ; 0-255 microsecond delay macro movlw TIME movwf DELAY call DELAY_US endm LCD_CLEAR macro ; sends clear command to LCD movlw 0x01 call LCD_OUT_COMMAND DELAY_MILLI 2 endm LCD_HOME_LINE1 macro ; homes LCD on line 1 movlw 0x80 call LCD_OUT_COMMAND DELAY_MICRO 45 endm LCD_HOME_LINE2 macro ; homes LCD on line 2 movlw 0xA8 call LCD_OUT_COMMAND DELAY_MICRO 45 endm LCD_COMMAND macro CMD ; LCD command output movlw CMD call LCD_OUT_COMMAND endm LCD_PRINT macro CHAR ; prints a single ascii to LCD movlw CHAR call LCD_OUT_DATA endm ;------------------------------------------------------------------------= ---------------- ; Program code ;------------------------------------------------------------------------= ---------------- PAGE org 0 goto MAIN ;------------------------------------------------------------------------= ---------------- ; Subroutines ;------------------------------------------------------------------------= ---------------- DELAY_MS ; busy wait of DELAY ms movf DELAY,w movwf DELAYTMP ; save DELAY time DELAY_MS_LOOP ; inner loop movlw 245 ; load 245 (1) movwf DELAY ; into DELAY (2) call DELAY_US ; wait 245us (3-249) movlw 245 ; load 245 (250) movwf DELAY ; into DELAY (251) call DELAY_US ; wait 245us (252-498) movlw 245 ; load 245 (499) movwf DELAY ; into DELAY (500) call DELAY_US ; wait 245us (501-747) movlw 246 ; load 246 (748) movwf DELAY ; into DELAY (749) call DELAY_US ; wait 246us (750-997) decfsz DELAYTMP,f ; test DELAYTMP count (998) goto DELAY_MS_LOOP ; loop if not done (999,1000) return ; gtfo (999,1000) DELAY_US ; busy wait of DELAY us ; .2us instruction period assumed nop ; (1) nop ; (2) decfsz DELAY,f ; test DELAY count (3) goto DELAY_US ; loop if not done (4,5) return ; gtfo (4,5) LCD_OUT_COMMAND bcf LCD_RS ; LCD command mode movwf LCD_DATA ; put data on LCD Data Bus bsf LCD_E ; bring E high nop ; wait a teensy bit bcf LCD_E ; bring E low return LCD_OUT_DATA bsf LCD_RS ; LCD command mode movwf LCD_DATA ; put data on LCD Data Bus bsf LCD_E ; bring E high nop ; wait a teensy bit bcf LCD_E ; bring E low DELAY_MICRO 45 ; wait for instruction to complete return ;------------------------------------------------------------------------= ---------------- ; Mainline of code ;------------------------------------------------------------------------= ---------------- org 1024 MAIN =20 BANK1 ; set up registers movlw 0x3F ; W <- xx11 1111 movwf TRISA ^ 0x80 ; PORTA[5:0] input clrf TRISB ^ 0x80 ; PORTB[7:0] output clrf TRISC ^ 0x80 ; PORTC[7:0] output movlw 0x04 ; W <- 1xxx 0100 movwf ADCON1 ^ 0x80 ; set ADCON1 BANK0 LCD_INITIALIZATION ; setup the LCD for us... bcf LCD_RS ; LCD command mode bcf LCD_RW ; LCD write mode bcf LCD_E ; LCD strobe low DELAY_MILLI 20 ; 20ms wait from startup LCD_COMMAND 0x30 ; required DELAY_MILLI 5 ; 5ms delay LCD_COMMAND 0x30 ; required DELAY_MICRO 125 ; 125us delay LCD_COMMAND 0x30 ; required DELAY_MICRO 125 ; 125us delay LCD_COMMAND 0x38 ; 8-bit, 2-line, fontset DELAY_MILLI 5 ; 5ms delay LCD_COMMAND 0x0C ; no cursor, no blink DELAY_MILLI 5 ; 5ms delay LCD_COMMAND 0x06 ; auto-increment cursor DELAY_MILLI 5 ; 5ms delay LCD_CLEAR ; clear it out end ------=_NextPart_000_0007_01C1C374.F2CDF0D0-- -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics