I never had the opportunity to use this device but saved the info for future use: MCP23017 16 bit I/O expander
May work for you.
I never had the opportunity to use this device but saved the info for future use: MCP23017 16 bit I/O expander
May work for you.
Louie
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
Click image for larger version
Code: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
DT
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.
Code: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] . . . . .
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.
DT
Bookmarks