pic16f628a experimentos

Upload: cesar-matos

Post on 03-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 PIC16F628A experimentos

    1/11

    Experiment 1. Test Port A Bit 0 ON LED

    First Experiment we will test Port RA by on RA0 that connect to LED the schematic for Experiment 1isshown below in Figure 1

    Figure 1.1schematic for Experiment 1Test ON LED ON Port A Bit 0

    Assemble circuit as figure 1.1 and load Programming to PIC16F628 after that on power supply youwill see result it

  • 8/12/2019 PIC16F628A experimentos

    2/11

    Source Code For Experiment 1

    ;**********************************************************************;

    ; Filename: Experiment 1. Test Port A Bit 0 ON LED

    ;; www.electronics-microcontroller.com;;**********************************************************************

    list p=16f628 ; list directive to defineprocessor

    #include ; processor specific variabledefinitions

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC &_MCLRE_ON & _LVP_OFF

    org 0x000clrf PORTA ; Initial PORTAmovlw 0x07 ; Turn Comparator off andmovwf CMCON ; Enable pins for I/Obsf STATUS,RP0 ; Select Bank 1movlw b'11111110' ; All PORTA = Inputmovwf PORTA ; RA0 = Outputbcf STATUS,RP0 ; Return to Bank 0bcf PORTA,0 ; RA0 = 0 LED "ON"goto $

    END ; end of program

  • 8/12/2019 PIC16F628A experimentos

    3/11

    Experiment 2. Input & Output on Port A

    The Experiment 2 we will test Port A is both Input and Output . Assemble circuit as figure 2.1 andDownload Program to PIC16F628

    Figure 2.1schematic for Experiment 2 Input & Output on Port A

    Assemble circuit as figure 2.1 and Download Programming to PIC16F628

  • 8/12/2019 PIC16F628A experimentos

    4/11

    Source Code For Experiment 2

    ;**********************************************************************;

    ; Filename: Experiment 2. Input & Output on Port A;; www.electronics-microcontroller.com;;**********************************************************************

    list p=16f628 ; list directive to defineprocessor

    #include ; processor specific variabledefinitions

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC &

    _MCLRE_ON & _LVP_OFF

    org 0x000clrf PORTA ; Initial PORTAmovlw 0x07 ; Turn Comparator off andmovwf CMCON ; Enable pins for I/Obsf STATUS,RP0 ; Select Bank 1movlw b'11111111' ; All PORTA = Inputmovwf PORTA ;bcf STATUS,RP0 ; Return to Bank 0btfsc PORTA,0 ; Test Switch Press ?goto $-1 ; If Not Press Loopbsf STATUS,RP0 ; If Press Set RA0 = Output

    bcf PORTA,0 ; TRISAbcf STATUS,RP0 ; Return To Bank 0bcf PORTA,0 ; RA0 = 0 LED "ON"goto $

    END ; end of program

  • 8/12/2019 PIC16F628A experimentos

    5/11

    Experiment 3. Sound Generated

    The Experiment 3 we will Generate sound (one frequency) by use PIC16F628. First of all see TimingDiagram as figure 3.1 for to understand

    Figure 3.1Timing Diagram for Sound Generated

    Assemble circuit as figure 3.2 and load Programming to PIC16F628

    Figure 3.2schematic for Experiment 3 Sound Generated

    Assemble circuit as figure 3.2 and load Program to PIC16F628 . RA4 Connect with PIEZO , TheFrequency can be calculate by formula as below

    f = 1/ T1/(768 uSec + 768 uSec) = 651 Hz

  • 8/12/2019 PIC16F628A experimentos

    6/11

  • 8/12/2019 PIC16F628A experimentos

    7/11

    Experiment 4. Sound Melody

    The previously experiment (Exp 3) we can Generated Sound at one frequency, for this experimentwe will apply Exp 3 to Generated Sound more one frequency like melody

    Assemble circuit as figure 4.1 and Download Program to PIC16F628

    Figure 4.1schematic for Experiment 4 Sound Melody

    Assemble circuit as figure 4.1 and Download Program to PIC16F628

  • 8/12/2019 PIC16F628A experimentos

    8/11

    Source Code For Experiment 4

    ;**********************************************************************;

    ; Filename: Experiment 4. Sound Generated

    ;; www.electronics-microcontroller.com;;**********************************************************************

    list p=16f628 ; list directive to defineprocessor

    #include ; processor specific variabledefinitions

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC &_MCLRE_ON & _LVP_OFF

    COUNT equ 0x20SETTIME equ 0x21

    org 0x000clrf PORTA ; Initial PORTA

    ; output data latchesmovlw 0x07 ; Turn Comparator off andmovwf CMCON ; Enable pins for I/Obsf STATUS,RP0 ; Select Bank 1movlw 0x0F ; RA0-RA3 =Input RA4 = Outputmovwf PORTA ;bcf STATUS,RP0 ; Return to Bank 0

    LOOP1 bsf PORTA,4 ; Start Rising Pulsecall Delay ; Delaybcf PORTA,4 ; Falling Pulsecall Delaybtfsc PORTA,3 ; Test RA3 Pressgoto Check2 ; If No Continue Checkmovlw 0x20 ; If RA3 Press Set Time = 20Hmovwf SETTIMEgoto LOOP1 ; Continue

    Check2 btfsc PORTA,1 ; Test RA1 Pressgoto Check1 ; If No Continue Checkmovlw 0x55 ; If RA1 Press

    movwf TIME ; Set Time = 55Hgoto LOOP1 ; ContinueCheck1 btfsc PORTA,0 ; Test RA0 Press

    goto LOOP1 ; If No Begin Pulse Againmovlw 0x60 ; If RA0 Pressmovwf TIME ; Set Time = 60Hgoto LOOP1 ; Begin Pulse Again

    Delay movf TIME,w ; Delay Use Change Delay Timemovwf COUNT ; With TIME Registerdecfsz COUNT,fgoto $-1return

    END ; of program

  • 8/12/2019 PIC16F628A experimentos

    9/11

    Experiment 5. Stepper Motor Drive

    The Experiment 5 we will test Use PIC16F628 to Drive Stepper Motor, for Article & Types of SteppingMotors you and see links as Resources ,Tools & Related Menu below

    This Experiment use Unipolar Motors 9-24 V 7.5 Degree/Step , and use IC ULN2003 for Drive

    Unipolar Motors IC ULN2003

    Figure 5.1schematic for Experiment 5 Stepper Motor Drive

    Assemble circuit as figure 5.1 and Download Program to PIC16F628 from Figure 5.1 VR 100k use foradjust frequency clock of PIC16F628 when run in mode ER

  • 8/12/2019 PIC16F628A experimentos

    10/11

    Source Code For Experiment 5

    ;**********************************************************************;

    ; Filename: Experiment 5. Stepper Motor Drive

    ;; www.electronics-microcontroller.com;;**********************************************************************

    list p=16f628 ; list directive to defineprocessor

    #include ; processor specific variabledefinitions

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON &_ER_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF

    COUNT equ 0x20DUMMY1 equ 0x21DUMMY2 equ 0x22

    org 0x000 ; Reset Vetor Addressbsf STATUS,RP0 ; Set RB4-RB7 For Drive Stepper Motormovlw b'00001111'movwf PORTBbcf STATUS,RP0

    Begin movlw .12 ; Loop 12 Time For 7.5 Degree/Step 4x12x7.5 =360

    movwf COUNTLoop movlw b'00010000' ; 1 Phase Full Step

    movwf PORTBcall Delay ; Change Delay For Change Speedmovlw b'00100000'movwf PORTBcall Delaymovlw b'01000000'movwf PORTBcall Delaymovlw b'10000000'movwf PORTB

    call Delaydecfsz COUNT,f ; Check Loop = 12 Time ?goto Loop ; If Not Loop Again

    movlw .12 ; Reverse Move 12 Timemovwf COUNT

    Loop2 movlw b'01000000'movwf PORTBcall Delaymovlw b'00100000'movwf PORTBcall Delaymovlw b'00010000'

    movwf PORTBcall Delay

  • 8/12/2019 PIC16F628A experimentos

    11/11

    movlw b'10000000'movwf PORTBcall Delaydecfsz COUNT,f ; Check Loop = Time ?goto Loop2goto Begin ; If Yes Start Again

    Delay movlw 0x20 ; Delay Between Stepmovwf DUMMY1

    Delay1 clrf DUMMY2decfsz DUMMY2,fgoto $-1decfsz DUMMY1,fgoto Delay1return

    END ; of program