PicBasic Pro Programs

PICBASIC PRO PROGRAMS FOR 16F88:
Beginning Programs
Servo and Motor Control Programs
Stepper Motor Programs
Reading Sensor Programs
Serial Communications Programs
Visual Basic.NET Programs
Robotics Programs
DS1620 Thermometer Programs
Making Music with PIC16F88

PICBASIC PRO PROGRAMS FOR 16F877A:
Beginning Programs
Servo and Motor Control Programs
Stepper Motor Programs
Reading Sensor Programs


PICBASIC PRO PROGRAMS FOR 18F4331:
Encoder Programs


These fundamental PicBasic Pro programs were written to introduce new statements that periodically would be combined into a program with a robotic application. Most of the programs are very short, focusing on one new command or a new application of a command. Check Technical Lessons for Year 2 for more background information.

The microcontroller used for the most part is the PIC16F88-I/P from Microchip Technology,
http://microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=64. The data sheet is available at: http://ww1.microchip.com/downloads/en/devicedoc/30487c.pdf. Jameco stocks the PIC16F88-I/P at a cost of $3.25 each for quantities less than 10. Microchipdirect lists the PIC16F88-I/P at $2.60 each for quantities less than 26.

Some of the programs have adapted to the PIC16F877A.

The programs are written in PicBasic Pro from micro-Engineering Labs, Inc., melabs.com. We use the melabs U2 Programmer. The cost for both the PicBasic Pro Compiler 3.0 and the U2 Programmer with Accessories ranges from $174.90 to $394.90 USD depending upon which version of PicBasic Pro Compiler 3.0 purchased.

16F88 Beginning Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
blink1 LED flashes on and off one time per second. PAUSE, GOTO, END

Schematic

5 v Voltage
Regulator

Code
PDF
file
blink1.pbp
blink2 LED flashes on and off one time per half second using different commands. HIGH, LOW Schematic Code
PDF
file
blink2.pbp
railroad Two LEDs flash like a railroad crossing.   Schematic Code
PDF
file
railroad.pbp
blink3 Turns one LED on and off 5 times. FOR..NEXT Schematic Code
PDF
file
blink3.pbp
led_piezo Many patterns of flashing   Schematic Code
pdf
file
led_piezo.pbp
bounce1 Eight LED's scroll on from the right then to the left then back again.   Schematic Code
PDF
file
bounce1.pbp
bounce2 Eight LED's scroll off from the right then to the left.   Schematic Code
PDF
file
bounce2.pbp
count1 Eight LEDs count in binary from 1 to 255   Schematic Code
PDF
file
count1.pbp
count2 Display 8-bit
number as
decimal,
hexadecimal,
binary number
on LCD
  Schematic Code
PDF
file
count2.pbp
LCD1 Prints simple message to LCD. LCDOUT Schematic Code
PDF
file
LCD1.pbp
LCD2 Demonstrates several commands to move LCD cursor.   Schematic Code
PDF
file
LCD2.pbp
LCD3 Display resistance readings from a potentiometer. POT Schematic Code
PDF
file
LCD3.pbp
pic_as_source PIC acts as a source output to light an LED   Schematic Code PDF file pic_as_source
pic_as_sink PIC acts as a sink output to light an LED   Schematic Code PDF file Pic_as_sink
active_high LED turns on when active high switch is pressed   Schematic Code PDF file active_high
active_low LED turns on when active low switch is pressed   Schematic Code PDF file active_low
array1 Set up two 6 element arrays   Schematic Code
PDF
file
array1
array2 Find max value in 7 element array   Schematic Code
PDF
file
array2
fiber-optic1 Sends simple signal through fiber-optic cable   Schematic Code PDF file fiber_optic1
shift1 Use shift operator << to shift value to left Shift Operator Schematic Code
PDF
file
shift1.pbp
signed_num1 Display signed numbers   Schematic Code
PDF
file
signed_num1



16F88 Servo and Motor Control Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
servo1 Rotates servo cwise and ccwise using PULSOUT PULSOUT Schematic Code
PDF
file
servo1.pbp
servo2 Rotates servo cwise and ccwise using PAUSEUS PAUSEUS Schematic Code
PDF
file
servo2.pbp
servo3 Rotates servo cwise and ccwise in incremental steps   Schematic

Code
PDF

file

servo3.pbp
servo4 Servo position determined by switch inputs   Schematic Code
PDF
file
servo4.pbp
h_bridge PIC drives SN754410 1.5 A driver   Schematic

Photo of
Breadboard

(large pdf file)
Code
PDF
file
h_bridge_
sn754410_ 1.pbp
pwm1 Drives dc motors at different speeds. Jameco motor1 motor2 PWM Schematic Code
PDF
file
pwm1.pbp
hpwm1 Shows HPWM working in program background HPWM Schematic Code
PDF
file
hpwm1.pbp
hpwm2 Changes speeds using HPWM   Schematic Code
PDF
file
hpwm2.pbp

pwm_

hpwm1

Runs PWM and HPWM commands together   Schematic Code
PDF
file
pwm_hpwm1
pwm_
sn754410
Uses PAUSEUS
command to
create PWM
signal to drive
SN754410 1.5 A h-bridge driver
  Schematic

Photo of
Breadboard

(large pdf file)
Code
PDF
file
pwm_
sn754410_1


16F88 Stepper Motor Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
step_mot1 Drives stepper motor   Schematic Code PDF file step_mot1.pbp
step_mot_
hi_torque
Generates 1.4
times the torque as step_mot1
  Schematic Code PDF file step_mot_
hi_torque.pbp
step_mot_
half_step
Drives stepper motor with twice the steps as step_mot1   Schematic Code PDF file step_mot_
half_step.pbp
step_mot_
one_rev
Drives stepper motor to rotate one revolution cw and ccw then stop LOOKUP Schematic Code PDF file step_mot_
one_
revolution.pbp


16F88 Reading Sensor Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
switch1 Turn on/off LED's with button switch. IF..THEN Schematic Code
PDF
file
switch1.pbp
switch2 Switch drives LED and servo. IF..THEN.. ELSE Schematic Code
PDF
file
switch2.pbp

switch_

limit1

Uses limit switches to reverse motor See Video   Schematic Code
PDF
file
switch_limit1
adc1 8-Bit Analog-to-Digital conversion ADCIN Schematic

Code
PDF
file

adc1.pbp
adc2 10-bit Analog-to-Digital conversion   Schematic Code
PDF
file
adc2.pbp
adc3 Converts 10-Bit data to voltage   Schematic Code
PDF
file
adc3.pbp
bend_sensor1 Use flex sensor to rotate hobby servo See Video   Schematic Code
PDF
file
bend_sensor1
read_voltage Reads and displays 0 to +15 volts   Schematic Code PDF file read_voltage
sonar1 Displays SRF04 sonar readings to LCD. PULSIN Schematic Code
PDF
file
sonar1
sonar2 LED's light up as sonar is brought close to an object.   Schematic Code
PDF
File
sonar2
dinsmore1 Reads Dinsmore 1490 Digital Compass   Schematic Code PDF File dinsmore1
MPX4250 Measures water depth with MPX4250AP sensor   Schematic Code PDF File mpx4250


16F88 Serial Communications:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
serout2_hello Display hello on PC terminal program
SEROUT2

Schematic
Code
PDF
file

serout2_hello
serout2_
potentiometer_
8bit
Display 8-bit
potentiometer
reading on PC terminal program
 
Schematic

Code
PDF
file

serout2_
potentiometer_
8bit
serout2_
potentiometer_
10bit
Display 10-bit
potentiometer
reading on PC terminal program
 
Schematic

Code
PDF
file

serout2_
pontentiometer_
10bit
serin2_led_on_
off
PC controls
LEDs on PIC
SERIN2
SELECT CASE
Schematic Code
PDF
file
serin2_led_on_off
serin2_pwm PC controls
motor speed
SERIN2 with
Timeout,
Label
Schematic Code
PDF
file
serin2_pwm
serin2_pwm_
wait
PC controls
motor speed
SERIN2 with
WAIT ()
Modifier
Schematic Code
PDF
file
serin2_pwm_wait

multiplex_tx1 &
multiplex_rx1

 

Control 4 LEDs over fiber-optic cable using 4 variables HSEROUT
HSERIN
Schematic tx1.pdf
rx1.pdf
multiplex_tx1
multiplex_rx1
multiplex_tx2 &
multiplex_rx2
Control 4 LEDs over fiber-optic cable using 1 variable   Schematic tx2.pdf
rx2.pdf
multiplex_tx2
multiplex_rx2
multiplex_tx3 &
multiplex_rx3
Control 2 motors' speed over fiber-optic cable.
One tx PIC, two rx PICs
  Schematic tx3.pdf
rx3x.pdf
rx3y.pdf
multiplex_tx3
multiplex_rx3x
multiplex_rx3y



16F877A Beginning Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
blink1 LED flashes on and off one time per second. PAUSE, GOTO, END

Schematic

5 v Voltage
Regulator

Code
PDF
file
blink1.pbp
blink2 LED flashes on and off one time per half second using different commands. HIGH, LOW Schematic Code
PDF
file
blink2.pbp
railroad Two LED's flash like a railroad crossing.   Schematic Code
PDF
file
railroad.pbp
blink3 Turns one LED on and off 5 times. FOR..NEXT Schematic Code
PDF
file
blink3.pbp
bounce1 Eight LED's scroll on from the right then to the left then back again.   Schematic Code
PDF
file
bounce1.pbp
bounce2 Eight LED's scroll off from the right then to the left.   Schematic Code
PDF
file
bounce2.pbp
count1 Eight LEDs count in binary from 1 to 255   Schematic Code
PDF
file
count1.pbp
LCD1 Prints simple message to LCD. LCDOUT Schematic Code
PDF
file
LCD1.pbp
LCD2 Demonstrates several commands to move LCD cursor.   Schematic Code
PDF
file
LCD2.pbp
LCD3 Display resistance readings from a potentiometer. POT Schematic Code
PDF
file
LCD3.pbp


16F877A Servo and Motor Control Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
servo1 Rotates servo cwise and ccwise using PULSOUT PULSOUT Schematic Code
PDF
file
servo1.pbp
servo2 Rotates servo cwise and ccwise using PAUSEUS PAUSEUS Schematic Code
PDF
file
servo2.pbp
servo3 Rotates servo cwise and ccwise in incremental steps   Schematic

Code
PDF
file

servo3.pbp
servo4 Servo position determined by switch inputs   Schematic Code
PDF
file
servo4.pbp
h_bridge PIC drives SN754410 1.5 A driver   Schematic

Code
PDF
file
h_bridge_
sn754410_ 1.pbp
pwm1 Drives dc motors at different speeds. Jameco motor1 motor2 PWM Schematic Code
PDF
file
pwm1.pbp
hpwm1 Shows HPWM working in program background HPWM Schematic Code
PDF
file
hpwm1.pbp
hpwm2 Changes speeds using HPWM   Schematic Code
PDF
file
hpwm2.pbp
pwm_
sn754410
Uses PAUSEUS
command to
create PWM
signal to drive
SN754410 1.5 A h-bridge driver
  Schematic

Code
PDF
file
pwm_
sn754410_1


16F877A Stepper Motor Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
step_mot1 Drives stepper motor   Schematic Code PDF file step_mot1.pbp
step_mot_
hi_torque
Generates 1.4
times the torque as step_mot1
  Schematic Code PDF file step_mot_
hi_torque.pbp
step_mot_
half_step
Drives stepper motor with twice the steps as step_mot1   Schematic Code PDF file step_mot_
half_step.pbp
step_mot_
one_rev
Drives stepper motor to rotate one revolution cw and ccw then stop LOOKUP Schematic Code PDF file step_mot_
one_
revolution.pbp


16F877A Reading Sensor Programs:

Program Name
Program
Description

New PICBASIC PRO Statements

Schematic for Code
Code as .pdf
file
Download PicBasic Pro Code
as .pbp File
switch1 Turn on/off LED's with button switch. IF..THEN Schematic Code
PDF
file
switch1.pbp
switch2 Switch drives LED and servo. IF..THEN.. ELSE Schematic Code
PDF
file
switch2.pbp
adc1 8-Bit Analog-to-Digital conversion ADCIN Schematic

Code
PDF
file

adc1.pbp
adc2 10-bit Analog-to-Digital conversion   Schematic Code
PDF
file
adc2.pbp
adc3 Converts 10-Bit data to voltage   Schematic Code
PDF
file
adc3.pbp
sonar1 Displays SRF04 sonar readings to LCD. PULSIN Schematic Code
PDF
file
sonar1

 


Copyright 2015, Cornerstone Robotics / Disclaimer