This is a multi-part message in MIME format. ------=_NextPart_000_00CB_01C5B924.768F4830 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit Paul James E. wrote: > You sure do put your comments way out in right field. Makes it > difficult to print out on a standard page and still be able to read the > comments. I noticed that too. There's a lot of bad code formatting out there. That's why I wrote my ASPIC_FIX program, which is part of my PIC development environment at http://www.embedinc.com/pic. I ran Sean's code thru that before even attempting to make sense of it. As an example, I've attached his latest code as cleaned up by ASPIC_FIX. ------=_NextPart_000_00CB_01C5B924.768F4830 Content-Type: application/octet-stream; name="x.aspic" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x.aspic" ; May the source be with you! ;+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ; Preperational Part: LIST P=3D16F684 ;The mighty PIC 16F684 #INCLUDE ERRORLEVEL -302 ;Supress the (manual) banking error! __CONFIG _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF = & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ; This (below) is where we define memory space [ BANK 0 : 0x20 - 0x7F && = BANK 1 : 0xA0 - 0xBF ]. ; The "Temporary" memory locations: TEMP_W RES 1 ;Place to dump W-Register in case of = interrupt. TEMP_STATUS RES 1 ;Place to dump STATUS-Register data in case = of interrupt. ; This is where the definitions STOP. ORG 0x00 GOTO START ;Standard Operation ; ************************************************************* ; ; ; ; INTERRUPT SERVICE ROUTINE ; ; ; ; ************************************************************* ; ORG 0x04 ;The Interrupt Service Routine (Called in = case of an Interrupt). ; Backup the W-register MOVWF TEMP_W ;Write the W-Register to it's temporary = memory location. ; Backup the STATUS-Register in bank0. SWAPF STATUS, W ;Swap STATUS to be saved in to the = W-Register. CLRF STATUS ;Clear the STATUS register; go to bank0. MOVWF TEMP_STATUS ;Store STATUS in it's temporary place in = memory-space. ;### Begin ISR code: ### ; Turn LED on and keep it in that state for 5 whole seconds. BSF PORTA, 1 ;Turn LED on. CALL DELAY1S ;Delay for 1 second. CALL DELAY1S ;Delay for 1 second. CALL DELAY1S ;Delay for 1 second. CALL DELAY1S ;Delay for 1 second. CALL DELAY1S ;Delay for 1 second. BCF PORTA, 1 ;Turn LED off. ;### END ISR CODE ### ; Last but not least: Restore Data and return to main program. ; Restore STATUS SWAPF TEMP_STATUS, W ;Restore STATUS MOVWF STATUS ; Restore W-Register SWAPF TEMP_W, F ;Swap the first and the last nible of = TEMP_W. SWAPF TEMP_W, W ;Swap the TEMP_w into the W-Register. BCF INTCON, RAIF ;Clear the PORTA interrupt flag. RETFIE ;Return from Intterupt, and go back to = wherever! ; END OF INTERRUPT SERVICE ROUTINE ; ************************************************************* ; ; ; ; MICROCONTROLLER INITIALIZATION ; ; ; ; ************************************************************* ; INITIALIZE ; Set OSC to 31kHz BANKSEL OSCCON ;Switch to the correct bank. MOVLW 0x01 ;Move 0x01 into W-register MOVWF OSCCON ;Move value from W-register to = TRISA-Register. ; Set prescaler to devide clock by 256 BANKSEL OPTION_REG ;Switch to the correct bank. MOVLW 0x07 ;Move 0x07 into W-register MOVWF OPTION_REG ;Move value from W-register to = TRISA-Register. ; Make RC0 Analogue. BANKSEL ANSEL ;Switch to the correct bank. MOVLW 0x01 ;Move 0x01 into W-register. MOVWF ANSEL ;Move value from W-register to = TRISA-Register. ; Make RC0 & RC3 inputs. BANKSEL TRISA ;Switch to the correct bank. MOVLW 0x09 ;Move 0x09 into W-Register. MOVWF TRISA ;Move value from W-register to = TRISA-Register. ; Turn off comparators BANKSEL CMCON0 ;Switch to the correct bank. CLRF CMCON0 ;Clear CMCON0 ; Clear Ports 'n Timers BANKSEL PORTA ;Switch to the correct bank. CLRF PORTA ;Clear PORTA BANKSEL PORTC ;Switch to the correct bank. CLRF PORTC ;Clear PORTC BANKSEL TMR0 ;Switch to the correct bank. CLRF TMR0 ;Clear TMR0 ; Interrupt Configuration BANKSEL IOCA ;Switch to the correct bank. BSF IOCA, IOCA3 ;Enable interrupt-on-change on RA3. BANKSEL PIR1 ;Switch to the correct bank. CLRF PIR1 ;Clear the PIR1-Register. BANKSEL PIE1 ;Switch to the correct bank. CLRF PIE1 ;Clear the PIE1-Register. BANKSEL INTCON ;Switch to the correct bank. CLRF INTCON ;Clear the INTCON-Register. BCF INTCON, RAIF ;Clear the PORTA interrupt flag. BSF INTCON, RAIE ;Enable PORTA change interrupt. BSF INTCON, GIE ;Set the General Interrupt Enable bit to 1. RETURN ;Return to origin. ; END OF INITIALIZATION ; ************************************************************* ; ; ; ; THE SUBROUTINES ; ; ; ; ************************************************************* ; ; ### Old second delay ### ; DELAY1S CLRF TMR0 ;Clear TMR0 LOOPY MOVF TMR0, W ;Read value of TMR0 SUBLW 0x0F ;Subtract 0x0F from the value of TMR0 BTFSS STATUS, Z ;If the result of the above equals 0, skip = the 'GOTO' below. GOTO LOOPY ;Else: LOOP (go to LOOPY). RETURN ;Return to point of origin. ; ### End of delay ### ; ; ### Flash Led Subroutines ### ; ; An endless "Flash The LED" loop. FLASHLEDLOOP ;Aka "beginning of loop". BANKSEL PORTA ;Switch to the correct bank. BCF PORTA, 1 ;Switch LED off. CALL DELAY1S ;Delay for 1 second. BSF PORTA, 1 ;Switch the LED on. CALL DELAY1S ;Delay for 1 second. GOTO FLASHLEDLOOP ;Go to beginning of loop. ; Flash the LED twice. FLASHLED BANKSEL PORTA ;Switch to the correct bank. BCF PORTA, 1 ;Switch LED off. CALL DELAY1S ;Delay for 1 second. BSF PORTA, 1 ;Switch LED on. CALL DELAY1S ;Delay for 1 second. BCF PORTA, 1 ;Switch LED off. CALL DELAY1S ;Delay for 1 second. BSF PORTA, 1 ;Switch LED on. CALL DELAY1S ;Delay for 1 second. RETURN ;Return to point of origin. ; ### End of FlAsH LeD ### ; ; END OF THE SUB-ROUTINES ; ************************************************************* ; ; ; ; THE REAL CODE ; ; ; ; ************************************************************* ; START CALL INITIALIZE ;Initialize Microcontroller. ; Main program loop. MAIN NOP ;Do nothing... GOTO MAIN ;Loop MAIN. ; CODE ENDS HERE END ------=_NextPart_000_00CB_01C5B924.768F4830 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ------=_NextPart_000_00CB_01C5B924.768F4830-- ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com