Select Page
Blink code in assembly for PIC18F452
#include <p18f452.inc>

  config OSC = HS
  config BOR = OFF, WDT = OFF, LVP = OFF
  
  cblock ; where varialbls are defined in memory
    count1 ;
    count2
    count3
  endc
  

  org 0x0000

start:
    clrf   TRISC  ; put port C [7:0] outputs 
loop:
    
    setf    PORTC  ; Increment PORT C by 1 so = 2 
    call    delay500	;500mS delay
    clrf    PORTC  ; Increment PORT C by 1 so = 3
    call    delay500
    bra loop   
    
 ; Delay functions
delay500:    ;500mS delay
    movlw   d'10'
    movwf   count3
    bra	    delay
delay100:    ;50mS delay
    movlw   d'1'
    movwf   count3
    bra	    delay
delay: 
    movlw   d'199'
    movwf   count1
delay_loop_outer:
    clrf    count2
delay_loop_inner:
    incf    count2
    bnz	    delay_loop_inner
    incf    count1
    bnz	    delay_loop_outer
    decf    count3
    bnz	    delay_loop_outer
    return
    
    
    
    
  end