menu selection


Closed Thread
Results 1 to 7 of 7

Thread: menu selection

  1. #1
    Join Date
    May 2010
    Posts
    21

    Default menu selection

    hi,
    i'm currently working on a menu selection using pic 16f886 and lcd 4x20. my problem is the pic only execute the first subroutine only....here is the code sample

    tx:
    Code:
    @ DEVICE HS_OSC
    define osc  20
    define ADC_bits     10
    define ADC_CLOCK    3
    DEFINE ADC_SAMPLEUS 50
    
            TRISA   = %11111111
            ADCON0  = %00000001
            ADCON1  = %10010000
            suhu1 var word
            suhu2 var word
            dta     VAR WORD
            volt    VAR WORD
            x       var word                                      
    main:
    ADCIN 0,dta             ' ADC port=AN0 
    high portb.0
    suhu1=(dta-215)*13    '215=utk offset sebab start dri 1v bkn start dri 0v
    suhu2=suhu1-5504
    SEROUT2 PORTC.6,84, [" WQ101-ADC:",dta,dec suhu2/100,46,dec2 suhu2,248,67,10]  
    low portb.0
    PAUSE 200
    GOTO main
    rx(menu selection part):
    Code:
    @ DEVICE HS_OSC
    define OSC 20
    DEFINE LCD4X20 1
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 4
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    
    DEFINE HSER_BAUD 9600
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 129
    
    dta var word
    dta1 var word
    led var portb.0
    m var portB.1
    ANSEL = 0          'All Digital, konfigurasi ini utk jadikan semua port
    ANSELH = 0  
    
    push var byte : push = 1
    goto screen1
    
    main: 
        if portB.1=1 then                               'arrow down
            push = push+1 : goto selection : endif
        if portA.1=1 then                               'arrow up
            push = push-1 : goto selection : endif
        pause 5000
        goto main
        
    selection:
        pause 200
        if push=1 then screen1
        if push=2 then screen2
        if push=3 then screen3
        if push=4 then screen4
        if push=5 then screen5
        if push=6 then screen6
        if push=7 then screen7
        if push=8 then screen8
        if push=9 then
            push = 1 : goto screen1 : endif  
        if push=0 then
            push = 8 : goto screen8 : endif
        goto main 
    
    screen1:
        LCDOUT $FE,1,$7E,  "|Mode1|   |Mode5|"    '$7E= ARROW PADA LCD
        LCDOUT $FE,$C0+1,  "|Mode2|   |Mode6|"
        LCDOUT $FE,$94+1,  "|Mode3|   |Mode7|"
        LCDOUT $FE,$D4+1,  "|Mode4|   |Mode8|"
        
        GOSUB TEMP
        GOto MAIN
        
    TEMP:high LED : pause 300
    hserout ["+++"]
        hserin 2000,main,[dta1(0),dta1(1)]
        serout2 portb.2, 16468,[dta1(0), dta1(1)]
        LCDOUT $FE,1,"STATUS: ",DTA1(0),DTA1(1):pause 2000   
        serin2 portc.7,84,[wait(" "),dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15)]
        pause 50
        serout2 portc.5,16468,[dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15),13]
        LCDOUT $FE,$C0,dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15)
        RETURN   
       
    
    screen2: 
        LCDOUT $FE,1,     " |Mode1|   |Mode5|"
        LCDOUT $FE,$C0,$7E,"|Mode2|   |Mode6|"
        LCDOUT $FE,$94+1,  "|Mode3|   |Mode7|"
        LCDOUT $FE,$D4+1,  "|Mode4|   |Mode8|"
        low led 'led off when arrow at mode 2 in LCD
      
        goto main 
            
    screen3:
        LCDOUT $FE,1,     " |Mode1|   |Mode5|"
        LCDOUT $FE,$C0+1,  "|Mode2|   |Mode6|"
        LCDOUT $FE,$94,$7E,"|Mode3|   |Mode7|"
        LCDOUT $FE,$D4+1,  "|Mode4|   |Mode8|"
        goto main
        
    screen4:
        LCDOUT $FE,1,     " |Mode1|   |Mode5|"
        LCDOUT $FE,$C0+1,  "|Mode2|   |Mode6|"
        LCDOUT $FE,$94+1,  "|Mode3|   |Mode7|"
        LCDOUT $FE,$D4,$7E,"|Mode4|   |Mode8|"
        goto main
        
    screen5:
        LCDOUT $FE,1,     " |Mode1|  ",$7E,"|Mode5|"
        LCDOUT $FE,$C0+1,  "|Mode2|   |Mode6|"
        LCDOUT $FE,$94+1,  "|Mode3|   |Mode7|"
        LCDOUT $FE,$D4+1,  "|Mode4|   |Mode8|"
        goto main
    
    screen6:
        LCDOUT $FE,1,    " |Mode1|   |Mode5|"
        LCDOUT $FE,$C0+1, "|Mode2|  ",$7E,"|Mode6|"
        LCDOUT $FE,$94+1, "|Mode3|   |Mode7|"
        LCDOUT $FE,$D4+1, "|Mode4|   |Mode8|"
        goto main
            
    screen7:
        LCDOUT $FE,1,    " |Mode1|   |Mode5|"
        LCDOUT $FE,$C0+1, "|Mode2|   |Mode6|"
        LCDOUT $FE,$94+1, "|Mode3|  ",$7E,"|Mode7|"
        LCDOUT $FE,$D4+1, "|Mode4|   |Mode8|"
        goto main
        
    screen8:
        LCDOUT $FE,1,    " |Mode1|   |Mode5|"
        LCDOUT $FE,$C0+1, "|Mode2|   |Mode6|"
        LCDOUT $FE,$94+1, "|Mode3|   |Mode7|"
        LCDOUT $FE,$D4+1, "|Mode4|  ",$7E,"|Mode8|"
        goto main

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    When the hardware serial port is used with DEFINEs you can not use SERIN2 commands on the same pins. If you do not DEFINE then you can but I do not see where this would be much of an advantage for you.

    So in the Temp routine in the RX code get rid of the HSERIN for starters.
    Then in the SERIN2 command you may want to wait for something other than a blank space. Send a Z or something and wait for that.

    This is the part I am talking about

    *
    Code:
    * hserin 2000,main,[dta1(0),dta1(1)]
    * * serout2 portb.2, 16468,[dta1(0), dta1(1)]
    * * LCDOUT $FE,1,"STATUS: ",DTA1(0),DTA1(1):pause 2000* 
    * * serin2 portc.7,84,[wait(" "),dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15)]
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Default lcd menu

    i have change the port and still the same...
    Code:
    serin2 portc.7,84,[wait("z"),dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15)]
    pause 50
    serout2 portc.5,16468,[dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15),13]
    LCDOUT $FE,1,dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15)

  4. #4
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=NURULHAIZA;90813]i have change the port and still the same...

    I am not sure that this was the answer to your question - the problem is that you are stuck in item 1 of your menu largely because you are polling your buttons for a few microseconds every 5 seconds - not much hope of happening to be pressing at the right time:
    main:
    if portB.1=1 then 'arrow down TAKES A FEW MICROSECONDS
    push = push+1 : goto selection : endif
    if portA.1=1 then 'arrow up
    push = push-1 : goto selection : endif
    pause 5000 'DO NOTHING FOR 5 SECONDS
    goto main
    I suggest you have a much shorter pause (eg PAUSE 50) and it may be more responsive!

    Also it is not clear you have made portB.1 an input - I like to use
    INPUT portB.1
    but you could also use the TRIS register also

    Peter

  5. #5
    Join Date
    May 2010
    Posts
    21


    Did you find this post helpful? Yes | No

    Unhappy menu selection

    guys i have tried everything that you told me...but it still the same....once the rx received data from tx and display it on LCD it will stop there and will not execute the other loop. do i need to change anything at tx?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Let's try to debug this...
    Your code is running to here?
    Code:
    TEMP:
    'SNIP
        LCDOUT $FE,$C0,dta(0),DTA(1),DTA(2),DTA(3),DTA(4),DTA(5),DTA(6),DTA(7),DTA(8),dta(9),dta(10),dta(11),dta(12),DTA(13),DTA(14),DTA(15)
        RETURN
    Then ends up here
    Code:
    main: 
    'ADD LED TO FLASH TO SEE IF IT IS HERE OR DISPLAY "AT MAIN" TO THE LCD 
        if portB.1=1 then                               'arrow down
            push = push+1 : goto selection : endif
        if portA.1=1 then                               'arrow up
            push = push-1 : goto selection : endif
        pause 5000
        goto main
    Then when you get here
    Code:
    selection:
    "DISPLAY THE VALUE OF "push" TO THE LCD
        pause 200
        if push=1 then screen1
        if push=2 then screen2
        if push=3 then screen3
        if push=4 then screen4
        if push=5 then screen5
        if push=6 then screen6
        if push=7 then screen7
        if push=8 then screen8
        if push=9 then
            push = 1 : goto screen1 : endif  
        if push=0 then
            push = 8 : goto screen8 : endif
        goto main
    I have a sneaky suspicion you will need to use >= in place of =
    Does that make sense?
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    Sorry to say but I have tested the menu selection on a simulator and if you change the pause to 50 it works fine (although I would have used a LOOKUP with BRANCHL), but leaving that aside, I suspect you have been naughty with your syntax - you define a word and then treat it like an array. A simple little test of:
    dta = 513
    dta1 = 514
    extra1 = 515
    extra2 =516

    LCDOUT dec dta(0), " ", dec dta(1), " ", dec DTA(2), " ", dec dta(3), " "

    gives this result:
    513 514 515 516
    indicating that
    dta(0) = dta
    dta(1) = the next defined variable etc
    quite unpredicable results - you must define an array and reference it with "square brackets" or better still with the STR expression. Eg:

    Buffer var byte[16]
    HSERIN 1000, tsync, [str Buffer\5]

    Peter
    Last edited by FinchPJ; - 16th June 2010 at 13:10. Reason: spelling correction

Members who have read this thread : 1

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