PIC Hello World

From On-signal: Projects & Research

Jump to: navigation, search
PIC Hello World
PIC Hello World

The assembly code for a simple "Hello world", a 4-led walking-light ("looplicht"), programmed on a PIC 16F628A.


;;; ************************************************************
;;; LED walking light with 4 leds
;;; Arjan Scherpenisse <arjan@scherpenisse.net>, jan 2009
;;; This code is released in the public domain.
;;; ************************************************************

       LIST P=16F628A, R=DEC    ; Use the PIC16F628 and decimal system

	#include "P16F628A.INC"  ; Include header file
	
       __config  _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON

       CBLOCK 0x20             ; Declare variable addresses starting at 0x20
         Loop1,Loop2
       ENDC
;
; -----------
; INITIALIZE
; -----------
;
       ORG    0x000           ; Program starts at 0x000

       CLRF   PORTA           ; Initialize port A
       CLRF   PORTB           ; Initialize port B

       BSF    STATUS,RP0      ; RAM bank 1

       CLRF   TRISA           ; All pins port A output
       CLRF   TRISB           ; All pins port B output

       BCF    STATUS,RP0      ; RAM bank 0
;
; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
       MOVLW    7
       MOVWF    CMCON         ; Comparators off, all pins digital I/O
;
; ----------
; MAIN LOOP
; ----------
;
Main
	BCF     PORTA,0
	BCF     PORTA,1
	BCF     PORTA,2
	BSF     PORTA,3
       CALL    delay

	BCF     PORTA,0
	BCF     PORTA,1
	BSF     PORTA,2
	BCF     PORTA,3
       CALL    delay

	BCF     PORTA,0
	BSF     PORTA,1
	BCF     PORTA,2
	BCF     PORTA,3
       CALL    delay
 
	BSF     PORTA,0
	BCF     PORTA,1
	BCF     PORTA,2
	BCF     PORTA,3
       CALL    delay

       GOTO    Main
;
; ---------------
; DELAY 250 MSEC
; ---------------
;
delay   MOVLW   250
        MOVWF   Loop1
Outer   MOVLW   200
        MOVWF   Loop2
Inner   NOP
       NOP
       DECFSZ  Loop2,F
       GOTO    Inner          ; Inner loop = 5 usec.
       DECFSZ  Loop1,F
       GOTO    Outer
       RETURN

       END
Personal tools