The document describes 5 experiments using a PIC16F628 microcontroller. Experiment 1 turns on an LED connected to port A bit 0. Experiment 2 tests port A as both input and output to control an LED. Experiment 3 generates a tone by toggling a pin connected to a piezo buzzer. Experiment 4 builds on this by generating a melody with multiple frequencies. Experiment 5 drives a stepper motor by sequentially energizing its coil pins under microcontroller control. Source code is provided for each experiment.
The document describes 5 experiments using a PIC16F628 microcontroller. Experiment 1 turns on an LED connected to port A bit 0. Experiment 2 tests port A as both input and output to control an LED. Experiment 3 generates a tone by toggling a pin connected to a piezo buzzer. Experiment 4 builds on this by generating a melody with multiple frequencies. Experiment 5 drives a stepper motor by sequentially energizing its coil pins under microcontroller control. Source code is provided for each experiment.
The document describes 5 experiments using a PIC16F628 microcontroller. Experiment 1 turns on an LED connected to port A bit 0. Experiment 2 tests port A as both input and output to control an LED. Experiment 3 generates a tone by toggling a pin connected to a piezo buzzer. Experiment 4 builds on this by generating a melody with multiple frequencies. Experiment 5 drives a stepper motor by sequentially energizing its coil pins under microcontroller control. Source code is provided for each experiment.
The document describes 5 experiments using a PIC16F628 microcontroller. Experiment 1 turns on an LED connected to port A bit 0. Experiment 2 tests port A as both input and output to control an LED. Experiment 3 generates a tone by toggling a pin connected to a piezo buzzer. Experiment 4 builds on this by generating a melody with multiple frequencies. Experiment 5 drives a stepper motor by sequentially energizing its coil pins under microcontroller control. Source code is provided for each experiment.
; Filename: Experiment 1. Test Port A Bit 0 ON LED ; ; www.electronics-microcontroller.com ; ;**********************************************************************
list p=16f628 ; list directive to define processor #include <p16f628.inc> ; processor specific variable definitions
org 0x000 clrf PORTA ; Initial PORTA movlw 0x07 ; Turn Comparator off and movwf CMCON ; Enable pins for I/O bsf STATUS,RP0 ; Select Bank 1 movlw b'11111110' ; All PORTA = Input movwf PORTA ; RA0 = Output bcf STATUS,RP0 ; Return to Bank 0 bcf PORTA,0 ; RA0 = 0 LED "ON" goto $
END ; end of program
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 and Download Program to PIC16F628
Figure 2.1 schematic for Experiment 2 Input & Output on Port A
Assemble circuit as figure 2.1 and Download Programming to PIC16F628
; Filename: Experiment 2. Input & Output on Port A ; ; www.electronics-microcontroller.com ; ;**********************************************************************
list p=16f628 ; list directive to define processor #include <p16f628.inc> ; processor specific variable definitions
org 0x000 clrf PORTA ; Initial PORTA movlw 0x07 ; Turn Comparator off and movwf CMCON ; Enable pins for I/O bsf STATUS,RP0 ; Select Bank 1 movlw b'11111111' ; All PORTA = Input movwf PORTA ; bcf STATUS,RP0 ; Return to Bank 0 btfsc PORTA,0 ; Test Switch Press ? goto $-1 ; If Not Press Loop bsf STATUS,RP0 ; If Press Set RA0 = Output bcf PORTA,0 ; TRISA bcf STATUS,RP0 ; Return To Bank 0 bcf PORTA,0 ; RA0 = 0 LED "ON" goto $
END ; end of program
Experiment 3. Sound Generated
The Experiment 3 we will Generate sound (one frequency) by use PIC16F628. First of all see Timing Diagram as figure 3.1 for to understand
Figure 3.1 Timing Diagram for Sound Generated
Assemble circuit as figure 3.2 and load Programming to PIC16F628
Figure 3.2 schematic for Experiment 3 Sound Generated
Assemble circuit as figure 3.2 and load Program to PIC16F628 . RA4 Connect with PIEZO , The Frequency can be calculate by formula as below
The previously experiment (Exp 3) we can Generated Sound at one frequency, for this experiment we 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.1 schematic for Experiment 4 Sound Melody
Assemble circuit as figure 4.1 and Download Program to PIC16F628
org 0x000 clrf PORTA ; Initial PORTA ; output data latches movlw 0x07 ; Turn Comparator off and movwf CMCON ; Enable pins for I/O bsf STATUS,RP0 ; Select Bank 1 movlw 0x0F ; RA0-RA3 =Input RA4 = Output movwf PORTA ; bcf STATUS,RP0 ; Return to Bank 0 LOOP1 bsf PORTA,4 ; Start Rising Pulse call Delay ; Delay bcf PORTA,4 ; Falling Pulse call Delay btfsc PORTA,3 ; Test RA3 Press goto Check2 ; If No Continue Check movlw 0x20 ; If RA3 Press Set Time = 20H movwf SETTIME goto LOOP1 ; Continue Check2 btfsc PORTA,1 ; Test RA1 Press goto Check1 ; If No Continue Check movlw 0x55 ; If RA1 Press movwf TIME ; Set Time = 55H goto LOOP1 ; Continue Check1 btfsc PORTA,0 ; Test RA0 Press goto LOOP1 ; If No Begin Pulse Again movlw 0x60 ; If RA0 Press movwf TIME ; Set Time = 60H goto LOOP1 ; Begin Pulse Again
Delay movf TIME,w ; Delay Use Change Delay Time movwf COUNT ; With TIME Register decfsz COUNT,f goto $-1 return
END ; of program
Experiment 5. Stepper Motor Drive
The Experiment 5 we will test Use PIC16F628 to Drive Stepper Motor, for Article & Types of Stepping Motors 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.1 schematic for Experiment 5 Stepper Motor Drive
Assemble circuit as figure 5.1 and Download Program to PIC16F628 from Figure 5.1 VR 100k use for adjust frequency clock of PIC16F628 when run in mode ER