;************************************************************
; Processor: PIC16F628 at 4 MHz using internal RC oscillator
; Function: Flash a LED connected to RA2
; Hardware: Testboard K4
; Filename: 628LED.asm
; Author: Lars Petersen,
oz1bxm@qsl.net
; Website:
www.qsl.net/oz1bxm/PIC/pic.htm
; Credit: Tony Nixon's LED flasher
;************************************************************
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.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
;***** VARIABLE DEFINITIONS
W_TEMP EQU 0X28
STATUS_TEMP EQU 0X29
COUNTERA EQU 0X2A
COUNTERB EQU 0X2B
COUNTERC EQU 0X27
;
; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O
;
; ----------
; MAIN LOOP
; ----------
;
Main BSF PORTA,0 ; Turn on LED connected to RA2 VErmelho 1
BSF PORTA,1 ; Turn on LED connected to RA3 Azul 2
CALL delay
BCF PORTA,1 ; Turn off LED connected to RA3 Azul 2
BSF PORTA,2 ; Turn on LED connected to RA5 VERDE 2
CALL delay
CALL delay
CALL delay
BCF PORTA,2 ; Turn off LED connected to RA5 Verde 2
BSF PORTA,3 ; Liga LED connected to RA5 Amarelo 2
CALL delay
CALL delay
BCF PORTA,3 ; Turn off LED connected to RA5
BCF PORTA,0 ; Turn off LED connected to RA2
BSF PORTB,2 ; Turn on LED connected to RA2 VErmelho 1
BSF PORTB,3 ; Turn on LED connected to RA3 Azul 2
CALL delay
CALL delay
BCF PORTB,3 ; Turn off LED connected to RA3 azul 2
BSF PORTB,4 ; Turn on LED connected to RA5 VERDE 2
CALL delay
CALL delay
CALL delay
BCF PORTB,4 ; Turn off LED connected to RA5 Verde 2
BSF PORTB,5 ; Liga LED connected to RA5 Amarelo 2
CALL delay
CALL delay
BCF PORTB,5 ; Turn off LED connected to RA5
BCF PORTB,2 ; Turn off LED connected to RA2
GOTO Main
;PIC Time Delay = 0.5000000 s with Osc = 4.000000 MHz
delay MOVLW D'3'
MOVWF COUNTERC
MOVLW D'140'
MOVWF COUNTERB
MOVLW D'83'
MOVWF COUNTERA
LOOP DECFSZ COUNTERA,1
GOTO LOOP
DECFSZ COUNTERB,1
GOTO LOOP
DECFSZ COUNTERC,1
GOTO LOOP
RETURN
END
Achei esse codigo na net, funciona perfeitamente. Muito bom para trabalhos de faculdade.
So sobrar um tempo deixo ele mais didatico, mesmo pq ate o final do ano tenho quer apresentar os codigos na faculdade.
O Circuito.
