Autor Tema: LCD en mikrobasic me duplica datos  (Leído 3215 veces)

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

Desconectado beto0350

  • PIC12
  • **
  • Mensajes: 58
LCD en mikrobasic me duplica datos
« en: 05 de Agosto de 2009, 09:40:19 »
Hola:
      hice un programa en mikrobasic que me muestra fecha y hora en un lcd de 16x2, la fecha la muestro en la linea 1
y la hora en la 2.
el problema es que me muestra en la linea 1 al final de la misma  el comienzo de la linea 2(adjunto el pgm que creo que esta bien),
el error lo da en Proteus y en un protoboard tambien.

Cualquier ayuda se agradece


program Lcd_Test
dim csecs,secs, mins, hrs as byte               ' tally variables
dim clk as string[12]          ' output string for LCD
dim hstr as string[3]
dim mstr as string[3]
dim sstr as string[3]
dim csstr as string[3]

dim todosfecha as string[8]
dim dia,mes,ano as byte
dim diastr as string[3]
dim messtr as string[3]
dim anostr as string[2]
 dim int_count as byte
dim text as string[16]
dim update as boolean

sub procedure Muestro_display(dim byref dia,mes,ano,hrs,mins,secs,csecs as byte,
                              dim byref diastr as string[3],
                              dim byref messtr as string[3],
                              dim byref anostr as string[2],
                              dim byref hstr as string[3],
                              dim byref mstr as string[3],
                              dim byref sstr as string[3],
                              dim byref csstr as string[3])

    bytetostr(dia, diastr)                  ' create clock output string for LCD
    If diastr[1] = 32 Then diastr[1] = 48 End If
    bytetostr(mes, messtr)
    messtr[0] = "/"
    If messtr[1] = 32 Then messtr[1] = 48 End If
    bytetostr(ano, anostr)
    anostr[0] = "/"
    If anostr[1] = 32 Then anostr[1] = 48 End If

   bytetostr(hrs, hstr)                  ' create clock output string for LCD
    If hstr[1] = 32 Then hstr[1] = 48 End If
    bytetostr(mins, mstr)
    mstr[0] = ":"
    If mstr[1] = 32 Then mstr[1] = 48 End If
    bytetostr(secs, sstr)
    sstr[0] = ":"
    If sstr[1] = 32 Then sstr[1] = 48 End If
    bytetostr(csecs, csstr)
    csstr[0] = ":"
    If csstr[1] = 32 Then csstr[1] = 48 End If

    Lcd_Out(1,1,diastr)
    Lcd_Out(1,4,messtr)
    Lcd_Out(1,7,anostr)


    LCD_Out(2,2,hstr)
    LCD_OUT(2,5,mstr)
    LCD_OUT(2,8,sstr)
    LCD_OUT(2,11,csstr)

end sub


main:
  text = "mikroElektronika"
 
  ADCON1 = 0x0F

   int_count = 0
   secs = 59
   mins = 59
   hrs = 23
   dia=31
   mes=12
   ano=8

   update = true



' Lcd_Config(PORTB,3,2,1,0,PORTB,4,7,5) ' Lcd_Init_EP5, see Autocomplete
 Lcd_Config(PORTB,3,2,1,0,PORTB,4,7,5) ' Lcd_Init_EP5, see Autocomplete


  LCD_Cmd(LCD_CLEAR)                    ' Clear display
  LCD_Cmd(LCD_CURSOR_OFF)               ' Turn cursor off
  Delay_ms(500)


  while true
        Muestro_display(dia,mes,ano,hrs,mins,secs,csecs,diastr,messtr,anostr,hstr,mstr,sstr,csstr)
  wend
end.

Desconectado jhonorozco44

  • PIC10
  • *
  • Mensajes: 1
Re: LCD en mikrobasic me duplica datos
« Respuesta #1 en: 15 de Junio de 2012, 13:12:12 »
Que tal viejo.. yo hice este ... intetalo y me cuentas como te fue.... el reloj que utilice es el ds1307,,  ademas puedes mostrar el dia, sin quieres la fecha agregas la variable FECRTC1 ....suerte


