Isnin, 26 Julai 2010

Projek Elektronik = PIC 16F877A Intro


























Projek elektronik

Salam kepada student sekalian
dalam bab ini saya akan memperkenalkan
model PIC yang amat mudah untuk di program..
Tidak seperti PIC lain 16F877/16F877A
merupakan PIC yang mudah di program kerana ia mempunyai 5 port input / output.
Disamping itu juga port A boleh dijadikan sebagai ADC (analog digital converter)

Anda boleh menggunakan PIC ini untuk interface ke beberapa item

Sebagai contoh saya berikan di sini, anda boleh jadikan port A sebagai suis dan port B, port C dan port D sebagai Output, jadi ia telah menjimatkan penggunaan PIC dalam projek anda


COODING CONTOH UNTUK ANDA --projek elektronik--
===================================================================
list      p=16F877A            ; list directive to define processor
#include        ; processor specific variable definitions


__CONFIG   0X3FF2


; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


;================================================================================== 
; VARIABLE DEFINITION
;==================================================================================

D1 EQU 0X20 ;FOR DELAY
D2 EQU 0X21 ;FOR DELAY
D3 EQU 0X22 ;FOR DELAY
COUNT EQU 0X23 ;FOR COUNT THE NO OF LOOPING


;==================================================================================

;==================================================================================
; WRITE YOUR PROGRAM HERE
;==================================================================================

ORG     0x000             ; processor reset vector
   goto    main              ; go to beginning of program


main


; initialize of your PIC, setting the general I/O in TRIS


BSF STATUS,5 ;SWITCH TO BANK1; BIT 5 OF STATUS REGISTER IS SET TO 1
CLRF TRISB ;SET PORTB AS OUTPUT
BSF TRISA,2 ;SET RA2 AS INPUT
BSF TRISA,3 ;SET RA3 AS INPUT
BSF TRISA,4 ;SET RA4 AS INPUT
BCF STATUS,5 ;SWITCH TO BANK0; BIT 5 OF STATUS REGISTER IS SET TO 0


MOVLW B'11111111'
MOVWF PORTB ;SET ALL 8 PIN IN PORTB TO HIGH(1)


;the main program begin here


START
BTFSS PORTA,2 ;check signal at pushbutton1, if press then goto following line, else skip the following line
CALL RED ;button1 pressed, program execute the operation in subroutine RED
BTFSS PORTA,3 ;check signal at pushbutton2, if press then goto following line, else skip the following line
CALL GREEN ;button2 pressed, program execute the operation in subroutine GREEN
BTFSS PORTA,4 ;check signal at pushbutton3, if press then goto following line, else skip the following line
CALL YELLOW ;button3 pressed, program execute the operation in subroutine YELLOW
GOTO START ;no any button being pressed, program keep looping to check the pushbuttons' signal 


RED
MOVLW D'20' ;WRITE A CONSTANT FOR COUNT
MOVWF COUNT ;VALUE OF COUNT
BCF PORTB,6 ;OFF RED LED
CALL DELAY ;DELAY
BSF PORTB,6 ;ON RED LED
CALL DELAY ;DELAY
DECFSZ COUNT ;DECREASE THE VALUE OF COUNT AND SKIP THE NEST LINE WHEN IT REACH ZERO
GOTO $-5 ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 5 LINE ABOVE, WHICH IS OFF THE LED
RETURN


GREEN
MOVLW D'20' ;WRITE A CONSTANT FOR COUNT 
MOVWF COUNT ;VALUE OF COUNT
BCF PORTB,5 ;OFF GREEN LED
CALL DELAY ;DELAY
BSF PORTB,5 ;ON GREEN LED
CALL DELAY ;DELAY
DECFSZ COUNT ;DECREASE THE VALUE OF COUNT AND SKIP THE NEST LINE WHEN IT REACH ZERO
GOTO $-5 ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 5 LINE ABOVE, WHICH IS OFF THE LED
RETURN


YELLOW
MOVLW D'20' ;WRITE A CONSTANT FOR COUNT
MOVWF COUNT ;VALUE OF COUNT
BCF PORTB,4 ;OFF YELLOW LED
CALL DELAY ;DELAY
BSF PORTB,4 ;ON YELLOW LED
CALL DELAY ;DELAY
DECFSZ COUNT ;DECREASE THE VALUE OF COUNT AND SKIP THE NEST LINE WHEN IT REACH ZERO
GOTO $-5 ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 5 LINE ABOVE, WHICH IS OFF THE LED
RETURN

;========================================================================================
; DELAY SUBROUTINE
;========================================================================================


DELAY MOVLW D'180' ;PAUSE FOR ABOUT 10mS (u can change the 180, 100, 1 value to obtain different delay timing)
MOVWF D3
MOVLW D'100'
MOVWF D2
MOVLW D'1'
MOVWF D1
DECFSZ D1
GOTO $-1
DECFSZ D2
GOTO $-5
DECFSZ D3
GOTO $-9
RETURN




    END                     ; directive 'end of program'








by 
projek elektronik









1 ulasan:

  1. salam..boleh bantu tak saya..cara cmna nk bt project mengunakkan pic dan circuit..

    project:heat detector/temperature detector

    input:digital thermometer DS1820 (-55C-125C)
    -reset switch-connect to MCLR pin
    -on/off switch (optional)

    output:LED1-cool(very low temp)<20C yelow
    LED2-low temperature (20-29C) yellow
    LED3-average (30-38C)-white/blue/green
    LED4-High temperature (39-45C)-red
    LED5-very high temperature (>45C)-red

    BalasPadam