Wednesday 24 October 2012

FYP 2 (WEEK 8)

WEEK 8


Title of Activity

  • Program for PIC and GSM (PART I)


Objective

  • To gain more knowledge from the programming
  • To create a program that suits the project


Content / Procedure


Microcontroller programming concept


;--------------------------PIC/HARDWARE SETTING----------------------

list p=pic16f877a
include p16f877a.inc
    __config 0x1E72
    errorlevel -302    ;Suppress bank warning

;----------------------------------------------------------------------
;VARIABLE DECLARATION
CBlock 0x20
N ; Delay registers.
N1
count1
counta
countb
countc
RXD
FIXDELAY


rxtime1
rxtime2

SMS1Counter ;SMS Alert counter
SMS2Counter
SMS3Counter
SMS4Counter
counter
;----------------------------------------------------------------------------------
org 0xFF
;---------------------I/O SETTING - DEFAULT INITIALIZATION--------------------------
start call initports ; Initialize Ports as output/inputs.
call setupUART
call INITLCD ; Initialize LCD 
call clrscreen ; Clear LCD SCREEN
call DisLCD
call visualdelay
call SECOND_1 ;3s delay before start main program
call SECOND_1
call SECOND_1
movlw d'0'
movwf SMS1Counter
movwf SMS2Counter
movwf SMS3Counter

;Initialize MODEM
;-----------------------------------------------------------------------------------------
bcf RCSTA,CREN ;pulse cren off...
movf RCREG,W ;flush fifo
movf RCREG,W ; all three elements.
movf RCREG,W
call SECOND_1
call SECOND_1
call SECOND_1
movlw A'A'      ;;test communication between microcontroller and GSM MODEM

call transmit
movlw A'T'
call transmit
movlw d'13'
call transmit
movlw d'10'
call transmit
call SECOND_1
call SECOND_1

movlw A'A' ;;set to text mode. 
call transmit
movlw A'T'
call transmit
movlw A'+'
call transmit
movlw A'C'
call transmit
movlw A'M'
call transmit
movlw A'G'
call transmit
movlw A'F'
call transmit
movlw A'='
call transmit
movlw A'1'
call transmit
movlw d'13'
call transmit
movlw d'10'
call transmit

call SECOND_1
call SECOND_1 ;delete SMS in memory 1 (receive SMS)
call Delete1
call clrscreen
call SECOND_1
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bcf PORTD,2 ;Turn off Relay1
bcf PORTD,3 ;Turn off Relay2
bcf PORTD,4 ;Turn off Relay3

bcf PORTD,0
bcf PORTD,1
;------------------MAIN PROGRAM------------------------------------------------

main btfsc PORTA,0 ;Check Vibration
goto NORMAL
goto DETECTED

NORMAL call DisNormal
call SECOND_1
bcf PORTD,2 ;Turn off Relay1
bcf PORTD,3 ;Turn off Relay2
bcf PORTD,4 ;Turn off Relay3
bcf PORTD,0
bcf PORTD,1
movlw d'0'
movwf SMS1Counter
goto main

DETECTED movlw d'3'
movwf counter
Loop1 call SECOND_1
btfsc PORTA,0 ;Check Vibration
goto NORMAL
decfsz counter,1
goto Loop1
call DisWarning
bsf PORTD,2 ;Turn on Relay1
bsf PORTD,3 ;Turn on Relay2
bsf PORTD,4 ;Turn on Relay3
bsf PORTD,0
bsf PORTD,1
call SECOND_1
Loop2 movlw d'12'
movwf counter
Loop3 call SECOND_1
btfsc PORTA,0 ;Check Vibration
goto NORMAL
decfsz counter,1
goto Loop3
call DisWarning2
call SendAlm1
movlw d'1'
movwf SMS1Counter
call SECOND_1
goto Loop2
;----------------------------------------------------------------

Analysis

From the program, what we can say is PIC have 3 parts which is A,B and C . Port A and B are as input while PORT C act as output port. Every single port / pins have to be declare neither it can not function or can not be identified and this will cause the program to failed.


Conclusion

What we can conclude here, it takes a while to generate this program. I take about three days to make sure this program for PART I succeed.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.