Analog Out

 

# Prototyping board (breadboard)
# Power supply connector
# 5-15VDC power supply
# Assorted wires
# 5V regulator
# PIC 18F452 or BX-24
# Serial cable
# DB9 female serial connector & headers
# LED's
# Switch
# Servomotor
# variable resistor
# 220 ohm resistors

 

Analog out:

potentiometer will control the Servomotor

 

 

code:

pulseWidth var byte
' set up constants with the minimum and maximum pulsewidths
minPulse CON 50
maxPulse CON 250
' set up a constant with the time between pulses:
refreshPeriod CON 20

' set an initial pulsewidth:
pulseWidth = minPulse

main:
'take the output pin low so we can pulse it high
Low PORTC.3
' pulse the pin
PulsOut PORTC.3, pulseWidth
' pause for as long as needed:
Pause refreshPeriod

' change the angle for the next time around:

IF pulseWidth > maxPulse Then
pulseWidth = minPulse
Else
pulseWidth = pulseWidth + 1
Endif

GoTo main