This is a multi-part message in MIME format. ------=_NextPart_000_002E_01C669DF.898DE880 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit Sean Schouten wrote: > Olin, about that TAB problem; After the last time you couldn't read my > code, I dug out the -tab- options in MPLAB and set it to use 4 spaces > instead of TABs, thinking that that would solve the problem. I can now > open my own .ASM files in notepad without a problem, as long as I don't > have "word wrap" on. As you still seem to be having trouble with my > tabs, I am interested to know what you use as an editor as my thoughts > behind using tabs (spaces in this case) was to improve readability by > separating comments from code. I just clicked on the little attachement icon in Outlook Express, so it probably opened your file with Notepad. I saw things lining up in lots of different columns. It looked like each thing snapped to a random multiple of something like 8 columns, which is usually a good sign there are hard tabs in there. I ran your code thru my FIX_ASPIC program which removes all tabs and lines up MPASM code in fixed columns. The result is attached. It is much more readable than your original and should look the same in any editor except for the wrapping of very long lines. ------=_NextPart_000_002E_01C669DF.898DE880 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 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. TEMP_VAR RES 1 ;Global Temporary Value SPI_ROTATE RES 1 ;Variable used to keep track of SPI_DATA = rotation. SPI_BUFFER RES 6 ;Variable used to store SPI data. ; Label Definitions #DEFINE SPI_ENABLE PORTC, 2 #DEFINE SPI_DATA PORTC, 1 #DEFINE SPI_CLOCK PORTC, 0 ; 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: ### ;### 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 8Mhz BANKSEL OSCCON ;Switch to the correct bank. MOVLW 0x71 ;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 0x08 ;Move 0x08 into W-Register. MOVWF OPTION_REG ;Move value from W-register to = OPTION_REG-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. BANKSEL ADCON0 ;Switch to the correct bank. MOVLW 0x01 ;Move 0x01 into W-register. MOVWF ADCON0 ;Move value from W-register to = ADCON0-Register. BANKSEL ADCON1 CLRF ADCON1 ; 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. BCF INTCON, RAIE ;Disable PORTA change interrupt. BCF INTCON, GIE ;Disable General Interrupt Enable (GIE). RETURN ;Return to origin. ; END OF INITIALIZATION ; ************************************************************* ; ; ; ; THE SUBROUTINES ; ; ; ; ************************************************************* ; ;SPI_WRITE subroutine: Used to transfer up to 16-bits of data over = SPI-Bus in one go. SPI_WRITE BCF INTCON, GIE ;Disable GIE. BCF SPI_ENABLE ;Set SPI_ENABLE-bit to a logical 'ZERO'. BCF STATUS, Z ;Clear Z-bit (just in case...) MOVLW 0x08 ;Initial value to move into the SPI = rotation counter. MOVWF SPI_ROTATE ;Move new value into SPI_ROTATE. SPI_BYTE_1 ; Put data on SPI_DATA-pin BSF SPI_DATA ;Set SPI_DATA to a logical '1'. BTFSS SPI_BUFFER, 0 ;If SPI_DATA is not supposed to be a = logical '1', set to logical '0': BCF SPI_DATA ;this saves me 1 instruction cycle. ; Clock Pulse BSF SPI_CLOCK ;Set clock-bit to logical '1'. DECF SPI_ROTATE, F ;Decrease Bit-Counter. RRF SPI_BUFFER, F ;Rotate Byte Right one bit. NOP ;usefull for something. We fill this up = with whatever to balance the CLOCK. NOP NOP NOP BCF SPI_CLOCK ;Set clock-bit to logical '0'. ; Loop / Jump loop. BTFSC STATUS, Z ;Has the 1st byte experienced a full = rotation? GOTO SPI_BYTE_1 ;If not true: loop. ; Preperation for transfer of second byte. MOVLW 0x08 ;Initial value to move into the SPI = rotation counter. MOVWF SPI_ROTATE ;Move new value into SPI_ROTATE. SPI_BYTE_2 ; Put data on SPI_DATA-pin BSF SPI_DATA ;Set SPI_DATA to a logical '1'. BTFSS SPI_BUFFER+1, 0 ;If SPI_DATA is not supposed to be a = logical '1', set to logical '0': BCF SPI_DATA ;this saves me 1 instruction cycle. ; Clock Pulse BSF SPI_CLOCK ;Set clock-bit to logical '1'. DECF SPI_ROTATE, F ;Decrease Bit-Counter. RRF SPI_BUFFER+1, F ;Rotate Byte Right one bit. NOP NOP NOP NOP BCF SPI_CLOCK ;Set clock-bit to logical '0'. ; Loop / Jump loop. BTFSC STATUS, Z ;Has the 2nd byte experienced a full = rotation? GOTO SPI_BYTE_2 ;If not true: loop. ; Preperation for transfer of third byte. MOVLW 0x08 ;Initial value to move into the SPI = rotation counter. MOVWF SPI_ROTATE ;Move new value into SPI_ROTATE. SPI_BYTE_3 ; Put data on SPI_DATA-pin BSF SPI_DATA ;Set SPI_DATA to a logical '1'. BTFSS SPI_BUFFER+2, 0 ;If SPI_DATA is not supposed to be a = logical '1', set to logical '0': BCF SPI_DATA ;this saves me 1 instruction cycle. ; Clock Pulse BSF SPI_CLOCK ;Set clock-bit to logical '1'. DECF SPI_ROTATE, F ;Decrease Bit-Counter. RRF SPI_BUFFER+2, F ;Rotate Byte Right one bit. NOP NOP NOP NOP BCF SPI_CLOCK ;Set clock-bit to logical '0'. ; Loop / Jump loop. BTFSC STATUS, Z ;Has the 3rd byte experienced a full = rotation? GOTO SPI_BYTE_3 ;If not true: loop. ; Preperation for transfer of fourth byte. MOVLW 0x08 ;Initial value to move into the SPI = rotation counter. MOVWF SPI_ROTATE SPI_BYTE_4 ; Put data on SPI_DATA-pin BSF SPI_DATA ;Set SPI_DATA to a logical '1'. BTFSS SPI_BUFFER+3, 0 ;If SPI_DATA is not supposed to be a = logical '1', set to logical '0': BCF SPI_DATA ;this saves me 1 instruction cycle. ; Clock Pulse BSF SPI_CLOCK ;Set clock-bit to logical '1'. DECF SPI_ROTATE, F ;Decrease Bit-Counter. RRF SPI_BUFFER+3, F ;Rotate Byte Right one bit. NOP NOP NOP NOP BCF SPI_CLOCK ;Set clock-bit to logical '0'. ; Loop / Jump loop. BTFSC STATUS, Z ;Has the 4th byte experienced a full = rotation? GOTO SPI_BYTE_4 ;If not true: loop. ; Preperation for transfer of fourth byte. MOVLW 0x08 ;Initial value to move into the SPI = rotation counter. MOVWF SPI_ROTATE SPI_BYTE_5 ; Put data on SPI_DATA-pin BSF SPI_DATA ;Set SPI_DATA to a logical '1'. BTFSS SPI_BUFFER+4, 0 ;If SPI_DATA is not supposed to be a = logical '1', set to logical '0': BCF SPI_DATA ;this saves me 1 instruction cycle. ; Clock Pulse BSF SPI_CLOCK ;Set clock-bit to logical '1'. DECF SPI_ROTATE, F ;Decrease Bit-Counter. RRF SPI_BUFFER+4, F ;Rotate Byte Right one bit. NOP NOP NOP NOP BCF SPI_CLOCK ;Set clock-bit to logical '0'. ; Loop / Jump loop. BTFSC STATUS, Z ;Has the 5th byte experienced a full = rotation? GOTO SPI_BYTE_5 ;If not true: loop. ; Preperation for transfer of fourth byte. MOVLW 0x08 ;Initial value to move into the SPI = rotation counter. MOVWF SPI_ROTATE SPI_BYTE_6 ; Put data on SPI_DATA-pin BSF SPI_DATA ;Set SPI_DATA to a logical '1'. BTFSS SPI_BUFFER+5, 0 ;If SPI_DATA is not supposed to be a = logical '1', set to logical '0': BCF SPI_DATA ;this saves me 1 instruction cycle. ; Clock Pulse BSF SPI_CLOCK ;Set clock-bit to logical '1'. DECF SPI_ROTATE, F ;Decrease Bit-Counter. RRF SPI_BUFFER+5, F ;Rotate Byte Right one bit. NOP NOP NOP NOP BCF SPI_CLOCK ;Set clock-bit to logical '0'. ; Loop / Jump loop. BTFSC STATUS, Z ;Has the 6th byte experienced a full = rotation? GOTO SPI_BYTE_6 ;If not true: loop. ; Preperation for transfer of fourth byte. MOVLW 0x08 ;Initial value to move into the SPI = rotation counter. MOVWF SPI_ROTATE BSF SPI_ENABLE ;Set SPI_ENABLE bit. RETURN ; ADC_SAMPLE subroutine: Sample analog value @ pin-x and return = converted value in W-Reg. ADC_SAMPLE BCF ADCON0, GO ;Start ADC Caputer BTFSS ADCON0, GO ;If capture is not done: GOTO $ - 1 ;Loop MOVF ADRESH, W ;Move 8 most significant bits into = W-Register. RETURN ; CALC_FREQ subroutine: Calculate devider for the desired freqency in = real time. CALC_FREQ ; Devider =3D ; 2^28 * DESIRED.FREQ / MCLK ; =3D DESIRED.FREQ * 26.84 (=3D 00011010.11010111 ) ; To be able to cover the a 1 - 100000 Hz range, we need to be = able to multiply 24 bits wide. RETURN ; SWEEP_LOG subroutine: Frequency sweep 5 Hz - 25 Khz, logarithmic = incrementation/decrementation of frequency. SWEEP_LOG ; FREQ_INCR/DECR =3D DOMAIN ^ (1 / STEPS) --> Audio =3D 2 ^ = (1 / 12). RETURN ; SWEEP_LIN subroutine: Frequency sweep 5 Hz - 25 Khz, linear = incrementation/decrementation of frequency. SWEEP_LIN RETURN ;PLAY_SONG subroutine: Plays Frere Jaques (Vader Jacob). PLAY_SONG RETURN ; END of subroutine section. ; ************************************************************* ; ; ; ; THE REAL CODE ; ; ; ; ************************************************************* ; START CALL INITIALIZE ;Initialize Microcontroller. ; Main program loop. MAIN GOTO MAIN ;Loop MAIN. ; CODE ENDS HERE END ------=_NextPart_000_002E_01C669DF.898DE880 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ------=_NextPart_000_002E_01C669DF.898DE880-- ****************************************************************** Embed Inc, Littleton Massachusetts, (978) 742-9014. #1 PIC consultant in 2004 program year. http://www.embedinc.com/products