ash87
Newbie level 4
hi im using PIC16C745 in assembly language with MPLAB..
I have this GSM modem which the output is connected to the PIC pin 6 (RA4) and the Modem input to PIN5 (RA3).. when the GSM modem is "ON" (connected to GND) it will turn on the LED (RB7) and the RTC will start counting 1hr immediately..after the 1hr the PIC will send a signal from PIC RA3 to the modem input..and start counting 1hour again..
but nothing seem working
THis is my very first time writing this code, and learning it in oni a few weeks.. so i reli need help!
I have this GSM modem which the output is connected to the PIC pin 6 (RA4) and the Modem input to PIN5 (RA3).. when the GSM modem is "ON" (connected to GND) it will turn on the LED (RB7) and the RTC will start counting 1hr immediately..after the 1hr the PIC will send a signal from PIC RA3 to the modem input..and start counting 1hour again..
but nothing seem working
THis is my very first time writing this code, and learning it in oni a few weeks.. so i reli need help!
Code:
;-----------------REAL TIME CLOCK--------------------------------------------
START1
CALL WRITE_EN
MOVLW 0X8E
MOVWF REGWRITE
CALL WRITE_RTC
MOVLW 0 ; CONTROL REGISTER
MOVWF REGWRITE
CALL WRITE_RTC
;*******************************
CALL WRITE_EN
MOVLW 0X80
MOVWF REGWRITE
CALL WRITE_RTC
MOVF SEC,W ; SEC
MOVWF REGWRITE
CALL WRITE_RTC
;*******************************
CALL WRITE_EN
MOVLW 0X82
MOVWF REGWRITE
CALL WRITE_RTC
MOVF MIN,W ; MIN
MOVWF REGWRITE
CALL WRITE_RTC
;*******************************
CALL WRITE_EN
MOVLW 0X84
MOVWF REGWRITE
CALL WRITE_RTC
MOVF HR,W ; HR
MOVWF REGWRITE
CALL WRITE_RTC
;*********************************
; CALL WRITE_EN
; MOVLW 0X8A
; MOVWF REGWRITE
; CALL WRITE_RTC
; MOVF DAY,W ; DAY
; MOVWF REGWRITE
; CALL WRITE_RTC
;*********************************
BCF CE ;The reset signal of the RTC must be asserted high during a read or a write.
; CLRF PORTB
; THIS FUNCTION IS TO CHECK THE VALUE OF "w" by looking at the LED and a buzz means end of this function
; MOVWF TEST
; MOVWF TEST2
;HAHA
; BSF PORTB,6
; CALL DELAY1
; BCF PORTB,6
; CALL DELAY1
; DECFSZ 0X57
; GOTO HAHA
; BSF PORTB,7
; CALL DELAY1
; BCF PORTB,7
; CALL DELAY1
; MOVF TEST,W
Start
clrf PORTB ; clear PORTB output latch
clrf PORTA ; Clear PORTA output latch
movlw b'00000000' ; Set all pins PORTB as output
movwf TRISB
movlw b'00010000' ; Set RA4 as Input port,and the rest as output
MOVWF TRISA
ON
btfsc PORTA,4 ; Is GSM output ON?
goto ON ; No, go back check again
goto SMS_1HRON
; movf Tempholding,0
;----------------CHECK INTERVAL-----------------------------
SMS_1HRON ; turn on the LED for 1 hour
call READ_MIN
movf TIME_TEMP,W
movwf smstime_min ; store the minute first to compare
;later
bsf PORTB,7 ; turn on RB7 (LED) only!
SMS_1HR
call SMS_TIME
SMS_1HRLOOP
call READ_HR
movf TIME_TEMP,w
subwf SMS_TIME,0 ; substract current HR with
;HR you got from CALL SMS_TIME
btfss STATUS,Z ; if result is zero skip to the next
;instruction
goto SMS_1HRLOOP
bcf STATUS,C
SMS_MINLOOP
CALL READ_MIN ; Compare minute after hour
movf TIME_TEMP,w
subwf smstime_min,0 ; Substract Current MIN with MIN you
;got from CALL smstime_min
btfss STATUS,Z
goto SMS_MINLOOP
bcf STATUS,C
goto Start1
Start1
clrf PORTA ; clear PORTA output latch
movlw b'00010000' ; Set RA4 as Input port,and the rest as output
MOVWF TRISA
bsf PORTA,3 ; Set RA3 and Send signal '1' to modem input
goto SMS_1HRON
SMS_TIME
bcf STATUS,C
call READ_HR
movf TIME_TEMP,W
sublw 0x47
btfsc STATUS,Z
goto time47
bcf STATUS,C
movf TIME_TEMP,W
sublw 0x33
btfsc STATUS,Z
goto time47
bcf STATUS,C
movf TIME_TEMP,W
sublw 13
btfsc STATUS,Z
goto time13
goto posresult
time47 ; hour is at 23 which is 47h
movlw 0x01 ; Next hour of 23 is 0hour which is 01h
movwf SMS_TIME
RETURN
time33 ; hour is at 19
movlw 0x41
movwf SMS_TIME
RETURN
time13
movlw 0x21 ; hour is at 9
movwf SMS_TIME
RETURN
posresult
movf TIME_TEMP,w
movwf SMS_TIME
incf SMS_TIME,1
incf SMS_TIME,1
RETURN
;-------------END OF CHECK INTERVAL----------------------------------------------
READ_HR
CALL WRITE_EN
MOVLW 0X85 ;READ HOUR
movlw REGWRITE
call WRITE_RTC
bsf STATUS,RP0
movlw b'00000100'
movwf TRISC ; set b'111100' as output port
bcf STATUS,RP0 ; set register bank 0
call READ_RTC
nop ; must give sometime to RTC
bcf CE
nop
nop
RETURN
READ_MIN
CALL WRITE_EN
MOVLW 0X83 ;READ min
movlw REGWRITE
call WRITE_RTC
bsf STATUS,RP0
movlw b'00000100'
movwf TRISC ; set b'111100' as output port
bcf STATUS,RP0 ; set register bank 0
call READ_RTC
nop ; must give sometime to RTC
bcf CE
nop
nop
RETURN
READ_SEC
CALL WRITE_EN
MOVLW 0X81 ;READ sec
movlw REGWRITE
call WRITE_RTC
bsf STATUS,RP0
movlw b'00000100'
movwf TRISC ; set b'111100' as output port
bcf STATUS,RP0 ; set register bank 0
call READ_RTC
nop ; must give sometime to RTC
bcf CE
nop
nop
RETURN
;-----------------------------------------------------------
READ_DAY
CALL WRITE_EN
MOVLW 0X8B
MOVWF REGWRITE
CALL WRITE_RTC
BSF STATUS,RP0
MOVLW B'00000100'
MOVWF TRISC ; SET B'111100' AS OUTPUT PORT
BCF STATUS,RP0 ;SET REGISTER BANK 0
CALL READ_RTC
NOP
BCF CE
NOP ; MUST GIVE SOMETIME TO RTC
NOP ;
RETURN
;--------------WRITE SUBROUTINE-----------------------
WRITE_EN
CLRF PORTC ;CE = 0, SCLK=0
BSF STATUS,RP0 ;SET REGISTER BANK 1
MOVLW B'000000'
MOVWF TRISC ; SET B'00000000' AS OUTPUT PORT
BCF STATUS,RP0 ;SET REGISTER BANK 0
BSF CE ; CE=1
RETURN
;--------------WRITE DATA-------------------------------
WRITE_RTC
MOVLW 0X08
MOVWF TIME_COUNT
WRITE_LOOP
BCF SCLK ;SCLK =0
BSF IO
BTFSS REGWRITE,0
BCF IO ;SET IO=1
NOP ;DO NOTHING
BSF SCLK ;SCLK =1
RRF REGWRITE,1
DECFSZ TIME_COUNT,1
GOTO WRITE_LOOP
RETURN
;---------------------------READ SUBROUTINE--------------
READ_RTC
clrf TIME_TEMP
MOVLW 0X08
MOVWF TIME_COUNT
READ_LOOP
BSF SCLK
bsf STATUS,C
BTFSS IO
BCF STATUS,C
BCF SCLK
RRF TIME_TEMP,1
DECFSZ TIME_COUNT,1
GOTO READ_LOOP
MOVF TIME_TEMP, W
RETURN