You are on page 1of 2

;******************************************************************************; ; Processor: PIC16F628 at 4 MHz using internal RC oscillator ; ; Function : When the circuit is energized two LEDs will turn

on, the power ; ; indicator and LED_D1. Every time the button is pressed the LED_D1 ; ; will turn off and the LED_D2 will turn on, the opposite occurs ; ; when the button is released, turning off the LED_D2 and turning ; ; on the LED_D1 again. ; ; Hardware : Protoboard ; ; Filename : main.asm ; ; Author : Jean J. Míchel <jeanjmichel-at-gmail.com> ; ; Website : http://www.jeanjmichel.blogspot.com ; ; Credit : ; ;******************************************************************************; ; Wiring diagram +-/\/\/--|>|--o GND ; ; +---v---+ | R2 LED_PWR ; ; -<|º 1 |>--+ ; ; -<| 6 |>----/\/\/--|>|--o GND ; ; -<| F |>--+ R3 D1 ; ; -<| 6 |>- | ; ; -<| 2 |>- +-/\/\/--|>|--o GND ; ; -<| 8 |>R4 D2 ; ; -<| A |>; ; -<| |>--+----o¯o----o VDD 5v ; ; +-------+ | R1 ; ; +---/\/\/---o GND ; ;******************************************************************************; #include <p16f628a.inc> list p=16f628a ERRORLEVEL 0, -302;, -224, -302, -305, -207 __config (_INTOSC_OSC_NOCLKOUT & _CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _BODEN_OFF & _MCLRE_OFF) #define #define #define #define #define #define select_bank0 bcf STATUS,RP0 select_bank1 bsf STATUS,RP0 LED_PWR PORTA,1 LED_D1 PORTA,0 LED_D2 PORTA,7 BUTTON PORTB,4 org goto main btfsc goto goto bcf bsf goto bcf bsf goto 0x00 setup BUTTON turn_on_d2 turn_on_d1 LED_D2 LED_D1 main LED_D1 LED_D2 main

;Perform the initial settings

;

;Monitors the action of the button; ;Turns on LED_D2 ; ;Turns on LED_D1 ; ;Turns off LED_D2 ;Turns on LED_D1 ; ;

turn_on_d1

turn_on_d2

;Turns off LED_D1 ;Turns on LED_D2

; ;

setup

select_bank1 movlw B'00000000' movwf TRISA movlw movwf B'00010000' TRISB

;Defines all pins of the PORTA ;registrator as output

; ;

;Defines all pins of the PORTB ; ;registrator as output except the ; ;the pin 4 - push button ; ;Sets 16F628 to operate at 4MHz ;

bsf

PCON, OSCF

select_bank0 movlw 0x07 movwf CMCON

;Turns off the comparator

;

Loop forever .) . . Enjoy! . .Clears all pins of the PORTB . clrf PORTB bsf LED_PWR goto end main .registrator . .Clears all pins of the PORTA .Turns on LED_PWR .power LED .registrator . .clrf PORTA .