time counter using pic16F84A (need help in checking my code)


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    hmm...
    i have few more questions..

    --- is the define of "TRISB.0= 0" and "TRISB.1= 0" is useless...
    --- should i delete the "RETURN"...
    --- is it suitable to use "IF..THEN...".....how about "FOR...TO...NEXT"
    --- is the define of "OSC 4" is useless...

    thanks for helps..^^

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    1. When you use GOSUB to reach a sub-routine, there should always be a RETURN to get back.

    2. TRIS is not necessary when using the HIGH and LOW commands.

    3. GOTO start at the end of start ensures program execution will loop in start, and not fall through to the routines below it.

    See how this works.
    Code:
    DEFINE osc 4 'using 4MHz oscillator
    
    second VAR BYTE
    'TRISB is not necessary when using the HIGH and LOW commands
    'TRISB.0= 0 ' define portb.0 as output
    'TRISB.1= 0 'define portb.1 as output
    
    start:
    second= second + 1 'count from 0 second..1 second..2 seconds and so on..
    IF second <= 5 THEN
    GOSUB loopa 
    ELSE
    GOSUB loopb
    PAUSE 500
    ENDIF
    GOTO Start
    
    loopa:
    HIGH PORTB.0 'blinking led in portb.0
    PAUSE 500
    LOW PORTB.0
    PAUSE 500
    'GOSUB loopa ' replaced with RETURN
    RETURN
    
    loopb: 
    HIGH PORTB.1 'blinking led in portb.1
    PAUSE 500
    LOW PORTB.1
    PAUSE 500
    'GOSUB loopb ' replaced with RETURN
    RETURN 'return to start and count continuously until switch is switched off
    END
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Aug 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce,

    thanks for your help...i very appreciate it..
    i will program it in my school laboratary later..
    hope that i can get the results..


    Eric...

Similar Threads

  1. Help with Pic Delay code mod please
    By g7jiq in forum General
    Replies: 1
    Last Post: - 26th March 2009, 01:06
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  3. Code snippet: time execution for each line: help please
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th April 2008, 16:46
  4. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 03:55
  5. Time diference in microseconds
    By leonel in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 14th March 2005, 09:25

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