DIM SEGRTC, MINRTC, HORRTC, DIARTC, FECRTC, MESRTC, ANORTC, CTRRTC AS BYTE
DIM SEGRTC1, MINRTC1, HORRTC1, DIARTC1, FECRTC1, MESRTC1, ANORTC1, CTRRTC1 AS BYTE
DIM TEMPRTC AS CHAR[2]


DIM  SCL_Direction  as sbit at TRISC3_BIT
     SDA_Direction  as sbit at TRISC4_BIT

DIM  LCD_RS as sbit at RB4_bit
     LCD_EN as sbit at RB5_bit
     LCD_D4 as sbit at RB0_bit
     LCD_D5 as sbit at RB1_bit
     LCD_D6 as sbit at RB2_bit
     LCD_D7 as sbit at RB3_bit


DIM  LCD_RS_Direction as sbit at TRISB4_bit
     LCD_EN_Direction as sbit at TRISB5_bit
     LCD_D4_Direction as sbit at TRISB0_bit
     LCD_D5_Direction as sbit at TRISB1_bit
     LCD_D6_Direction as sbit at TRISB2_bit
     LCD_D7_Direction as sbit at TRISB3_bit

' End lcd module connections

' Declarations section

SUB PROCEDURE LEER_RTC
  I2C1_INIT(100000)
  I2C1_START()            ' INICIA SEÑAL DE START
  I2C1_WR(0XD0)           ' DIRECCIONA LA COMUNICACION AL DS1307
  I2C1_WR(0)              ' EMPIEZA DESDE EL REGISTRO CERO
  I2C1_REPEATED_START()   ' INICIA UNA SEGUNDA SEÑAL DE STARR
  I2C1_WR(0XD1)           ' LE DICE AL DS1307 QUE LEERA LOS REGISTROS DESDE LA DIRECCION INDICADA ANTERIORMENTE
  SEGRTC = I2C1_RD(1)     ' LEE EL BYTE DE SEGUNDOS
  MINRTC = I2C1_RD(1)     ' LEE EL BYTE DE MINUTOS
  HORRTC = I2C1_RD(1)     ' LEE EL BYTE SE HORAS
  DIARTC = I2C1_RD(1)     ' LEE EL BYTE DEL DIA (DIA DE LA SEMANA)
  FECRTC = I2C1_RD(1)     ' LEE EL BYTE DE LA FECHA (DIA DEL MES)
  MESRTC = I2C1_RD(1)     ' LEE EL BYTE DEL MES
  ANORTC = I2C1_RD(1)     ' lEE EL BYTE DEL AÑO
  CTRRTC = I2C1_RD(0)
  I2C1_STOP()             ' PARA LA TRANSMISION DE DATOS SOBRE EL BUS
END SUB

SUB PROCEDURE TRANSF_RTC
  SEGRTC  =  ((SEGRTC AND 0XF0) >> 4)*10 + (SEGRTC AND 0X0F)  ' TRANSFORMA SEGUNDOS
  MINRTC  =  ((MINRTC AND 0XF0) >> 4)*10 + (MINRTC AND 0X0F)  ' TRANSFORMA MINUTOS
  HORRTC  =  ((HORRTC AND 0XF0)  >> 4)*10  + (HORRTC AND 0X0F)    ' TRANSFORMA HORAS
  ANORTC  =  (ANORTC AND 0XC0) >> 6 + 12                               ' TRANSFORMA AÑO
  FECRTC  =  ((FECRTC AND 0X30) >> 4)*10    + (FECRTC AND 0X0F)       ' TRANSFORMA DIA DEL MES
  DIARTC  =  ((DIARTC AND 0X30) >> 4)*10    + (DIARTC AND 0X0F)       ' TRANSFORMA DIA DE LA SEMANA
  MESRTC  =  ((MESRTC AND 0X10)  >> 4)*10 + (MESRTC AND 0X0F)     ' TRANSFORM MESES
END SUB

