Changing declared variables names on the fly


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Thanks Sayzer

    Hi Sayzer,

    Yes I found Melanie's thread a while back and I even wrote a short simple program to try and understand it better. I got the program to turn on an led whenever the bits equaled 1 and to shut it off when 0 and with the press of a button the sequence changes but I couldn't figure an application for it in any of my programs. I'd still be interested in hearing Dave's concept as it seems he can see an application that's beyond my comprehension and I'm eager to learn that.

    Thanks for your explanation of the eepron and it does make sense to me for that part now. I did read the manual but couldn't make any real sense of it. This is just a hobby for me, I haven't had any courses or schooling on programming or electronics so I take it slowly. Now that I'm semi retired I've started to spend more time with electronics and programming and I find it very rewarding.

    Thanks for your help and the links
    jessey


    Code:
    Select_Push_Button   VAR PORTB.7          '(pin 40)  1st
    Hours_Push_Button VAR PORTD.2             '(pin 21)  2nd  
    Minutes_Push_Button var PORTB.0           '(pin 33)  3rd  
    Seconds_Push_Button var PORTB.1           '(pin 34)  4th                 
    Toggle_Push_Button var PORTB.2            '(pin 35)  5th 
    
    
    A VAR BYTE
    A = 0
    MyWord var word
    MyWord = %1010101010101010
    MyByte Var word
    MyVar var word
    MyBit var BIT
    Reference_Word  VAR WORD
    Reference_Word1 VAR WORD
    Reference_Word2 VAR WORD
    Reference_Word3 VAR WORD
    Reference_Word  = 1010
    Reference_Word1 = 1010
    Reference_Word2 = 1010
    Reference_Word3 = 1010
    Is_Pressed CON 0
    
    
          GOTO mainloop
    
    Sound_Buzzer:
          PWM Buzzer,250,1
    RETURN
    
    PAUSE_100:
          PAUSE 100
    RETURN     
    
    
     mainloop:
     Show_Print:
     For MyVar=0 to 15
       MyBit=MyWord.0(MyVar)
       LCDOut $FE,1,"Bit ",DEC MyVar,"=",DEC MyBit
       LCDOut $fe,$c0,$fe,$0e,dec Reference_Word,DEC Reference_Word1, _
                         DEC Reference_Word2,DEC Reference_Word3
       if a = 1 then Return_To_Push_Button_1
       if a = 2 then Return_To_Push_Button_2
       if a = 3 then Return_To_Push_Button_3
       if a = 4 then Return_To_Push_Button_4
       if a = 5 then Return_To_Push_Button_5
       IF MyBit = 1 then
        HIGH LED
        PAUSE 1000             
       ELSE
        LOW LED
        PAUSE 1000
       ENDIF
    
       IF Select_Push_Button = Is_Pressed then ' #1 
        GOSUB Sound_Buzzer : A = 1  
        MyWord = %1100110011001100
        Reference_Word  = 1100
        Reference_Word1 = 1100
        Reference_Word2 = 1100
        Reference_Word3 = 1100
        MyVar = 0
        IF A = 1 THEN Show_Print
        Return_To_Puch_Button_1:
        A = 0
        WHILE Select_Push_Button = Is_Pressed : GOSUB PAUSE_100 : WEND
        IF MyVar = 0 THEN MAINLOOP
       ENDIF
    
       IF Hours_Push_Button = Is_Pressed then ' #2
        GOSUB Sound_Buzzer : A = 2  
        MyWord = %1110111011101110
        Reference_Word  = 1110
        Reference_Word1 = 1110
        Reference_Word2 = 1110
        Reference_Word3 = 1110
        MyVar = 0
        IF A = 2 THEN Show_Print
        Return_To_Puch_Button_2:
        A = 0
        WHILE Hours_Push_Button = Is_Pressed : GOSUB PAUSE_100 : WEND
        IF MyVar = 0 THEN MAINLOOP
       ENDIF
    
       IF Minutes_Push_Button = Is_Pressed then ' #3
        GOSUB Sound_Buzzer : A = 3 
        MyWord = %1101101111001001
        Reference_Word  = 1101
        Reference_Word1 = 1011
        Reference_Word2 = 1100
        Reference_Word3 = 1001
        MyVar = 0
        IF A = 3 THEN Show_Print
        Return_To_Puch_Button_3:
        A = 0
        WHILE Minutes_Push_Button = Is_Pressed : GOSUB PAUSE_100 : WEND
        IF MyVar = 0 THEN MAINLOOP
       ENDIF
        
       IF Seconds_Push_Button = Is_Pressed then ' #4
        GOSUB Sound_Buzzer : A = 4  
        MyWord = %1010100110101001
        Reference_Word  = 1010
        Reference_Word1 = 1001
        Reference_Word2 = 1010
        Reference_Word3 = 1001
        MyVar = 0
        IF A = 4 THEN Show_Print
        Return_To_Puch_Button_4:
        A = 0
        WHILE Seconds_Push_Button = Is_Pressed : GOSUB PAUSE_100 : WEND
        IF MyVar = 0 THEN MAINLOOP
       ENDIF
    
       IF Toggle_Push_Button = Is_Pressed then ' #5 
        GOSUB Sound_Buzzer : A = 5 
        MyWord = %1111101110101101 
        Reference_Word  = 1111
        Reference_Word1 = 1011
        Reference_Word2 = 1010
        Reference_Word3 = 1101
        MyVar = 0
        IF A = 5 THEN Show_Print
        Return_To_Puch_Button_5:
        A = 0
        WHILE Toggle_Push_Button = Is_Pressed : GOSUB PAUSE_100 : WEND
        IF MyVar = 0 THEN MAINLOOP
       ENDIF 
     Next MyVar
    
     GOTO mainloop
     end

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Jessey,

    "There are many ways to skin a cat"; for some "a dog", "a snake", etc...

    Someone writes a code in his/her logic and it works with no problem.
    Someone else writes a different code in a different logic and it also works and does the same job with no problem.

    A third one writes a code in much shorter and faster way, it does the same job and works with no problem, too.

    Now, since you are starting to programming, I suggest you skip the arrays at first and write long lines instead .

    If you start your coding with arrays at the beginning, I see more complexity and confusion in front of you.

    So when it comes to your code and project, there are of course several ways to do the same job in relatively less lines with arrays and some advanced coding techniques.

    But why now?

    -----------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. changing osc on the fly
    By viewgsm in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th February 2010, 15:13
  2. Mode changing on the fly
    By Angus Anderson in forum GSM
    Replies: 1
    Last Post: - 28th November 2006, 08:58
  3. edit names of variables
    By mischl in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th January 2005, 21:00

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