You are on page 1of 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 1is
shown below in Figure 1



Figure 1.1 schematic 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 you
will see result it






















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 define
processor
#include <p16f628.inc> ; processor specific variable
definitions

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

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


















Source Code For Experiment 2


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

; 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

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

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

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






Source Code For Experiment 3

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

; Filename: Experiment 3. Sound Generated
;
; www.electronics-microcontroller.com
;
;**********************************************************************

list p=16f628 ; list directive to define
processor
#include <p16f628.inc> ; processor specific variable
definitions

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

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 b'11101111' ; RA4 = Output
movwf PORTA ; Other = Input
bcf STATUS,RP0 ; Return to Bank 0
Loop1 bsf PORTA,4 ; High RA4 768 usec
call Delay
bcf PORTA,4 ; Low RA4 768 usec
call Delay
goto Loop1 ; Frequency = 1/(768 usec + 768 usec) = 651
Hz

Delay clrf 0x20 ; Delay 768 usec
decfsz 0x20,f
goto $-1
return

END



















Experiment 4. Sound Melody

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































Source Code For Experiment 4

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

; Filename: Experiment 4. Sound Generated
;
; www.electronics-microcontroller.com
;
;**********************************************************************

list p=16f628 ; list directive to define
processor
#include <p16f628.inc> ; processor specific variable
definitions

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

COUNT equ 0x20
SETTIME equ 0x21

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



















Source Code For Experiment 5

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

; Filename: Experiment 5. Stepper Motor Drive
;
; www.electronics-microcontroller.com
;
;**********************************************************************

list p=16f628 ; list directive to define
processor
#include <p16f628.inc> ; processor specific variable
definitions

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

COUNT equ 0x20
DUMMY1 equ 0x21
DUMMY2 equ 0x22

org 0x000 ; Reset Vetor Address
bsf STATUS,RP0 ; Set RB4-RB7 For Drive Stepper Motor
movlw b'00001111'
movwf PORTB
bcf STATUS,RP0

Begin movlw .12 ; Loop 12 Time For 7.5 Degree/Step 4x12x7.5 =
360
movwf COUNT
Loop movlw b'00010000' ; 1 Phase Full Step
movwf PORTB
call Delay ; Change Delay For Change Speed
movlw b'00100000'
movwf PORTB
call Delay
movlw b'01000000'
movwf PORTB
call Delay
movlw b'10000000'
movwf PORTB
call Delay
decfsz COUNT,f ; Check Loop = 12 Time ?
goto Loop ; If Not Loop Again

movlw .12 ; Reverse Move 12 Time
movwf COUNT
Loop2 movlw b'01000000'
movwf PORTB
call Delay
movlw b'00100000'
movwf PORTB
call Delay
movlw b'00010000'
movwf PORTB
call Delay
movlw b'10000000'
movwf PORTB
call Delay
decfsz COUNT,f ; Check Loop = Time ?
goto Loop2
goto Begin ; If Yes Start Again

Delay movlw 0x20 ; Delay Between Step
movwf DUMMY1
Delay1 clrf DUMMY2
decfsz DUMMY2,f
goto $-1
decfsz DUMMY1,f
goto Delay1
return

END ; of program

You might also like