INCLUDE "modedefs.bas"
PORTA = $00 ' Set all port a pins to low
PORTB = $00 ' Set all port b pins to low
PORTC = $00 ' Set all port c pins to low
PORTD = $00 ' Set all port d pins to low
PORTE = $00 ' Set all port e pins to low
asm ; The following code is assembly, not Basic
__CONFIG _CONFIG1, _INTOSCIO & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF & _LVP_OFF
; Use internal oscillator & make both, OSC pins I/Os, turn off watchdog timer, enable Power-up timer,
; code protection off, brown-out off, disable switch over mode, turn off failsafe monitor,
; low voltage programming off
endasm ' End assembly code
ADCON0.0 = 0 ; Make all analog pins digital I/Os
CM1CON0.7 = 0 ; Disable comparator C1
CM2CON0.7 = 0 ; Disable comparator C2
OSCCON.6 = 1 ; Set the internal oscillator to 8MHz
OSCCON.5 = 1 ; Set the internal oscillator to 8MHz
OSCCON.4 = 1 ; Set the internal oscillator to 8MHz
WDTCON.0 = 0 ; Disable the watchdog timer
ANSEL = %00000000 ; Set all analog pins on port a to digital I/O
ANSELH = %00000000 ; Set all analog pins on port b to digital I/O
DEFINE OSC 8 ' Tell the program the oscillator is running at 8 MHz
TRISA = %00000000 ' Make all port a pins outputs
TRISB = %00001111 ' Make port b pins 0-3 inputs and the rest as outputs
TRISC = %00000000 ' Make all port c pins outputs
TRISD = %00000000 ' Make all port d pins outputs
TRISE = %00000000 ' Make all port e pins outputs
PORTA = $00 ' Set all port a pins to low
PORTB = $00 ' Set all port b pins to low
PORTC = $00 ' Set all port c pins to low
PORTD = $00 ' Set all port d pins to low
PORTE = $00 ' Set all port e pins to low
'Variables**************************************** ************************************************** *
b0 VAR byte ' Required byte variable for toggle button
i var word
temp var byte
'************************************************* ************************************************** *
INITIALIZE: ' Initialize Routine
INTCON.0 = 0 ' Clear the interrupt-on-change flag
On Interrupt goto Halt ' Once an active interrupt port is enabled, go to the Halt routine
INTCON = %10001000 ' Enable global interrupts, Enable interrupt-on-change on Port b
IOCB = %00000011 ' Enable interrupt-on-change on RB0-RB3
PORTE.1 = 0 ' Make sure LED on PORTE.1 is off
PORTE.2 = 0 ' Make sure LED on PORTE.2 is off
GOTO MAIN ' Go to Main routine
'************************************************* ************************************************** *
MAIN:
HIGH PORTE.0
FOR i = 1 to 5000
PAUSEUS 100
NEXT
LOW PORTE.0
FOR i = 1 to 5000
PAUSEUS 100
NEXT
GOTO MAIN
'*************************************************
DISABLE ' do NOT place interrupt checking code below
Halt: ' Halt Routine
temp = PORTB
IF temp.0 = 0 THEN
WHILE PORTB.0=0 ' wait for button release & end mismatch condition on portb
WEND
PAUSE 20 ' Debounce delay
HIGH PORTE.1
LOW PORTE.2
ENDIF
IF temp.1 = 0 THEN
WHILE PORTB.1=0 ' wait for button release & end mismatch condition on portb
WEND
PAUSE 20 ' Debounce delay
LOW PORTE.1
HIGH PORTE.2
ENDIF
INTCON.0 = 0 ' Clear the interrupt-on-change flag
RESUME ' Resume wherever program left off at
ENABLE ' Enable all active interrupts
Bookmarks