Blink.Bas on 18f45k20 Newbie seeks working example.


Results 1 to 4 of 4

Threaded View

  1. #3


    Did you find this post helpful? Yes | No

    Default Try this

    Hi Discoed

    Try this, I use an 18F4520 as well and this is what I used initially to get an LED blinking.
    The code will cause the LED to go high then pause for 1 second and then go low and pause for one second and then loop forever. Be careful of the blink.bas example since the keyword LOOP is used for the label , however this is now reserved in PBP , so I just use the word LOOPY instead for a loop :-)

    Good luck

    Kind regards

    Dennis

    Code:
    '*********************
    'PIC18f4520 blink prog
    '*********************
    
    'Ocsillator selections here
    'DEFINE OSC 8
    'OSCCON=%01110000
    'or
    'DEFINE OSC 4
    'OSCCON=%01100000
    'OSCTUNE.6 = 0 'PLL Multiplier disabled
    'OSCTUNE.6 = 1 'PLL 4x
    'Ocsillator selections here
            OSCCON = $70            'Int CLK 8MHz
            OSCTUNE.6 = 1           'PLL 4x
            ADCON1= %00001111       '$0F = disable A/D converter
            cmcon   =   7 
            INTCON2.7 = 0     'switch pull-ups ON
            
    'END of oscillator selections
      'timer/oscillator defines 
            DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    
    'Ports
    PORTA=0
    PORTB=0
    PORTC=0
    PORTD=0
    PORTE=0
    'end of port clear
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111       'All pins are inputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 
    'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 'inputs, 
            TRISB = %00000000  'all output
            TRISC = %10000000  'C7 is input (RX) the rest are output
            TRISD = %00000000  'all output
            TRISE.0 = 0	'output
            TRISE.1 = 0	'output
            TRISE.2 = 0	'output
    'End of Port IO directions and presets for port pins begin here
    
    
    'variable defined here
    led var PORTD.0
    'end of variables
    
    'Main code begins here - notice it's called loopy 'cos LOOP is a reserved keyword now
    
    loopy:
    high LED ' First LED on
            Pause 1000       ' Delay for 1 second
    	low led
             Pause 1000       ' Delay for 1 second
    
               Goto loopy  ' Go back to loop and blink LED forever
            End
    Last edited by Dennis; - 29th December 2009 at 03:06.

Similar Threads

  1. blink.bas for 18f4520 for newbie - HELP
    By Dennis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2009, 19:45
  2. Replies: 2
    Last Post: - 13th September 2005, 19:23

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