SUB PROCEDURE PROG_RTC

  SEGRTC = dec2bcd(SEGRTC1)
  MINRTC = dec2bcd(MINRTC1)
  HORRTC = dec2bcd(HORRTC1)
  DIARTC =  dec2bcd(DIARTC1)
  FECRTC =  dec2bcd(FECRTC1)
  MESRTC = dec2bcd(MESRTC1)
  ANORTC =  dec2bcd (ANORTC1) 'dec2bcd(11)

  I2C1_INIT(100000)  ' INICIALIZA EL MODULO I2C A 100 KHZ
  I2C1_START()       ' INICIA SEÑAL DE START
  I2C1_WR(0XD0)      ' DIRECCIONA EL DS1307
  I2C1_WR(0)
  I2C1_WR(SEGRTC)
  I2C1_WR(MINRTC)
  I2C1_WR(HORRTC)
  I2C1_WR(DIARTC)
  I2C1_WR(FECRTC)
  I2C1_WR(MESRTC)
  I2C1_WR(ANORTC)
  I2C1_WR($90)
  I2C1_STOP()

END SUB

SUB PROCEDURE INIT_RTC
  I2C1_INIT(100000)  ' INICIALIZA EL I2C EN MODO FULL MASTER
  I2C1_START()       ' INICIA SEÑAL DE START
  I2C1_WR(0XD0)      ' DIRECCIONA EL DS1307
  I2C1_WR(0)         ' INICIA DESDE LA DIRECCION 0
  I2C1_WR(0)         ' ESCRIBE 0 PARA QUE COMIENCE EL CONTEO
  I2C1_STOP()        ' FINALIZA LA COMUNICACION
END SUB
main:
'   Main program
    'ANSEL = 0
    'ANSELH = 0
    TRISB = 0
    TRISC = 0
    DELAY_MS(200)
    LCD_INIT()
    'INIT_RTC
    SEGRTC1 = 0
    MINRTC1 = 05
    HORRTC1 = 22
    DIARTC1 = 5
    FECRTC1 = 14
    MESRTC1 = 06
    ANORTC1 = 12
    'PROG_RTC
   
   
    Lcd_Cmd(_LCD_CLEAR)
    Lcd_OUT(1,1,"HORA:")
    Lcd_Out(2, 1, "DIA:")
    Lcd_Out(1, 9, ":")
    Lcd_Out(1, 13, ":")
    LCD_CMD(_LCD_CURSOR_OFF)
   
'    DIREEPROM = 0
'    DATAEEPROM = "L"
'    GRABAR_EXT_BYTE
'
'    DIREEPROM = 0
'    LEER_EXT_BYTE
'    TEMPEEPROM = DATAEEPROM
'
'    LCD_CHR(2,15,TEMPEEPROM)
   WHILE true
    LEER_RTC
    TRANSF_RTC
    BYTETOSTR(HORRTC,TEMPRTC)
    LCD_OUT(1,6,TEMPRTC)
    BYTETOSTR(MINRTC,TEMPRTC)
    LCD_OUT(1,9,TEMPRTC)
    BYTETOSTR(SEGRTC,TEMPRTC)
    LCD_OUT(1,12,TEMPRTC)
    Lcd_Out(1, 9, ":")
    Lcd_Out(1, 12, ":")
    LCD_CMD(_LCD_CURSOR_OFF)

   
    SELECT CASE DIARTC
           CASE 1
           LCD_OUT(2,6,"DOMINGO")
           CASE 2
           LCD_OUT(2,6,"LUNES")
           CASE 3
           LCD_OUT(2,6,"MARTES")
           CASE 4
           LCD_OUT(2,6,"MIERCOLES")
           CASE 5
           LCD_OUT(2,6,"JUEVES")
           CASE 6
           LCD_OUT(2,6,"VIERNES")
           CASE 7
           LCD_OUT(2,6,"SABADO")
           CASE ELSE
           LCD_OUT(2,5,"UNPROGRAM")
    END SELECT
 
 WEND
   
end.

Desconectado TAZcustom

  • PIC10
  • *
  • Mensajes: 8
Re: LCD en mikrobasic me duplica datos
« Respuesta #2 en: 20 de Junio de 2012, 23:41:53 »
Amigo tal vez estas olvidando dividir lineas

      Lcdcmdout LcdClear 'borra la pantalla
      Lcdout "T.MI T.ACTU T.MA" 'mostramos dato en linea 1
      Lcdcmdout LcdLine2Home 'vamos ala segunda linea
      Lcdout #tempbaj, "oC" 'mostramos dato en linea 2
      Lcdout $fe, $14, #dato, "oC" 'mostramos dato en linea 2
      Lcdout $fe, $14, #tempalt, "oC" 'mostramos dato en linea 2


suerte saludos!!


 

anything