This is a conglomerate of many different examples I read on the PIClist website (there are no 18FXXX examples that I could see so I had to convert the code, it was a good learning experience) and what I could glean from the datasheet. All it does is depending on whether I switch RB4 of port B between VCC and VSS (through 1k resister) it will run the appropriate routine. I'm looking for constructive criticism. (the timing part is not accurate, but it delays enough to work). It compiles and runs perfectly. ;-----------------------------------------------------------------------; ; ROT&CNT.ASM Switch between rotating and counting on LEDs (RD0-RD7) ; ;-----------------------------------------------------------------------; LIST P=PIC18F452 INCLUDE "p18f452.inc" __CONFIG _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H __CONFIG _CONFIG3H, _CCP2MX_ON_3H __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L __CONFIG _CONFIG7H, _EBTRB_OFF_7H CBLOCK 0x020 CNT1 CNT2 ENDC goto begin ORG 0x008 ;interupt vector movlw B'11111111' MOVWF TMR0L ;load timer0 with 255 so as to get a 16us delay BCF INTCON, TMR0IF ;clear timer overflow interupt flag RETFIE ;return from interupt begin: ORG 0x010 ; start a program memory location zero CLRF PORTD ;clear tristate buffer movlw B'00000000' MOVWF TRISA ;set up all bits of PORT A as outputs MOVWF TRISC ;set up all bits of PORT C as outputs MOVWF TRISD ;set up all bits of PORT D as outputs MOVWF TRISE ;set up all bits of PORT E as outputs movlw B'00010000' ; RB4 input, all other output (my switch) MOVWF TRISB movlw B'01000001' MOVWF T0CON ;set timer0 as 8 bit, internal clk, prescale 1:4 movlw B'11111111' MOVWF TMR0L ;load timer0 with 255 so as to get a 16us delay ;Delay = (256 - TMR0 * prescaler) ;----------------------------------------- ; Clock Frequency / 4 BSF INTCON, GIE ;enable interupts BSF INTCON, TMR0IE ;enable timer 0 overflow interupt movlw B'00000001' MOVWF PORTD ;-----------------------------------------------------------------------; ; This is the main program ; ;-----------------------------------------------------------------------; loop: btfsc PORTB, RB4 ; check rb4 goto ROTATE ; rb4 = 1 goto BINCNT ; rb4 = 0 ROTATE: Rrncf PORTD, 1 ; rotate right port D CALL Delay goto loop BINCNT: INCF PORTD, 1 ; add 1 to port D CALL Delay goto loop Delay: MOVLW B'11111111' MOVWF CNT2 DELAY2: MOVLW B'11110100' MOVWF CNT1 DECFSZ CNT2 GOTO DELAY1 GOTO FINISH DELAY1: BSF T0CON, TMR0ON ;start timer0 DECFSZ CNT1 GOTO DELAY1 GOTO DELAY2 FINISH: return end ; end of program -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body