beginer help needed


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2014
    Location
    Pakistan
    Posts
    19

    Default beginer help needed

    hello
    I am beginer and practicing small codes so here is a code and i need help about it
    --------------------------------
    define osc 4
    Trisb =%01111111
    do
    high portb.7
    pause 300
    low portb.7
    pause 300
    loop until portb.2 = 0
    ---------------------------
    when i run this code led on start blinking but when i press button and make portb.2 low then operation of led should stop but it doesent stop ,it keep blinking whether there is 1 or 0 at portb.0
    what is wrong this code and how to correct it please guide me thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: beginer help needed

    Hi,
    Which PIC are you using?
    It probably has some analog function on PortB.2 so you need to set it to digital mode.

    Another thing is that it might do exactly what you want it to do. But when the Until PortB.2=0 evaluates true you don't do ANYTHING so the program continues into empty space and then start over, try:
    Code:
    ...
    ...
    loop until portb.2 = 0
    LOW PortB.7
    END
    Also, remember that define is case sensitive so it should be define OSC 4. In this case it doesn't really matter since 4MHz is the default anyway but try to remember that.

    /Henrik.

    EDIT: What exactly is the reason for posting the exact same question twice? You've already received an answer in the other thread....
    Any moderator care to delete or join threads?
    Last edited by HenrikOlsson; - 19th March 2014 at 16:15.

  3. #3
    Join Date
    Mar 2014
    Location
    Pakistan
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: beginer help needed

    thankyou sir ur reply was helpful, i have another question to ask, my device is pic 16f72 and port b is digital
    when a programm run in a loop how can i intrrupt it for example
    main:
    high portb.7
    pause 100
    low portb.7
    pause 100
    goto main
    ------
    now this loop keep repeating how can i intrrupt this loop ? if i write like this
    main:
    high portb.7
    pause 100
    low portb.7
    pause 100
    goto main
    if portb.2=0 then
    portb.7 = 0
    endif
    ------------
    intrrupt here doesnt work what is the way out to get out of the loop now

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: beginer help needed

    main:
    high portb.7
    pause 100
    low portb.7
    pause 100
    if portb.2=0 then goto EXIT 'test for exit 1 time for each loop
    goto main
    EXIT:
    portb.7 = 0
    remaining code goes here...........


    OR
    main:
    high portb.7
    if portb.2=0 then goto EXIT 'test for exit after setting port pin high
    pause 100
    low portb.7
    if portb.2=0 then goto EXIT 'test for exit after setting port pin low
    pause 100
    goto main
    EXIT:
    portb.7 = 0
    remaining code goes here...........
    Last edited by Dave; - 20th March 2014 at 11:02.
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: beginer help needed

    Hi,
    There are several ways of doing it.
    One way is to actually use a hardware interrupt, another way is to simply poll the input periodically as you go thru the loop. Yet another way is to move away from the loop structure and use a state machine aproach instead. Instead of using PAUSE, which "blocks" the processor, you can use hardware timers, either with interrupts or by simply polling the interrupt flag. It really depends on what you want to do and how fast you need to do it.

    If all you want to do is blink the LED untill an input goes high (or low) then you basically had it in the first example you posted. The drawback there is that the input is only checked once per iteration thru the loop so if the PAUSE is long there will be a long "reaction time".

    As you see there's not a single answer to your question, it all depends....

  6. #6
    Join Date
    Mar 2014
    Location
    Pakistan
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: beginer help needed

    Oh thanks a lot ,too many puzzeles have been solved in my mind with this answer of yours ,i m really feeling like i have jumped from beginner level to 5 steps ahead thanks again, i have an electronics desin of a ups circuit and i am only asking questions related to it ,now the next part of my question is that this pic16f72 generates an AC volt pulse at two of its pins at 50 hrtz , i want to know the command for doing this ,another thing that how can i make two output pins to opposite of one another ,for example if i take porb.0 and portb.1 , if one port is equal to 1 then other should automatically become equal to 0 and vice versa ,

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: beginer help needed

    Hi,
    Oh man, not again.....
    What is with this inverter/VFD/UPS stuff, it seems to be a common "beginner project" around here, yet it's NOT (I repeat NOT) a simple project, I don't get it.
    Is it possible that this is a school assignment at a certain class/school somewhere and whoever gets assigned the project "this year" always ends up here?

    Anyway, as before, there are several ways of making the PIC output a frequency.
    Generally speaking using a PIC with a CCP or ECCP or even PCPWM module is the way to go for these sort of things. The PWM feature of the these modules can often, but not always, be configured in half bridge mode. The 16F72 does not have this feature.

Similar Threads

  1. PBP 3.0 really needed?
    By Mugelpower in forum FAQ - Frequently Asked Questions
    Replies: 30
    Last Post: - 17th December 2017, 19:19
  2. Beginer problems
    By luxornet in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th February 2010, 04:55
  3. Beginer Help!
    By MINHLE in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 5th July 2008, 03:57
  4. Help Needed
    By Bizhub in forum General
    Replies: 1
    Last Post: - 30th June 2007, 20:18
  5. Help needed to troubleshoot
    By ssocs45 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th February 2004, 18:00

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