quarta-feira, junho 09, 2010

Mais um experimento com PIC 16F628A e Assembly

Seguindo a minha saga pelo mundo dos microcontroladores, hoje fiz mais um exemplo em Assembly usando o PIC 16F628A da Microchip.
 
A brincadeira é permutar entre o acendimento de um ou outro LED via chave táctil.
 
O fluxo do programa é este:
 
Fluxo
 
Aqui estão as imagens da simulação do circuito feita no Proteus:
 
Circuito desligado
Circuito desligado.
 
Circuito ligado
Circuito ligado.
 
Chave pressionada
Chave pressionada.
 
E aqui está o código Assembly:
 
;******************************************************************************;
; 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   select_bank0  bcf STATUS,RP0
#define   select_bank1  bsf STATUS,RP0
#define   LED_PWR  PORTA,1
#define   LED_D1   PORTA,0
#define   LED_D2   PORTA,7
#define   BUTTON   PORTB,4
 
                org       0x00
                goto      setup              ;Perform the initial settings     ;
                
main            btfsc     BUTTON             ;Monitors the action of the button;
                goto      turn_on_d2         ;Turns on LED_D2                  ;
                goto      turn_on_d1         ;Turns on LED_D1                  ;
                
turn_on_d1      bcf       LED_D2             ;Turns off LED_D2                 ;
                bsf       LED_D1             ;Turns on LED_D1                  ;
                goto      main
                
turn_on_d2      bcf       LED_D1             ;Turns off LED_D1                 ;
                bsf       LED_D2             ;Turns on LED_D2                  ;
                goto      main
                
setup           select_bank1
                movlw     B'00000000'        ;Defines all pins of the PORTA    ;
                movwf     TRISA              ;registrator as output            ;
                
                movlw     B'00010000'        ;Defines all pins of the PORTB    ;
                movwf     TRISB              ;registrator as output except the ;
                                             ;the pin 4 - push button          ;
                
                bsf       PCON, OSCF         ;Sets 16F628 to operate at 4MHz   ;
                
                select_bank0
                movlw     0x07
                movwf     CMCON              ;Turns off the comparator         ;
                
                clrf      PORTA              ;Clears all pins of the PORTA     ;
                                             ;registrator                      ;
                
                clrf      PORTB              ;Clears all pins of the PORTB     ;
                                             ;registrator                      ;
                
                bsf       LED_PWR            ;Turns on LED_PWR - power LED     ;
 
 
                goto      main               ;Loop forever ;)                  ;
 
end
 
Enjoy!

Um comentário:

Bráulio disse...

SOU INICIANTE E FOI DE GRANDE AJUDA VALEU