Handling a lot of text data, any simple and practical ways?


Results 1 to 20 of 20

Threaded View

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


    Did you find this post helpful? Yes | No

    Default Re: Handling a lot of text data, any simple and practical ways?

    on a 16f like this

    Code:
    ;16f1825#CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_OFF &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 32    
        OSCCON=$70
        ANSELA=0
        ANSELC=0
        TRISA = %001110
        trisc = %11100010     ' set PORTC I/O
        Strings CON EXT
    
    
        i VAR BYTE
        Char VAR BYTE
        ctemp  VAR WORD
        StringNumber VAR BYTE
        StartAddress VAR WORD
        rand      VAR WORD
        lata.0=1 
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10  
    Goto OverStrings
    ASM
    Strings
        ; Strings, fixed length, 20 characters including null terminator.
        ; Actual string terminatesends with a NULL and is then padded to exactly 20 chars.
        da "Set Year", 0, "           "    ; 0
        da "Set Month", 0, "          "    ; 1
        da "Set Date", 0, "           "    ; 2
        da "Set day of week", 0, "    "    ; 3
        da "Set Hour", 0, "           "    ; 4
        da "Set Minute", 0, "         "    ; 5 
        da "Set alarm mode", 0, "     "    ; 6
        da "Off", 0, "                "    ; 7
        da "On all week", 0, "        "    ; 8
        da "On without weekends", 0, ""    ; 9
        da "Set alarm hours", 0, "    "    ; 10
        da "Set alarm minutes", 0, "  "    ; 11
        da "Set display format", 0, " "    ; 12
        da "Imperial (12Hr/F)", 0, "  "    ; 13
        da "Metric (24Hr/C)", 0, "    "    ; 14
        da "Display brightness", 0, " "    ; 15
        da "Auto", 0, "               "    ; 16
        da "25%", 0, "                "    ; 17
        da "50%", 0, "                "    ; 18
        da "75%", 0, "                "    ; 19
        da "100%", 0, "               "    ; 20
    ENDASM
    OverStrings: 
    
    
    Start:
        Debug "Program start",13,10 
        Debug "Address of first string: $", HEX4 Strings, 13 ,10
    
    
    Action:    
         RANDOM  rand 
        StringNumber = rand//20                               ' Select which string to print
        GOSUB PrintString                               ' And, you guessed it, go print it.
         PAUSE 1000
        goto  Action
    END
    
    
    PrintString:   
        StartAddress = Strings + (StringNumber * 11)    ' Precalculate address of first char of string in question
        For i = 0 to 19                                 ' Maximum string length is 20 characters
            ReadCode (StartAddress + i), CTEMP           ' Get a char from string in question.
          Char = (CTEMP>>7) 
            IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
            Debug Char                                   ' Otherwise print it
         Char = CTEMP&$7f        
           IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
            Debug Char                                ' Otherwise print it
        NEXT
    RETURN
    or if all that padding is troubling , using random length null terminated strings
    Code:
    ;16f1825#CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_OFF &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 32
        OSCCON=$70
        ANSELA=0
        ANSELC=0
        TRISA = %001110
        trisc = %11100010     ' set PORTC I/O
        Strings CON EXT
        i VAR BYTE
        Char VAR BYTE
        ctemp  VAR WORD
        rand   VAR WORD
        StringNumber VAR BYTE
        StartAddress VAR WORD
        isa   VAR WORD
        lata.0=1 
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10  
    Goto OverStrings
    ASM
    Strings
        ;  string terminates with a NULL 
        da "Set Year", 0     ; 0
        da "Set Month", 0     ; 1
        da "Set Date", 0    ; 2
        da "Set day of week", 0    ; 3
        da "Set Hour", 0     ; 4
        da "Set Minute", 0     ; 5 
        da "Set alarm mode", 0     ; 6
        da "Off", 0    ; 7
        da "On all week", 0     ; 8
        da "On without weekends", 0   ; 9
        da "Set alarm hours", 0    ; 10
        da "Set alarm minutes", 0     ; 11
        da "Set display format", 0    ; 12
        da "Imperial (12Hr/F)", 0    ; 13
        da "Metric (24Hr/C)", 0    ; 14
        da "Display brightness", 0    ; 15
        da "Auto", 0    ; 16
        da "25%", 0     ; 17
        da "50%", 0    ; 18
        da "75%", 0     ; 19
        da "100%", 0     ; 20
        dw 3            ;eof
    ENDASM
    OverStrings:
    
    
    Start:
        Debug "Program start",13,10 
        Debug "Address of first string: $", HEX4 Strings, 13 ,10
    
    
    Action: 
        RANDOM  rand 
        StringNumber = rand//20                             ' Select which string to print
        GOSUB findIndex  
        GOSUB PrintString                               ' And, you guessed it, go print it.
        PAUSE 1000
        goto  Action
    END
    
    
    findIndex:
        isa    = Strings
        while StringNumber
            ReadCode isa, CTEMP
            isa=isa+1
            if  CTEMP ==3 then 
                isa=0
                return
            endif
            if (CTEMP.highbyte==0) then  
                StringNumber=StringNumber-1
                if    StringNumber == 0 then  return
            endif
        wend
    return 
    
    
    PrintString: 
        if  isa then
            Debug 13,10
            For i = 0 to 19                                 ' Maximum string length is 20 characters
                ReadCode (isa + i), CTEMP           ' Get a char from string in question.
                Char = (CTEMP>>7) 
                IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
                Debug Char                                   ' Otherwise print it
                Char = CTEMP&$7f        
                IF (Char = 0) THEN EXIT                     ' Break out if char is NULL
                Debug Char                                ' Otherwise print it
            NEXT
        endif
    RETURN
    Name:  Screenshot 2021-09-13 141521.jpg
Views: 1114
Size:  79.6 KB
    Last edited by Ioannis; - 13th September 2021 at 21:59.
    Warning I'm not a teacher

Similar Threads

  1. Any elegant way of text string handling?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd November 2020, 16:21
  2. Replies: 11
    Last Post: - 9th March 2020, 12:37
  3. Serious Help Needed-Tried a Lot & Now I am Here
    By Megahertz in forum Schematics
    Replies: 3
    Last Post: - 17th December 2009, 12:12
  4. Serial problem with a lot of chips
    By The Master in forum Off Topic
    Replies: 1
    Last Post: - 20th October 2007, 12:55
  5. Writing serial data to text file
    By TurboLS in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd March 2005, 22:09

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