Week 4
Title of the project: Study programming of PIC
Objective: Make the PIC operate
Content/Procedure:
Study pin i/p and o/p
Define port: A (sensor/heater)
B (LCD display)
C (Switch)
D (DC motor)
Program language:
;===============================================================
;PROJECT TITLE : WASTE TO FERTILIZER CONVERTER
;===============================================================
LIST P=16F877a
ERRORLEVEL -302
ERRORLEVEL -305
#INCLUDE <P16F877a.INC>
__CONFIG 0X3F32
;========================MACRO ==================================
BANK0 MACRO ;CHANGE TO BANK 0
BCF STATUS,RP0
BCF STATUS,RP1
ENDM
BANK1 MACRO ;CHANGE TO BANK 1
BSF STATUS,RP0
BCF STATUS,RP1
ENDM
BANK2 MACRO ;CHANGE TO BANK 2
BCF STATUS,RP0
BSF STATUS,RP1
ENDM
BANK3 MACRO ;CHANGE TO BANK 3
BSF STATUS,RP0
BSF STATUS,RP1
ENDM
CLOCK_E MACRO ;'E' RISE UP N FALL DOWN
BSF PORTD,07
CALL t1m
BCF PORTD,07
CALL t1m
ENDM
;===============================================================
;========== VARIABLE ===========================================
;DATA MEMORY ADDRESS = 20h - 7Fh (BANK0)
; A0h - EFh (BANK1)
; 110h - 16Fh (BANK2)
; 190h - 1EFh (BANK3)
;===============================================================
;===============================================================
;========== RESET VECTOR =======================================
;===============================================================
ORG 00
RESET GOTO INIT
;===============================================================
;========== INTERRUPT VECTOR ===================================
;===============================================================
ORG 04
INT GOTO INIT
;===============================================================
;========== INITIALIAZATION ====================================
;===============================================================
ORG 05
INIT
BANK0 CLRF PORTA
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF PORTE
BANK1 movlw b'00000101' ;PORTA analog input;right justifide;RA3 Vref
movwf ADCON1
movlw b'00011111'
movwf TRISA ;PORTA AS INPUT/OUTPUT
clrf TRISB ;PORTB AS OUTPUT
movlw b'10111111'
movwf TRISC ;PORTC AS INPUT
movlw b'00000000'
movwf TRISD ;PORTD AS INPUT/OUTPUT
movlw b'00000000'
movwf TRISE ;PORTE AS OUTPUT
BANK0
Mulain CLRF PORTB
clrf PORTD
;=============== MAIN PROGRAM START HERE========================
Analysis:
To write a program, student should know the language of the software used and the expectation of circuit operation. In this work, before writing a program it should be define the step operation at input and output PIC. By referring data sheet PIC16F877A and ASM software, student can plan what are step need such as time setting, input sensor, push button and LCD display. It must be properly step setting because PIC cannot read if the wrong instruction given also the operation may be interrupt. In this case, student already done some adjusted of the program because PIC cannot run as expected. So, the program should be modified until it can run as step planning. After complete writing program, it should be compile to check where the wrong of language and if have no problem, it show the program successfully build.
Conclusion:
Writing the programming is the important part in PIC because it functions as heart to giving instruction of circuit operation. So, all the instruction must be properly write depend on step and transmit at pins which make it operate.