Fun Electronics Today

banner copy.jpg

HOME   SWoff.png

Projects   SWon.png

About   SWoff.png

Contact   SWoff.png

 funelectronicstoday/ projects/ asm programming tutorials/

 

 

 

   Fun with a “hello world” type program

 

    For those of you who are fairly new in this assembly programming or ASM, here is a tutorial of how to initialize the ports of a PIC16F microcontroller and blink some LEDs for the beginning.

 

hello world youtube link.jpg

 

The source code is listed below in case you are interested in only copying it. As I mentioned in the video the MCU I used in the video is a PIC16F628, but this code can be adapted to PIC16F818, PIC16F819, PIC16F84 and many more.

 

 

; Hello world basic 16F628 ASM program

 RESET CODE 0x00

 #INCLUDE <P16F628A.inc>

 __CONFIG _HS_OSC & _CP_OFF & _LVP_OFF & _BODEN_OFF & _MCLRE_ON & _PWRTE_OFF & _WDT_OFF

 

 ; THIS PROGRAM WAS DESIGNED FOR 20 MHZ OSC

 ;------------------------------------

 ;_XT_OSC             : EXTERNAL 4MHZ

 ;_HS_OSC             : EXTERNAL 20MHZ

 ;_INTRC_OSC_NOCLKOUT : INTERNAL 4MHZ

 ;------------------------------------

 

 CBLOCK 0X20 ; THIS IS HOW YOU DECLARE A BLOCK OF VARIABLES

    NVAR1, NVAR2

 ENDC

 

 CLRF PORTA ;SET THESE PINS BEFORE YOU ACTUALLY CONFIGURE THEM

 CLRF PORTB

 

 MOVLW 0X07    ; DISABLE THE COMPARATORS AND ENABLING THE PINS FOR

 MOVWF CMCON   ; FUNCTIONING AS I-O

 

BCF STATUS, RP1 ;SETS BANK1

 BSF STATUS, RP0 ;

 

 MOVLW B'00111111' ;SET PINS 0 - 4 AS INPUTS ; TRIS 5 AS 1 ALWAYS 

 MOVWF TRISA

 

 MOVLW 0X00 ;SET PINS 0 - 7 AS OUTPUTS

 MOVWF TRISB

 

 BCF STATUS, RP1 ;SETS BANK1

 BCF STATUS, RP0 ;

 

 

;MAIN LOOP----------------

 

REPEAT

 

 MOVFW PORTA

 MOVWF NVAR1

 

 MOVFW NVAR1

 MOVWF PORTB

 

 GOTO REPEAT ; END OF MAIN LOOP

 

 END

 

 

   Another programming episode. Learn how to write an ASM delay loop

and have fun with blinking some LEDs

 

 

 

asm youtube link.jpg

 

For this second part of the tutorial, the initialization part of the MCU is basically the same.

The entire code of the main loop and of the delay loop is listed below:

 

;MAIN LOOP----------------

 

REPEAT

    MOVLW 0X00

    MOVWF PORTB

    CALL DELAY  

   

    MOVLW 0X01

    MOVWF PORTB

    CALL DELAY

   

    MOVLW 0X02

    MOVWF PORTB

    CALL DELAY

   

    MOVLW 0X04

    MOVWF PORTB

    CALL DELAY

   

    MOVLW 0X08

    MOVWF PORTB

    CALL DELAY

   

    CLRF PORTB

   

    CALL DELAY

    GOTO REPEAT ; END OF MAIN LOOP

   

 

DELAY

    CLRF DELAY1

    CLRF DELAY2

 

DELAYLOOP     

    DECFSZ DELAY2,F

    GOTO DELAYLOOP

   

    DECFSZ DELAY1,F

    GOTO DELAYLOOP

   

    RETURN

 

  

 

Fun Electronics Today ©Marius Taciuc 2016*  |   Public content  | Disclaimer Home                         Going up? ^

*This website and all the information contained in it is the intellectual property of Marius Taciuc. However, the information has a public

shared character and can be used, copied and replicated by everyone for personal use only.

Replicating these hardware parts or using their software for mass production is not permitted without the prior agreement of the designer.