The harder you work,
luckier you seem to be.  

Please refer to the buttonsLeds.bas file included in the project’s zip file during the remainder of this discussion as its code comments contain a much more complete description of this application then space allows here.

The code begins by defining compiler directives used by the hardware A/D, PWM and PULSIN circuitry.  Beginning at line 18, the I/O pins are assigned to the PIC’s ports.  Next, it declares several MAX/MIN constants used to distinguish demodulated SIRC pulses (start, zero, one) as well as command sequences for the LCD. 

Each device has its own “driver” code that consists of “*Init”, “*Read” and/or “*Paint” routines (eg. prSensorInit, prSensorRead).

The application’s main logic consists of an “Init” routine, which calls all of the device “*Init” routines.  This is followed by the “MainLoop” routine, which calls device “*Read” routines, then “compInDev” and “compSel” routines, and finally the “*Paint” routines.  It then pauses before repeating infinitely.  The “compInDev” routine computes which input device, the photoresistor or the SIRC device, to use as input.  Finally, the “compSel” routine computes the selected direction (reads the button state), and calculates the duty cycle for the motor.

6  of  6                                                                                   MichaelDWelch@(no-spam)                                                                 303-920-9749      remove (no-spam)

PIC 18F452 microcontroller with

Analog In/Out, Digital In/Out, Serial In/Out

System Software (continued)

A PIC project with Light Level Detection, SIRC and
PWM Motor Control

' ==========i/o pins=========
btn1            var portD.0
prSensorPin     var portA.0
sIrSensorPin    var portD.1
ledCW           var portC.4
ledSTOP         var portD.2
ledCCW          var portD.3
lcdPin          var portB.4
pwmPin          var portC.2
hBr1Pin         var portC.3
hBr2Pin         var portC.1

Init, MainLoop
compInDev, compSel

buttonInit, buttonRead
prSensorInit, prSensorRead
sIrSensorInit, sIrSensorRead
ledInit, ledPaint
lcdInit, lcdPaint
motorInit, motorPaint

prSensorCalibrate, motorCalibrate