Firefly 16F88 IR_IN & Button 1 test program

Status
Not open for further replies.
A simple program that lights LED1 Green when an IR signal is detected. Also can be used to test pushbutton #1

Code:
;**********************************************************************
; Firefly IR in test and/or button 1 test
; DIP switch dduudd (IR_in on, Tutor on, all others off)
; 
;**********************************************************************
    list      p=16f88             ; list directive to define processor
    include   <p16F88.inc>        ; processor specific variable definitions
    errorlevel  -302              ; suppress message 302 from list file

    __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB3 & _DEBUG_ON & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
    __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    
;**********************************************************************
; Oscillator select for Firefly 16F88 internal OSC (this also affects USART)
; 0 = 31.25KHz, 1 = 125KHz, 2 = 250KHz, 3 = 500KHz
; 4 = 1MHz,     5 = 2MHz,   6 = 4MHz,   7 = 8MHz
; OSCCON = 0xxx0010 (xxx = speed, bit2 = use internal RC osc)
OSC       EQU         7                 ;enter desired Oscillator speed

;**********************************************************************
; _let macro similar to BASIC LET X = value
; designed for readability
_let      macro     register, literal   ;_let <register>, <literal>
          movlw     literal             ;W = literal
          banksel   register            ;make sure it's in the right bank
          movwf     register            ;register = W
          endm
          
          org       0x000
          _let      OSCCON, OSC*.16|0x2 ; use OSC value to set internal osc
          _let      CMCON, 0x07         ; disable comparators
          _let      ANSEL, 0x00         ; disable A/D inputs
          _let      OPTION_REG, 0x00    ; weak pullups
          _let      TRISB, b'11111111'  ; all inputs
          _let      TRISA, b'10111110'  ; enable LED 1 (red / green)
          
          banksel   0                   ;B0 switch to bank 0
          clrf      PORTA               ;B0 zero port (LEDs off)
IR_test   btfss     PORTB, 0            ;B0 is RB0 low?  
          bsf       PORTA, 0            ;B0 if yes then LED1 on (Green)
          btfsc     PORTB, 0            ;B0 is RB0 high?
          bcf       PORTA, 0            ;B0 if yes then LED1 off
          goto      IR_test             ; loop forver
          end
 
Last edited:
Bill,

You're using Microchip instructions opcodes! I can actually understand your program listing (grin)! Thank you!

Happy Holidays. Mike
 
I'm actually enjoying it more than the old Parallax CVASM16. I can get macros to do things similar to CVASM16. I do like the banksel command and the math is pretty handy. Myke Predko is has recommened not using banksel but I think it's handy as anything if used properly and is recommend by Microchip as when you compile for the 18F series it simply ignores the command.
MPLAB is a teriffic tool for when you get the hang of it. Switching between the simulator, the ICD2 & the programmer is fast and easy. Knowing when to use the Simulator over the ICD2 is the key to speedy debugging.

PS do you like the _LET macro? doesn't hide in the code like a mov instruction would.

PPS Mike, did you manage to finish building your Firefly? Any code snippits you want to share?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…