Issue with single string character


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: Issue with single string character

    that last line was wrong should be


    day = ((reg_val[3] >> 4) * 10) + (reg_val[3]$0f) ; bcd2bin conversion

    lcdout dec2 day

    must have been too early in the morning for me

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Issue with single string character

    Quote Originally Posted by richard View Post
    that last line was wrong should be


    day = ((reg_val[3] >> 4) * 10) + (reg_val[3]$0f) ; bcd2bin conversion

    lcdout dec2 day

    must have been too early in the morning for me

    It took me a moment... I'm blaming it on mashed potato poisoning - self inflicted, don't call the police.


    In fact, I use a similar function to convert the calendar registers to decimal (and back) as part of each read and write routine. The problem comes in trying to use that decimal value to retrieve text characters. The math:

    REG_VAL[5] = 1 in January... So:

    READ 097 + (REG_VAL[5] * 3) + 0 = DATA position 100; CA_MONTH[0] = "J"
    READ 097 + (REG_VAL[5] * 3) + 1 = DATA position 101; CA_MONTH[1] = "A"
    READ 097 + (REG_VAL[5] * 3) + 2 = DATA position 102; CA_MONTH[2] = "N"

    The problem... On the LCD the first character in munged - displays as "$AN", where $ represents some random pattern of dots. When REG_VAL[5] = 2, I get $EB; 3 = $AR... Indicating that the month is correctly decoded and the DATA located properly. As they say, "Everything is perfect, it just don't work".

    The day (MO, TU, WE...) is decoded similarly from REG_VAL[3] (starting at DATA location 137) and displays as it should.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: Issue with single string character

    looks like I got hold of the wrong end of the stick again


    tried this

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 29/11/2014                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    #CONFIG
    cfg1 = _FOSC_INTOSC
    cfg1&= _WDTE_ON
    cfg1&= _PWRTE_OFF
    cfg1&= _MCLRE_ON
    cfg1&= _CP_OFF
    cfg1&= _CPD_OFF
    cfg1&= _BOREN_ON
    cfg1&= _CLKOUTEN_OFF
    cfg1&= _IESO_ON
    cfg1&= _FCMEN_ON
      __CONFIG _CONFIG1, cfg1
    cfg2 = _WRT_OFF
    cfg2&= _PLLEN_OFF
    cfg2&= _STVREN_ON
    cfg2&= _BORV_19
    cfg2&= _LVP_OFF
      __CONFIG _CONFIG2, cfg2
    #ENDCONFIG
    
     DATA @ 100, "J", "A", "N", "F", "E", "B", "M", "A", "R", "A", "P", "R", "M", "A", "Y", "J", "U", "N", "J", "L", "Y", "A", "U", "G", "S", "E", "P", "O", "C", "T", "N", "O", "V", "D", "E", "C"
     ;DATA @ 137, "S", "U", "M", "O", "T", "U", "W", "E", "T", "H", "F", "R", "S", "A", "S", "U"
     CA_MONTH var byte[3 ]
     reg_val  var byte
       osccon=$6a    '4 mhz
       anselA=0  
     
     
     main:
      for   reg_val =1 to 12
      gosub expand_date
      Serout2 PORTA.0,84,["m",#reg_val ," ",str ca_month \3 ,13,10]
      next
      goto main
    EXPAND_DATE:
     READ 097 + (reg_val * 3) + 0, CA_MONTH[0]
     READ 097 + (reg_val * 3) + 1, CA_MONTH[1]
     READ 097 + (reg_val * 3) + 2, CA_MONTH[2]
     RETURN
    result



    Code:
    m1 JAN
    m2 FEB
    m3 MAR
    m4 APR
    m5 MAY
    m6 JUN
    m7 JLY
    m8 AUG
    m9 SEP
    m10 OCT
    m11 NOV
    m12 DEC

    so the method is sound . reg_val[5] is binary not BCD right ?
    otherwise post entire code , I suspect an array overrun is most likely problem


    ps another method using flash mem not eprom :- for more ideas
    lookup pkt[3],["xmtwtfss"], day[0]
    lookup pkt[3],["xouehrau"], day[1]
    lookup pkt[3],["xnenuitn"], day[2]
    Last edited by richard; - 28th November 2014 at 23:10.

Similar Threads

  1. Replies: 3
    Last Post: - 3rd December 2011, 23:48
  2. How to send a string with another string inside it?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th May 2011, 18:11
  3. SEROUT command (single byte value not string)
    By MrRoboto in forum mel PIC BASIC
    Replies: 15
    Last Post: - 12th June 2010, 04:34
  4. sending string to module GSM with character ""
    By volcane in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd May 2010, 03:26
  5. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 09:52

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts