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




Bookmarks