blinking LED


Closed Thread
Results 1 to 15 of 15

Thread: blinking LED

  1. #1
    Join Date
    Jul 2009
    Posts
    15

    Default blinking LED

    Hi..
    By using PICBASIC PRO and PIC16F84a how I can make this:
    Port a.1 high for 6 sec & in the same time porta.0 blinking ???

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    	CounterA var Byte
    
    	LEDA var PortA.0
    	LEDB var PortA.1
    
    	Low LEDA
    	Low LEDB
    
    Start:
    	High LEDB			' PortA.1 goes High
    	For CounterA=1 to 6		' For Six seconds
    		Gosub BlinkyOne		' Whilst Blinky blinks
    		Next CounterA
    	Low LEDB			' PortA.1 then goes LOW
    EndLoop:				' and Blinky continues forever
    	Gosub BlinkyOne			
    	Goto EndLoop			' until you get bored and switch off
    
    	'
    	'	Subroutine Blinks LEDA across 1 Second
    	'	--------------------------------------
    BlinkyOne:
    	High LEDA
    	Pause 500
    	Low LEDA
    	Pause 500
    	Return
    C'mon Guys... lets have another five different ways of doing this... then all the students who are using this forum for answers to their homework assignments can each have a different method and not be accused of copying...

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Code:
    	CounterA var Byte
    
    	LEDA var PortA.0
    	LEDB var PortA.1
    
    	Low LEDA
    	Low LEDB
    
    Start:
    	High LEDB			' PortA.1 goes High
    	For CounterA=1 to 6*2		' For Six*2    half seconds
    		Gosub BlinkyHalf		' Whilst Blinky blinks
    	Next CounterA
    	Low LEDB			        ' PortA.1 then goes LOW
            pause 10000           ' a 10 second gap and then go blinkety blink
    EndLoop:
    	Gosub BlinkyHalf			
    	Goto EndLoop			' until you get bored and switch off
    
    	'
    	'	Subroutine Blinks LEDA across 1 Second
    	'	--------------------------------------
    BlinkyHalf:
    	Toggle LEDA
    	Pause 500
    	Return
    Melanie, I hope you don't mind me using my brain to mod your code. However, as you have it, it is a variation of blinky. More to come ??


  4. #4


    Did you find this post helpful? Yes | No

    Default

    Blinkcounter var byte
    clear

    start:
    High porta.1 'high port
    high porta.0 'on led
    pause 500
    low porta.0 'off led
    pause 500
    let blinkcounter = (blinkcounter + 1)
    if blinkcounter < 6 then start
    low porta.1
    low porta.0
    pause 1000
    goto start 'keep it going

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


    Did you find this post helpful? Yes | No

    Default

    untested . . .
    Code:
    PortA = %00000000
    TrisA = %00000000
    i var byte
    Start:
    PortA.1 = 1
    while PortA.1 = 1
    For i = 0 to 5
    portA.0 = 1
    pause 500
    PortA.0 = 0
    pause 500
    next i
    portA.1 = 0
    wend
    
    end
    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.

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


    Did you find this post helpful? Yes | No

    Default

    I know, wrong chip and wrong pins... it is what I have on the bench...
    Code:
    '18F6680'07/14/09'BLINKY
       
        DEFINE OSC 20
        @ __CONFIG    _CONFIG1H, _OSC_HS_1H
        @ __CONFIG    _CONFIG2H, _WDT_ON_2H &amp; _WDTPS_128_2H
        @ __CONFIG    _CONFIG4L, _LVP_OFF_4L
        CNT VAR BYTE
        FIRST6:HIGH PORTB.2 'SLOW
        FOR CNT = 1 TO 60:TOGGLE PORTG.4:PAUSE 100
        NEXT CNT:LOW PORTB.2:PAUSE 500:GOTO SECOND6
        
        SECOND6:HIGH PORTB.2   'FAST BLINK--REALLY FAST
        PWM PORTG.4,5,6000
        LOW PORTB.2:PAUSE 500:GOTO [color=#0000FF][b]FIRST6
    Last edited by mackrackit; - 8th April 2011 at 06:11. Reason: HTML to BB
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    PortA = 0
    TrisA = 0
    
    Seconds var Byte
    
    LED_1      var PortA.0
    LED_2      var PortA.1
    
    Loop:
    'Your gosub comand goes here
    Goto Loop
    
    
    Blink:
    High Led_1
    Seconds = 0
    While Seconds <>5
    High Led_2
    pause 500
    Low Led_2
    pause 500
    Seconds = Seconds + 1
    wend
    Low Led_1
    Return
    
    End
    Here my contribution.

    Al.
    All progress began with an idea

  8. #8
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    how about the easiest one out there:

    Code:
    Start:
    
    High Porta.1
    
    High porta.0
    Pause 500
    Low Porta.0
    Pause 500                       '1 second
    
    High porta.0
    Pause 500
    Low Porta.0
    Pause 500                       '2 seconds
    
    High porta.0
    Pause 500
    Low Porta.0
    Pause 500                        '3 seconds
    
    High porta.0
    Pause 500
    Low Porta.0
    Pause 500                       '4 seconds
    
    High porta.0
    Pause 500
    Low Porta.0
    Pause 500                       '5 seconds
    
    High porta.0
    Pause 500
    Low Porta.0
    Pause 500                       '6 seconds
    
    Low Porta.1
    pause 1000
    
    goto start
    it might not be the smallest in code size, but it will work and its really easy to understand!!!

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


    Did you find this post helpful? Yes | No

    Default

    Here is mine.

    No PAUSE used !
    Code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON ,BOD_OFF,LVP_OFF
    
    TRISA=0
    TRISB=0
    CMCON=7               ' PortA=digital I/O
    PAUSE 1
    VRCON=0
    PAUSE 1
    
    PORTA=0
    PORTB=0
    
    T1CON=%00110001       ' 0.524ms
    TMR1IF VAR PIR1.0       ' Overflow bit of Timer1.
    
    Output1 VAR PORTA.1     ' Blink 6secs.
    Output2 VAR PORTA.0     ' Blink 0.5secs.
    
    PreLoad     VAR WORD
    TimeCount   VAR BYTE
    TimetoBlink VAR BYTE
    
    PreLoad=3036 ' to get 500ms.
    TMR1L=PreLoad.LowByte
    TMR1H=PreLoad.HighByte
    
    TimeCount=0
    TimetoBlink=12 '12=6secs.
    
    PAUSE 50         ' OSC to Settle.
    
    
    Start:
    
    
       IF TMR1IF THEN Blink
    
       GOTO Start
        
        
    
    Blink: 'Each int is 0.500 sec.
        TMR1L=PreLoad.LowByte   ' Load the timer with preload value.
        TMR1H=PreLoad.HighByte
        TimeCount=TimeCount + 1 ' Count interrupts.
        Output2=Output2 ^ 1     ' Toggle fast blinking output.    
    
        IF TimeCount=TimetoBlink THEN '6Secs ON, 6secs OFF.
          TimeCount=0                   
          Output1=Output1 ^ 1 
        ENDIF
       
        TMR1IF=0                ' Clear TMR1 int. flag.  
        
        GOTO Start    
        
    END    
    
    Last edited by mackrackit; - 8th April 2011 at 06:07. Reason: HTML TO BB
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  10. #10
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    untested . . .
    Code:
    PortA = %00000000
    TrisA = %00000000
    i var byte
    Start:
    PortA.1 = 1
    while PortA.1 = 1
    For i = 0 to 5
    portA.0 = 1
    pause 500
    PortA.0 = 0
    pause 500
    next i
    portA.1 = 0
    wend
    
    end

    Hi..
    Thanks for all
    I test your code and its working fine but because I am new with picbasic what dose this meen
    PortA = %00000000
    TrisA = %00000000
    When I remove this tow lines the code not working,
    Best regard

  11. #11
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    PORTA = %00000000 read this as PORTA gets bits 00000000
    This means, write 0 to each bit position of PORTA. Each 0 represents the bits in PORTA from bit 7 to bit 0. You could also write it as
    PORTA = $00 read this as PortA gets Hex 0

    TRISA = %00000000
    This is the tristate register which tells your PIC to allow the values of PORTA to 'drive' the external world circuits. Same as above for the bit position part. If you set any 1 position to 1, that position will only be able to read (INPUT) from the external circuit.

    Clear now? Don't hesitate to ask. See how many responses you got.

  12. #12
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default A slight modification to Sayzer's code

    I am looking for a way to change the rate of blink (Blinking rate) using Interrupt. I would read a POT using ADC and then change the blink rate, Any idea how I could impliment it in Sayzer's code.

    Thanks.

    p.s. maybe using TMR0

  13. #13
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    A question for you first... why do you specify using INTERRUPT?

  14. #14
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    Cause, I want to use it in a code where I am doing some other things like reading ADC channel , and monitoring inputs , while the led is blinking.

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    You may want to look at this. Post #2 might be of interest.
    http://www.picbasic.co.uk/forum/showthread.php?t=3251
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 06:19
  2. Blinking an led problem on P16F84
    By aimenbukharie in forum General
    Replies: 1
    Last Post: - 20th March 2009, 05:00
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. simple LED Blinking project
    By koossa in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th December 2004, 01:25

Members who have read this thread : 2

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