Hi, I would really appreciate it if someone would have a look at this code for me. I have spent quite a lot of time rewriting it in the hope of getting it to work and got nowhere. I'm sure it's likely to be a stupidly small error, as always. You can tell from the code how the LCD is wired but just in case... RB0 - RB7 = D0 - D7 RA0 = CD RA1 = RD RA2 = WR RA3 = CE RE0 = LED RE1 = LCD RST Or if someone can't help with this code how about some working code for a 16f877 that I can look over. Thanks. Dave ;----------------------------------------------------------------------- ---- ; David Stubbs: Dave@nti-solutions.org ;----------------------------------------------------------------------- ---- Title "Toshiba T6963 Graphical LCD Test Code" ;----------------------------------------------------------------------- ---- list p = 16f877 ;#define TESTING ;----------------------------------------------------------------------- ---- #include ;----------------------------------------------------------------------- ---- __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF ;----------------------------------------------------------------------- ---- radix dec ; Set the default number base to 10 ;----------------------------------------------------------------------- ---- ; Variables Cblock 0x0C NumMilisecs ;Delay100 MiliLoopVar ;Delay100 NumTenths ;Delay CurrentNum Data2Send ;LCD_SendData AddrMSB ;LCD_SendAddress AddrLSB ;LCD_SendAddress Loop Character endc ;----------------------------------------------------------------------- ---- LCD_CONTROL EQU PORTA LCD_DATA EQU PORTB LCD_CE EQU 3 LCD_WR EQU 2 LCD_RD EQU 1 LCD_CD EQU 0 ;----------------------------------------------------------------------- ---- org 00h goto Main ;----------------------------------------------------------------------- ---- org 04h ;----------------------------------------------------------------------- ---- Main call InitPorts ; Wait 100 millseconds movlw 4 call Delay100 ;Hold RST Low for a second or so then set high bcf PORTE, 1 movlw 120 call Delay100 ; Probably well too long. Better safe than sorry.. bsf PORTE, 1 call TestLCD ProgramHeart call FlashLED goto ProgramHeart ;----------------------------------------------------------------------- ---- FlashLED bsf PORTE, 0 movlw 122 call Delay100 bcf PORTE, 0 movlw 122 call Delay100 return ;----------------------------------------------------------------------- ---- TestLCD call FlashLED ; Text home address call Check3 movlw 0 call WriteData call Check3 movlw 0 call WriteData call Check3 movlw 0x40 call WriteCommand call FlashLED ; text area set call Check3 movlw 0x20 call WriteData call Check3 movlw 0x00 call WriteData call Check3 movlw 0x43 call WriteCommand call FlashLED ; Mode Set call Check3 movlw 0x80 call WriteCommand call FlashLED ; Display mode call Check3 movlw b'10011100' call WriteCommand ; Move to start of text area call Check3 movlw 0 call WriteData call Check3 movlw 0 call WriteData call Check3 movlw 0x24 call WriteCommand ;Send Letter call Check3 movlw 15 call WriteData call Check3 movlw 0xC0 call WriteCommand return ;----------------------------------------------------------------------- ---- Check3 ; Initialise all lines as high bsf LCD_CONTROL, LCD_CE bsf LCD_CONTROL, LCD_RD bsf LCD_CONTROL, LCD_WR bsf LCD_CONTROL, LCD_CD ; Now do the magic combo to ask for a status check bsf LCD_CONTROL, LCD_CD bcf LCD_CONTROL, LCD_RD bsf LCD_CONTROL, LCD_WR bcf LCD_CONTROL, LCD_CE ;Read data on LCD_DATA bcf STATUS, RP1 bsf STATUS, RP0 ; Now into bank 1 ; Configure all pins as digital IO pins movlw 0x06 movwf ADCON1 ; Disable PORTB's weak pull up's ;movlw b'10010111' ;movwf OPTION_REG movlw 255 movwf TRISB ; Back to PAGE0 memory bcf STATUS, RP0 WaitReady btfss LCD_DATA, 0 goto WaitReady call FlashLED WaitReady2 btfss LCD_DATA, 1 goto WaitReady2 ; Restore it to an output port call InitPorts bsf LCD_CONTROL, LCD_CE bsf LCD_CONTROL, LCD_RD return ;----------------------------------------------------------------------- ---- WriteCommand movwf Temp call Check3 movf Temp, W ; Initialise all lines as high bsf LCD_CONTROL, LCD_CE bsf LCD_CONTROL, LCD_RD bsf LCD_CONTROL, LCD_WR bsf LCD_CONTROL, LCD_CD ; Now do the magic combo to write command movwf LCD_DATA bsf LCD_CONTROL, LCD_CD bcf LCD_CONTROL, LCD_WR bsf LCD_CONTROL, LCD_RD bcf LCD_CONTROL, LCD_CE nop bsf LCD_CONTROL, LCD_CE bsf LCD_CONTROL, LCD_WR return ;----------------------------------------------------------------------- ---- WriteData movwf Temp call Check3 movf Temp, W ; Initialise all lines as high bsf LCD_CONTROL, LCD_CE bsf LCD_CONTROL, LCD_RD bsf LCD_CONTROL, LCD_WR bsf LCD_CONTROL, LCD_CD ; Now do the magic combo to write data movwf LCD_DATA bcf LCD_CONTROL, LCD_CD bcf LCD_CONTROL, LCD_WR bsf LCD_CONTROL, LCD_RD bcf LCD_CONTROL, LCD_CE nop bsf LCD_CONTROL, LCD_CE bsf LCD_CONTROL, LCD_WR return ;----------------------------------------------------------------------- ---- InitPorts ; Bank 0 bcf STATUS, RP0 bcf STATUS, RP1 clrf PORTA ; Initialise by clearing output latch bsf STATUS, RP0 ; Now into bank 1 ; Configure all pins as digital IO pins movlw 0x06 movwf ADCON1 ; Disable PORTB's weak pull up's movlw b'10010111' movwf OPTION_REG ; Set to output. clrf TRISA clrf TRISB clrf TRISE ; Back to PAGE0 memory bcf STATUS, RP0 return ;----------------------------------------------------------------------- ---- ; Waits for a predetermined multiple of miliseconds. Calibrated for 4Meg clock- 4*249+4=1000 At 4MHz clock delay is ; 1mS Note: Works for a max of 255mS as only have 8 bit regs ; ; INPUT: Num of miliseconds to wait in W reg ; GLOBALS: NumMilisecs ; MiliLoopVar ;----------------------------------------------------------------------- ---- Delay movwf NumMilisecs ; Hold Num Miliseconds to wait #ifndef TESTING MiliSec movlw 249 ; 1uS movwf MiliLoopVar ; 1uS MiliLoop nop ; 1uS decfsz MiliLoopVar, 1 ; 1uS 2 On Jump goto MiliLoop ; 2uS ; outer loop counts miliseconds. Extra instruction delays insignificant decfsz NumMilisecs, 1 ; 1uS if no skip goto MiliSec ; 2uS #endif return ; 2uS ;----------------------------------------------------------------------- ---- ; Waits for a predetermined multiple of 1/10 seconds. Calibrated for 4Meg clock ; ; INPUT: Num of 100mS to wait in W reg ; CALLS: Delay ; GLOBALS: NumTenths ;----------------------------------------------------------------------- ---- Delay100 movwf NumTenths ; Hold Num 1/4S to wait iorlw 0 btfsc STATUS,Z ; Check w not 0 if it is, ret return #ifndef TESTING TenthsLoop movlw 100 ; Do 100ms delay... call Delay decfsz NumTenths, 1 goto TenthsLoop ; ...For desired 1/10ths delay #endif return ;----------------------------------------------------------------------- ---- end ;----------------------------------------------------------------------- ---- -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu