Autor Tema: Problema con lcd en 16f887  (Leído 1730 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado mestanza

  • PIC10
  • *
  • Mensajes: 22
Problema con lcd en 16f887
« en: 21 de Febrero de 2013, 14:20:52 »
Tengo el siguiente problema: Tengo el siguiente codigo en assembler y cuando lo corro en el proteus solo me muestra la 2da linea, la 1era linea no da señales de vida.. si me pueden ayudar, mil gracias

  LIST p = 16F887 ;Simply sets the processor type being used
  #INCLUDE <P16F887.INC> ;file for processor, adds predifined labels
 
   __CONFIG _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _LVP_OFF
                  ; Sets many parameters
  org 0x00             ; Start the code at location zero
 
 
LCD_PORT Equ PORTB
 
LCD_TRIS Equ TRISB
LCD_RS Equ 0x04 ;LCD handshake lines
LCD_E Equ 0x05
 
 
 CBLOCK 0x20
count ; Counter used when switch pressed has stopped
count1 ; 160us Counter variable
counta ; variables for delay timers
countb ; variables for delay timers
LCDTemp ; 4 bit for LCD
 ENDC ;
 
 org 0x00 ;
 goto Init ;
 
HEX_Table
 addwf PCL, f
 retlw 0x30
 retlw 0x31
 retlw 0x32
 retlw 0x33
 retlw 0x34
 retlw 0x35
 retlw 0x36
 retlw 0x37
 retlw 0x38
 retlw 0x39
 retlw 0x41
 retlw 0x42
 retlw 0x43
 retlw 0x44
 retlw 0x45
 retlw 0x46
 
Text
 addwf PCL, f
 retlw 'C'
 retlw 'A'
 retlw 'R'
 retlw 'L'
 retlw 'O'
 retlw 'S'
 retlw ' '
 retlw ' '
 retlw ' '
 retlw ' '
 retlw ' '
 retlw ' '
 retlw 0x00
 
Text2
 addwf PCL, f
 retlw 'M'
 retlw 'E'
 retlw 'S'
 retlw 'T'
 retlw 'A'
 retlw 'N'
 retlw 'Z'
 retlw 'A'
 retlw ' '
 
 
 retlw 0x00
 
; Initialize the PIC and the LCD
Init ;
   BANKSEL   ANSEL
; bsf STATUS,5 ;set memory bank 3
; bsf STATUS,6
 clrf ANSEL ;cofigure pins as digital
 clrf ANSELH
 
   BANKSEL   CM1CON0
; bcf STATUS,5 ;set memory bank 2
 bcf CM1CON0,7 ;disable comparators
 bcf CM2CON1,7
 
   BANKSEL   TRISA
; bcf STATUS,6 ;set memory bank 1
; bsf STATUS,5
 movlw 0XC0
 movwf TRISA ;set port A as output except output 6 and 7
 clrf TRISB ;set port B as output
 clrf TRISC ;set port C as output
 clrf TRISD ;set port D as output
 bcf STATUS,5 ;set memory bank 0
 
 
 call LCDInit ; Initialize the LCD Display
 
 
; Main program...
Message
 movf count,w ; put counter value in W
 goto NextMessage ; display next message if finished
 xorlw 0x00 ; is it a zero?
 btfsc STATUS, Z
 call Text; get a character from the text table ///Your error was here
 call LCD_Char
 incf count, f
 goto Message
 
NextMessage
 call LCD_L2 ;move to 2nd row, first column
 clrf count ;set counter register to zero
 
Message2
 movf count,w ;put counter value in W
 call Text2 ;get a character from the text table
 xorlw 0x00 ;is it a zero?
 btfsc STATUS, Z
 goto EndMessage
 call LCD_Char
 incf count, f
 goto Message2
 
EndMessage
 
; Infinate loop
Stop
 goto Stop ;endless loop
 
; LCD routines and subs
LCDInit ; 4 Bit Initialization...
 call Del05 ; Wait 15 msecs
 call Del05 ;
 call Del05 ;
 movlw 0x03 ; Send the Reset Instruction
 movwf LCD_PORT ;
 call Pulse_e ; Pulse LCD_E
 call Del05 ; Delay 5ms
 call Pulse_e ; Pulse LCD_E
 call D160us ; Delay of 160us
 call Pulse_e ; Pulse LCD_E
 call D160us ; Delay of 160us
 movlw 0x02 ; Send the Data Length Specification
 movwf LCD_PORT ;
 call Pulse_e ; Pulse LCD_E
 call D160us ; Delay of 160us
 movlw 0x028 ; Set Interface Length
 call LCDIns ;
 movlw 0x010 ; Turn Off Display
 call LCDIns ;
 movlw 0x001 ; Clear Display RAM
 call LCDIns ;
 movlw 0x006 ; Set Cursor Movement
 call LCDIns ;
 movlw 0x00C ; Turn on Display/Cursor
 call LCDIns ;
 call LCD_Clr ; Clear the LCD
 return ;
 
LCDIns ; Send the Instruction to the LCD
 movwf LCDTemp ; Save the Value
 swapf LCDTemp, 1
 movf LCDTemp, 0
 andlw 0x0F ; Most Significant Nibble first
 movwf LCD_PORT ;
 bcf LCD_PORT, LCD_RS ;
 call Pulse_e ;
 swapf LCDTemp, w ; Least Significant Nibble Second
 andlw 0x0F ;
 movwf LCD_PORT ;
 bcf LCD_PORT, LCD_RS ;
 call Pulse_e ;
 call Del01 ; wait 1 ms
 movf LCDTemp, w ;
 andlw 0xFC ; Have to Delay 5 msecs?
 btfsc STATUS, Z ;
 call Del01 ; 1ms
 return ;
 
LCD_CharD
 addlw 0x30 ; add 0x30 to convert to ASCII
LCD_Char ; Send the Character to the LCD
 movwf LCDTemp ; Save the Value
 swapf LCDTemp, 1
 MovF LCDTemp, 0
 andlw 0x0F ; Most Significant Nibble first
 movwf LCD_PORT ;
 bsf LCD_PORT, LCD_RS ;
 call Pulse_e ;
 swapf LCDTemp, w ; Least Significant Nibble Second
 andlw 0x0F ;
 movwf LCD_PORT ;
 bsf LCD_PORT, LCD_RS ;
 call Pulse_e ;
 call Del05 ;
 nop ;
 return ;
 
 
LCD_L2: movlw 0xc0 ; move to 2nd row, first column
 call LCDIns ;
 retlw 0x00 ;
 
LCD_Clr movlw 0x01 ; Clear display
 call LCDIns ;
 retlw 0x00 ;
 
Pulse_e ;
 bsf LCD_PORT, LCD_E ; LCD Enable pulse to write data from PORTB
 nop ; into LCD module.
 nop
 bcf LCD_PORT, LCD_E ;
 nop ;
 nop
 retlw 0x00 ;
 
 
; Delay routines...
D160us
 clrf count1 ;
 bsf count1, 5 ; Delay 160 usecs
 bsf count1, 4 ;
 decfsz count1, f ;
 goto $ - 1 ;
 return ;
 
Del255 movlw 0xff ; delay 255 mS
 goto d0 ;
Del200 movlw d'255' ; delay 200mS
 goto d0 ;
Del100 movlw d'200' ; delay 100mS
 goto d0 ;
Del50 movlw d'100' ; delay 50mS
 goto d0 ;
Del20 movlw d'40' ; delay 20mS
 goto d0 ;
Del05 movlw 0x10 ; delay 5.000 ms (4 MHz clock)
 goto d0 ;
Del01 movlw 0x05 ; delay 1.000 ms (4 MHz clock)
d0 movwf count1 ;
d1 movlw 0xC7 ; delay 1mS
 movwf counta ;
 movlw 0x04 ;
 movwf countb ;
Del_0 decfsz counta,f ;
 goto $+2 ;
 decfsz countb,f ;
 goto Del_0 ;
 decfsz count1,f ;
 goto d1 ;
 retlw 0x00 ;
 
 end