Created
April 8, 2014 06:19
-
-
Save bangonkali/10096511 to your computer and use it in GitHub Desktop.
PIC16F877A blinking leds example. Only blinks PORTA.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;******************************************************************************* | |
; Exercise 01 | |
; Description: This program adds a number to the Working register. | |
; Author: Bangon Kali 4/6/2014 | |
;******************************************************************************* | |
;******************************************************************************* | |
; Register file map | |
ADCON1 equ 9fh | |
STATUS equ 03h | |
TRISA equ 85h | |
PORTA equ 05h | |
COUNT1 equ 20h ;First counter for our delay loops (General Purpose Register) | |
COUNT2 equ 21h ;Second counter for our delay loops (General Purpose Register) | |
;******************************************************************************* | |
RP0 equ 05h | |
RP1 equ 06h | |
; Use the org directive to force program start at reset vector | |
org 00h | |
; Program starts here | |
clrw ; Clear the working register | |
BCF STATUS, RP0 ; | |
BCF STATUS, RP1 ; Bank0 | |
CLRF PORTA ; Initialize PORTA by | |
; clearing output | |
; data latches | |
BSF STATUS, RP0 ; Select Bank 1 | |
MOVLW 0x06 ; Configure all pins | |
MOVWF ADCON1 ; as digital inputs | |
MOVLW 0x00 ; Value used to | |
; initialize data | |
; direction | |
MOVWF TRISA ; Set RA<3:0> as inputs | |
; RA<5:4> as outputs | |
; TRISA<7:6>are always | |
; read as '0'. | |
BCF STATUS, RP0 ; Clear | |
BCF STATUS, RP1 ; Bank0 | |
START MOVLW 0xff ; Turn all leds on move to Wreg | |
MOVWF PORTA ; Turn all leds on PORTA | |
MOVLW 0xff | |
MOVWF COUNT1 ; Set Count1 to 0xFF | |
MOVWF COUNT2 ; Set Count1 to 0xFF | |
LOOP1 DECFSZ COUNT1, 1 ; Subtract 1 from 255 | |
GOTO LOOP1 ; If COUNT is Zero then carry on. | |
DECFSZ COUNT2, 1 ; Subtract 1 from 255 | |
GOTO LOOP1 ; Go back to the start of loop. | |
; This delay counts down from 255 to 0 | |
; 255 times. | |
MOVLW 0x00 ; Turn all leds on move to Wreg | |
MOVWF PORTA ; Turn all leds on PORTA | |
MOVLW 0xff | |
MOVWF COUNT1 ; Set Count1 to 0xFF | |
MOVWF COUNT2 ; Set Count1 to 0xFF | |
LOOP2 DECFSZ COUNT1, 1 ; Subtract 1 from 255 | |
GOTO LOOP2 ; If COUNT is Zero then carry on. | |
DECFSZ COUNT2, 1 ; Subtract 1 from 255 | |
GOTO LOOP2 ; Go back to the start of loop. | |
; This delay counts down from 255 to 0 | |
; 255 times. | |
GOTO START | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment