Problem runing my code


Closed Thread
Results 1 to 34 of 34

Hybrid View

  1. #1
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    SORRY ITS JUST 7 SEGMENTS NOT LCD..this is the 7segment schema i did draw sorry i havnt draw it good but im sure thats enought to undersnd its normal 7seg working through 74hc164 shift register and 4 digit pins to the pic .atached them all to portb . it works fine with a counter like b0 = b0 +1 to 9999. but i cant add any pause or delay i need to findout how to run my program apart of the 7 segment routing or loop. <<<< ITS LIKE I HAVE A LED BLINK IN A LOOP AND I WANT TO WRITE MY CODE APART AND LET THE LED BLINKIN WITHOUT STOPING EVEN OTHER PROGRAME IS WORKIN AND HAS ITS DELAYS OR NO OR SOME ITS LIKE I WANT TO RUN 2 THINGS IN 1 TIME 2 LOOPS I DONNO IF TIMRERS WILL HELP OR WAT TO WITH THIS BLLODY THINGS LOL >>>>THIS 7SED GODE WORKS OK THE TOP 1 I POSTED BEFOR ISNT WORKING ANYWAY THANK U FOR HELP

    Code:
    @ DEVICE WDT_ON, PWRT_ON,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
          Include "modedefs.bas"
    DEFINE OSC 4
     
    
    intcon = 0		
    vrcon = 0
    CMCON = 7	     
    
    SDO  Var PortB.4
    SCLK Var PortB.5
    BTM  Var PortB.6
    BTN VAR PORTB.7
    SEG var byte 
    Digit var byte[4] 
    index var byte 
    B0 var word
    D0 var byte 
    
    PORTA = %00000
    PORTB = %11000000
    TRISA = %00000
    TRISB = %11000000
    
    B0 = 0
    
    loop:
    
    
    MAIN:
    ''''''''HERE IN THIS LOOP I CANT WRITE PROGRAME WHICH HAS DELAYS.
    '''''' ALL WAT I WANT IS TO LEAV THIS RUNING ITS ROUTING EACH PAUSEUSS999
    ''''''' I WANT TO PUT MY PROGRAME OUT OF THIS LOOP AND SEND WAT I WANT TO SEE ON THE 7SEGMENT TO  B0 VAR 
    if btN = 0 then b0 = b0 - 1
    if btm = 0 then  b0 = b0 +1
    D0 = B0 DIG 0                    
    READ D0,DIGIT[0]
    D0 = B0 DIG 1
    READ D0,DIGIT[1]
    D0 = B0 DIG 2
    READ D0,DIGIT[2]
    D0 = B0 DIG 3
    READ D0,DIGIT[3]
    
    for index = 0 to 3
    seg = digit [index]
    SHIFTOUT SDO,SCLK,0,[SEG\8]
    PORTB.0[index] = 1
    PAUSEUS 999
    PORTB=0
    NEXT INDEX
    
    GOTO MAIN
    
    END
    data @0,3,159,37,13,153,73,65,31,1,9
    Attached Images Attached Images  
    Last edited by Mus.me; - 22nd November 2009 at 23:37.

  2. #2
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Question

    i think none understands my quetion.i want to run like this code ..
    i want both programes to run apart from each other its just example so i can write my programe like this plz help
    Code:
    main:   ' i wa]nt this led to blink  forever without any other delay or stops
    high led
    pause 100    
    low led
    pause 100
    goto main
    
    loop: ' and i want this led1 to blink without any other delay or stop
    high led1
    pause 2000
    low led1
    pause 200
    goto loop

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Thumbs down Processor unability ....

    i want both programes to run apart from each other
    Hi,

    With Pics ... You CAN'T do two things at the same time ( say totally independant things - excluding Peripheral use )

    a Pic does ONE THING AT A TIME ... " Multitasking " just is doing a little part of a task, then a little part of another task, then ...... a little part of the first task, then ....

    very quickly.

    thats ALL !!!

    For your LED Example ... you'd have to use a Pair of "555" as EXTERNAL peripherals, ( HPWM modules are too fast ) to drive your leds .

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    With Pics ... You CAN'T do two things at the same time ( say totally independant things - excluding Peripheral use )

    a Pic does ONE THING AT A TIME ... " Multitasking " just is doing a little part of a task, then a little part of another task, then ...... a little part of the first task, then ....

    very quickly.

    thats ALL !!!

    For your LED Example ... you'd have to use a Pair of "555" as EXTERNAL peripherals, ( HPWM modules are too fast ) to drive your leds .

    Alain
    o right thank u Acetronics for reply.check ur pm . it just confused me this 7 sgment it need the routine in main label each 1 ms, so if i put anythings has delays or like serin it cuz the 7seg delay and blinking slow thats im thinkin to define it like lcd or something to kepp the shift out runing each 1 ms .and do my programe works and has delayes,,,,,,,,,
    Last edited by Mus.me; - 23rd November 2009 at 14:44.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    BUT ...

    I think you could " re write " your project ... showing clearly what you want to do !!!

    refresing your full display @ 200 Hz is not compulsory . 50/60 Hz is a classical value ... that leaves some time in between to do little other tasks ... while a digit is lit ...

    You should Google around For the numerous ( ! ) alarm clock projects on the web ...

    Difficult to help you not knowing what you want to do ....

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    i think none understands my quetion.i want to run like this code ..
    i want both programes to run apart from each other its just example so i can write my programe like this plz help
    You can obtain the two leds flashing at a different interval with a couple of variable:


    Code:
    Dled     Var Byte
    Dled1   var Word
    
    main:   '  led will blink @ 0,1 sec; led1 will be on for 2 secs off for 0,2 sesc
    Pause 1
    
    Dled = Dled + 1
    Dled1 = Dled1 + 1
    
    If Dled =>100 then
    Toggle led
    Dled = 0
    endif
    
    If Dled1 = 1 then high led1
    If Dled1 = 2000 low led1
    If Dled1 =>2200 then Dled1 = 0
    
    
    goto main
    Al.
    All progress began with an idea

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mus.me View Post
    i think none understands my quetion.i want to run like this code ..
    i want both programes to run apart from each other its just example so i can write my programe like this plz help
    Code:
    main:   ' i wa]nt this led to blink  forever without any other delay or stops
    high led
    pause 100    
    low led
    pause 100
    goto main
    
    loop: ' and i want this led1 to blink without any other delay or stop
    high led1
    pause 2000
    low led1
    pause 200
    goto loop
    You might try this:
    Code:
    main:
    For ledvar = 0 to 100
    low led
    pause 100
    high led
    pause 100
    
    next ledvar
    
    low led1
    For ledvar = 0 to 100
    low led
    pause 100
    high led
    pause 100
    
    High LED1
    goto Main
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Angry i solved that code joe thank u for help

    the big problem i have now is to wake up pic 16f628 from sleep using usart interrupt hserin i tested PIR1 it occur but in sleep mode it doesnt occur . i donno i think im runing usart on synchronous slave mode thats what says the datasheet but i donno wheres my problem .my project is to transmet data to pic then wake it up . here is my code .
    Code:
     @ DEVICE WDT_ON, PWRT_OFF,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
          Include "modedefs.bas"
          
    DEFINE OSC 4
    RCSTA=$90'DEFINE HSER_RCSTA 90H
    TXSTA = $20'DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 2400
    DEFINE HSER_SPBRG 25
    'DEFINE HSER_EVEN 1
    'DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    'DEFINE HSER_TIMEOUT 1 ' Clear overflow automatically  
    
    PORTA = %00000
    PORTB = %00000010
    TRISA = %00000
    TRISB = %00000010
    intcon = 0		
    vrcon = 0
    CMCON = 7	     
    j var  BYTE
    led var portb.7
    
    LOOP:
    j = j + 1
    if j = 255 then SLP
    high led2
    HSERIN 10,main,[DEC4 b0]
    
    goto loop
    
    ' here will be  my programe 
    SLP:
    low led
    RCSTA.4=0
     pause 100
    INTCON.6 = 1
    RCSTA.4 = 1
    PIE1.5 = 1
    PIR1.5 = 0
    @ SLEEP
    @ NOP
    PAUSE 1000
    HIGH PORTB.6
    PAUSE 1000
    LOW PORTB.6
    GOTO LOOP
    END
    please help i had read all the usart datasheet and i did what it says but nothings i think the problem in sync slave mode or the osc goes off during sleep or usart not reciving data even i did set it to recive data and interrupt..
    and acetronics says (Alain

    ... and now, just use " Wake up on interrupt " ... as you have the interrupt flag !!! i donno where to put on interupt i trayed it many ways but nothings when it goes to sleep it die just like my nan bless her ..
    Last edited by Mus.me; - 27th November 2009 at 02:14.
    HELLO

  9. #9
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Mus.me, the time you are using to go to sleep it seems to to be too short. You have 2.5 secs available than your micro enter into the sleep process. I would use a word (J VAR WORD) and set at least 20 seconds, otherwise you cannot even read the display.

    Code:
    LOOP:
    j = j + 1
    if j = 255 then SLP '2.5 secs is a too short time use a word 
    high led2
    HSERIN 10,main,[DEC4 b0]
    
    goto loop
    Remove the two long pause in your code (after sleep command) otherwise when micro wakes has to process the two pauses and will loose the Tx data, and will return to sleep.

    Code:
    @ SLEEP
    @ NOP
    PAUSE 1000
    HIGH PORTB.6
    PAUSE 1000
    LOW PORTB.6
    GOTO LOOP
    Al.
    Last edited by aratti; - 27th November 2009 at 08:44.
    All progress began with an idea

  10. #10
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    thank u aratti for reply i think the problem is in usart when pic goes in sleep mode the something aint working to receive data from PC TX , i tryed everythings 3days now but nothings .here where i have the problem, why it doesnt wake up the chip ?? lol
    Code:
    SLP:
    OPTION_REG.7 = 0
    RCSTA.4=0
    pause 100
    INTCON.6 = 1
    RCSTA.4 = 1
    PIE1.5 = 1
    PIR1.5 = 0
    @ SLEEP
    @ NOP
    GOTO LOOP
    sorry for asking to much but i really wants to learn pbp very good im reading the whole datasheet every nights it helps and i get to much help and ideas from this forum thank u everyone
    HELLO

  11. #11
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Post

    Hi Mus.me,

    I think you should turn on global interrupt enable (GIE) bit.
    Code:
    INTCON.7 = 1
    Isn't that the master switch for all interrupts?

    BR,
    -Gusse-

  12. #12
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    this is wat i want to do but the serin cuz the 7seg leds blinkin and not working look at the quote #3 up u will see the schematic and the code to

    Code:
    @ DEVICE WDT_ON, PWRT_ON,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
          Include "modedefs.bas"
    DEFINE OSC 4
     
    
    intcon = 0		
    vrcon = 0
    CMCON = 7	     
    
    SDO  Var PortB.4
    SCLK Var PortB.5
    BTM  Var PortB.6
    BTN VAR PORTB.7
    SEG var byte 
    Digit var byte[4] 
    index var byte 
    B0 var word
    D0 var byte 
    
    PORTA = %00001
    PORTB = %11000000
    TRISA = %00001
    TRISB = %11000000
    
    B0 = 0
    
    loop:
    ''''' i tryed clock  but it cuz problem to 
    ''''if i put here anythings so 7seg doesnt works,,,just blinkin
    
    MAIN:
    serin porta.0,n2400,[],b0  this serin cuzin delays   so the 7seg led blink and 'stops
    if btN = 0 then b0 = b0 - 1
    if btm = 0 then  b0 = b0 +1
    D0 = B0 DIG 0                    
    READ D0,DIGIT[0]
    D0 = B0 DIG 1
    READ D0,DIGIT[1]
    D0 = B0 DIG 2
    READ D0,DIGIT[2]
    D0 = B0 DIG 3
    READ D0,DIGIT[3]
    
    for index = 0 to 3
    seg = digit [index]
    SHIFTOUT SDO,SCLK,0,[SEG\8]
    PORTB.0[index] = 1
    PAUSEUS 999
    PORTB=0
    NEXT INDEX
    
    GOTO MAIN  ' return  not workling????
    
    END
    data @0,3,159,37,13,153,73,65,31,1,9
    [/QUOTE]
    Last edited by Mus.me; - 23rd November 2009 at 19:59.

  13. #13
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink "the" peripheral

    as Serin WAITS for the incoming data ...

    difficult to have a precise timing !!!

    HSERIN offers the USART Rx interrupt flag polling ( doesn't stop the program flow ...) AND BYTE "recording" ...

    with a device showing an USART, of course... but the 628 has an inbuilt USART.

    Soooo ... just use it !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  14. #14
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    WELL THIS IS MY CODE WHEN I CLICK SENT DATA (1234)FROM PC TO PIC16F628. I SEE IT FOR LESS THAN 1 SECOND THEN THE 7SEG GOES OFF TILL I CLICK AGAIN TO SEND I SEE IT JUST BLINK 1234. I DONNO HOW TO USE INTERRUPTS OR STOP HSERIN AND LET THE LOOP WORKING .PLZ HERE I WANT TO SAVE THE HSERIN DATA IN HR VAR AND STAY ON TILL I SENT OTHER DATA TO CHANGE .PLZ HELP ,THANK U...
    Code:
    @ DEVICE WDT_ON, PWRT_ON,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
          Include "modedefs.bas"
    DEFINE OSC 4
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 2400
    DEFINE HSER_SPBRG 25
    DEFINE HSER_EVEN 1
    DEFINE HSER_ODD 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically  
    
    PORTA = %00000
    PORTB = %11000000
    TRISA = %00000
    TRISB = %11000000
    intcon = 0		
    vrcon = 0
    CMCON = 7	     
    
    SDO  Var PortB.4
    SCLK Var PortB.5
    BTM  Var PortB.6
    BTN VAR PORTB.7
    SEG var byte 
    Digit var byte[4] 
    index var byte 
    B0 var word
    D0 var byte 
    MN VAR WORD
    HR VAR word
    
    
    
    MAIN:
    HSERIN [DEC4 hr]
    
    B0 = HR
    D0 = B0 DIG 0                    
    READ D0,DIGIT[0]
    D0 = B0 DIG 1
    READ D0,DIGIT[1]
    D0 = B0 DIG 2
    READ D0,DIGIT[2]
    D0 = B0 DIG 3
    READ D0,DIGIT[3]
    
    for index = 0 to 3
    seg = digit [index]
    SHIFTOUT SDO,SCLK,0,[SEG\8]
    PORTA.0[index] = 1
    PAUSEus 999
    PORTA=0
    NEXT INDEX
    
    goto main
    
    END
    data @0,3,159,37,13,153,73,65,31,1,9
    Last edited by Mus.me; - 24th November 2009 at 03:33.

  15. #15
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Try to make these two correction to your code:

    Code:
    MAIN:
    HSERIN 10,Skip00, [DEC4 hr]
    
    B0 = HR
    D0 = B0 DIG 0                    
    READ D0,DIGIT[0]
    D0 = B0 DIG 1
    READ D0,DIGIT[1]
    D0 = B0 DIG 2
    READ D0,DIGIT[2]
    D0 = B0 DIG 3
    READ D0,DIGIT[3]
    
    Skip00:
    
    for index = 0 to 3
    seg = digit [index]
    SHIFTOUT SDO,SCLK,0,[SEG\8]
    PORTA.0[index] = 1
    PAUSEus 999
    PORTA=0
    NEXT INDEX
    
    goto main
    Al.
    All progress began with an idea

  16. #16
    Join Date
    May 2009
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    THANK YOU ARATTI,Acetronics FOR HELPING ME, I DID THIS IT WORKS GREAT NOW IM PULLING SOME HAIR TO WAKE THE PIC FROM SLEEP WHEN I SEND DATA BUT STILL NOT WORKING YET HERE S MY CODE
    Code:
    @ DEVICE WDT_OFF, PWRT_OFF,MCLR_ON,CPD_OFF, BOD_OFF, PROTECT_OFF,INTRC_OSC_NOCLKOUT
          Include "modedefs.bas"
    DEFINE OSC 4
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 2400
    DEFINE HSER_SPBRG 25
    DEFINE HSER_EVEN 1
    DEFINE HSER_ODD 1
    'DEFINE HSER_TIMEOUT 1 ' Clear overflow automatically  
    
    PORTA = %00000
    PORTB = %00000000
    TRISA = %00000
    TRISB = %00000000
    intcon = 0		
    vrcon = 0
    CMCON = 7	     
    
    SDO  Var PortB.4
    SCLK Var PortB.5
    BTM  Var PortB.6
    BTN VAR PORTB.7
    SEG var byte 
    Digit var byte[4] 
    index var byte 
    B0 var word
    D0 var byte 
    MN VAR WORD
    HR VAR word
    j var byte
    
    b0 = 0
    loop:
    j = j + 1
    if j = 200 then SLP
    HSERIN 10,main,[DEC4 b0]
    MAIN:
    
    D0 = B0 DIG 0                    
    READ D0,DIGIT[0]
    D0 = B0 DIG 1
    READ D0,DIGIT[1]
    D0 = B0 DIG 2
    READ D0,DIGIT[2]
    D0 = B0 DIG 3
    READ D0,DIGIT[3]
    
    for index = 0 to 3
    seg = digit [index]
    SHIFTOUT SDO,SCLK,0,[SEG\8]
    PORTA.0[index] = 1
    PAUSEus 999
    PORTA=0
    NEXT INDEX
    goto loop
    SLP:
    CLEAR
    RCREG = 1
    RCSTA .7=1
    RCSTA.4=1
    RCSTA.5 = 1
    RCSTA.6=1
    TXSTA.7=0
    TXSTA.4=1
    PIE1.5 = 1
    PORTB= %00000001
    
    OPTION_REG = %00000001 'F628 can use  4>7 pins to wake up sleep
    INTCON.1 = 0
    INTCON.4 = 1
    @ SLEEP 
    @ NOP  
    HIGH PORTB.6
    PAUSE 100
    LOW PORTB.6
    CLEAR
    RETURN
    END
    data @0,3,159,37,13,153,73,65,31,1,9
    Last edited by Mus.me; - 25th November 2009 at 14:57.
    HELLO

  17. #17
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink in the end

    Hi, Mus.me

    Took me time to find the thread ...

    have a look here ...

    That is what you're looking for ...

    http://www.picbasic.co.uk/forum/show...28&postcount=2

    best :
    http://www.picbasic.co.uk/forum/show...51&postcount=2


    Alain

    ... and now, just use " Wake up on interrupt " ... as you have the interrupt flag !!!
    Last edited by Acetronics2; - 25th November 2009 at 15:11.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 22:55
  2. 16F883 Code Verify Problem
    By munromh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 12:47
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. problem with my code
    By civicgundam in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd February 2008, 02:52
  5. Code problem
    By chai98a in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th May 2006, 05:43

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