Transistors
BJT
current controlled
cheap
require careful resistor sizing
PIC current = (1/10) load current required
5V = (PIC current)*(Resistor size)
MOSFET
voltage controlled
slightly less cheap
easy, just hook straight to pin
Darlington
H-Bridge
Motors
DC brush
Stepper
Servo
signal
OSCCON
Delay Library
LCD
LCDModule.h
LCDModule.c
print things
how to use
on line
XLCDPut(letter)
sprintf(words, string to print on line
%d , lineNumber);
XLCDPutRamString(words);
functions
Timers
really?
openTimerx
ReadTimerx
WriteTimerx
Timer calculations:
Instruction cycle frequency = (clock frequency) / 4
Timer frequency = (instruction cycle frequency) /
pre-scaler
Timer period = 1 / (Timer frequency)
rollover every 65536 ticks
1 tick = 1 Timer Period
see chart for how to set up
Push Button Interrupts
RB0, RB1, RB2
make sure to debounce
see chart for how to setup
ADC
use default values for OpenADC(config1, config2, portconfig)
portconfig is # of analog pins, up to 12. See previous chart
use 0x00 or 0b0000 0000
SetChanADC(ADC_CH#); # is pin#
ConvertADC()
while(BusyADC());
result = ReadADC();
0 - 1024
7-seg displays
Light Sensors
In the words of Dr. Fisher consult the datasheet, and do trial and
error. You dont want the fluorescent room lights to set it off, so adjust the resistor
so it doesnt.
PWM
Frequency = Cycles/second
duty cycle = % of time signal is high
first, OpenTimer2(TIMER_INT_OFF & T2_PS_1_#), # = 1, 4, 16
then OpenPWM1(period) or OpenPWM2(period)
period is frequency
SetDCPWM1(duty cycle) or SETDCPWM2(duty cycle)
use two pwm pins
frequency math:
PWM period = [(timer ticks) + 1] * 4 * Tosc * (TMR2
prescaler)
timer ticks is the period you put into OpenPWM1 (0255)
frequency = 1/(PWM period)
UART