PDA

View Full Version : 877A & 16 Inputs to be monitored



Megahertz
- 17th August 2013, 19:34
I have one 877A and I would like to monitor 16 inputs (or more if possible) which I cannot do it by continues monitoring the inputs to go low/high as PIC has to do some other stuff in the main routine.
Although I can use some PortB pins as they have interrupt on change BUT I do not want to use programming pins as inputs as I want to leave them for ICSP which leaves me with very few pins with 'change on interrupt'.

So, is there any other IC/technique which I can implement in this case which can help me to monitor many inputs using 1 interrupt or something like that.

LinkMTech
- 18th August 2013, 03:55
I never had the opportunity to use this device but saved the info for future use: MCP23017 (ww1.microchip.com/downloads/en/devicedoc/21952b.pdf)16 bit I/O expander
May work for you.

Darrel Taylor
- 18th August 2013, 04:41
You can use ON DEBUG to "Poll" every pin on the chip, which acts a lot like ON INTERRUPT.
Between each line of PBP code, it will jump to the debug routine which checks all the pins to see if anything has changed.

This demo program monitors the 16-pins on PORTB and PORTC, and transfers them to PORTD, PORTA and PORTE.
The main loop continues blinking PORTE.2 (green LED) while it "Polls" the pins.

Click image for larger version
http://support.melabs.com/DT/ON_DEBUG_POLL.gif (http://support.melabs.com/DT/ON_DEBUG_POLL.gif)
Click image for larger version


DEBUG_ADDRESS var word bank0 system ' Program address
ThisPORTB VAR BYTE
ThisPORTC VAR BYTE
LastPORTB VAR BYTE
LastPORTC VAR BYTE
PauseCount VAR WORD
IOCW VAR WORD

ADCON1 = 7
CMCON = 7
PORTD = 0
TRISD = 0
PORTA = 0
TRISA = 0
PORTE = 0
TRISE = 0

;--------------------------------------------------------------------------------------------
ON DEBUG GOTO Monitor16

Main:
HIGH PORTE.2
GOSUB PAUSE500
LOW PORTE.2
GOSUB PAUSE500
GOTO Main

PAUSE500:
FOR PauseCount = 1 to 500
PAUSEUS 980
NEXT PauseCount
RETURN

DISABLE DEBUG
;--------------------------------------------------------------------------------------------

Monitor16:
ThisPORTB = PORTB
ThisPORTC = PORTC
IF ThisPORTB != LastPORTB THEN
LastPORTB = ThisPORTB
PORTD = ~ThisPORTB
ENDIF
IF ThisPORTC != LastPORTc THEN
LastPORTC = ThisPORTC
PORTA = ~ThisPORTC
PORTE = ~(ThisPORTC >> 6)
ENDIF

exitdebug:
' End of debug routine - go back to main program
asm
movf DEBUG_ADDRESS + 1, W ; Set PCLATH with top byte of return address
movwf PCLATH
movf DEBUG_ADDRESS, W ; Go back to main program
movwf PCL
endasm

Megahertz
- 20th August 2013, 01:33
Thanks for the info. The On DEBUG seems very useful but will it work if I am DEBUGIN for 5 seconds in the main loop. I am trying to make a security system SMS based in which the 877A keeps checking the arrival of a text message in the main loop by polling the GSM module every few seconds and waits for an "OK" or other message from the module and does allow 5 second for the GSM module to respond.



main:
DEBUG "AT+CMGR=",DEC c,13,10
DEBUGIN 5000,main,[WAIT("+"),STR code\5\13, SKIP 15,STR num\13\13, SKIP 27,STR sms\25\13]
.
.
.
.
.

Darrel Taylor
- 20th August 2013, 01:59
No, of course not.
But your request didn't say anything about 5 second SERIN commands.

If you use the 16F877a's USART, then it doesn't have to sit there twiddling it's thumbs waiting for data to come in.
And can continue on monitoring the inputs.

Answers can only be as complete as the request made for it.