Thursday, July 28, 2005

Thinking about Final Project, vol. 02




'set m-sensor into AN0
'set motor PWM into PORTD.1
'set speaker PWM into PORTD.0
' OSC=Oscirator 4mhz
' It's not necessary but recommended
DEFINE OSC 4

start:
'Analog definifition

DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 10
' Set sampling time in uS
' Usually 50 but 10 or 50 not so much different
' Create variable to store result

'motor value, sound value
ADCvar VAR word
motorVal VAR byte
soundVal VAR byte

' Set PORTA to all input
TRISA = %11111111
' Set PORTA analog and right justify result
ADCON1 = %10000010

'set Lighting Trigger OUTPUT into portb.7
'set LED of FAN OUTPUT into portb.6
OUTPUT portb.7
OUTPUT portb.6

main:
ADCIN 0, ADCvar
' Read channel 0 to adval
'ADCvar = ADCVar/4
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out, '
' with linefeed and carriage return (10, 13)

'If I stay closer to the FAN, the FAN will start to rotate,
'simultaneouly speaker, lighting trigger too.
if ADCVar >= 100 then
HIGH portb.7
HIGh portb.6
motorVal = ADCVar/8
soundVal = ADCVar/8

PWM portd.1,motorVal,10
PWM portd.0,soundVal,10
else
LOW portd.0
LOW portd.1
LOW portb.7
LOW portb.6
endif

'PWM comment ---, duty of square wave , cycle of square wave of frequency
'pwm portd.2,ADCVar,100
'Use HPWM instead of PWM, this is HARDWARE PWM.
'Put HPWM to portc.1 (Only either portc.1 or portc.2 of pic can be used for HPWM )
'This means, use HPWM into portc.2, CCP1 and use ADCvar with 1000 frequency for MOTOR
'(1000 is appropriate, sometimes 200 is possible as low frequency.)
'FREQOUT PORTd.2,2000,ADCvar*100
'This is new syntax for speaker
'This means FREQOUT into PORTd.2 as 2000 and ADCvar X 100
'(FREQOUT needs a lot of number)
GoTo main

Tuesday, July 26, 2005

Thinking about Final Project, vol. 01




TIP120
base: from PIC (PWM is coming to TIP)
corrector: "hold" some "statement" (go to Motor movement)
emitter: GND (go to GND)


Sunday, July 24, 2005

HPWM

This is TIP for Microprocessors,
http://www.toddholoubek.com/systems/systems/microprocessor/microprocessor.html
About HPWM:
There are 2 ports for use for HPWM
CCP2...RC1
CCP1...RC2

Thursday, July 21, 2005

New Parts: TIP120, 2N2222

This is example for DC motor.
Transistor 2N2222
Voltage Regulator TIP120


HPWM: Pot & FREQOUT: speaker


'set pot into AN0
' OSC=Oscirator 4mhz
' It's not necessary but recommended
DEFINE OSC 4
start:
'This is Analog definifition
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS
ADCvar VAR word
' Create variable to store result
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
' this means switch

input portb.0
' This means information for motor rotation.
output portd.0
output portd.1
'how to know where pot isoutput portb.7
main:
ADCIN 0, ADCvar
' Read channel 0 to adval
' serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)
ADCVar = ( ADCvar / 17)
'loop
'If the switch is off
'if ADCVar <= 125 then

high portb.7
'make pin 2 high
'These mean for motor

high portd.1
'make pin 1 low
low portd.0
'PWM comment, duty of square wave , cycle of square wave of frequency
'pwm portd.2,ADCVar,100
'Use HPWM instead of PWM, this is HARDWARE PWM.
'Put HPWM to portc.1 (Only either portc.1 or portc.2 of pic can be used for HPWM )
'This means, use HPWM into portc.2, CCP1 and use ADCvar with 1000 frequency.
'(1000 is appropriate, sometimes 200 is possible as low frequency.)
hpwm 1,ADCVar,1000
'HPWM 2,ADCvar, 1000
FREQOUT PORTd.2,2000,ADCvar*100
'else
'low portb.7
'make pin 2 high
'These mean motor stops
'low portd.1
'make pin 1 low
'low portd.0
'endif
'end loop
GoTo main

----------------------------------------------------

Wednesday, July 20, 2005

DCmotor & its Velocity Controled by Pot dialing


'set pot into AN0'
OSC=Oscirator 4mhz
' It's not necessary but recommended
DEFINE OSC 4
start:
'This is Analog definifition
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS

ADCvar VAR word
' Create variable to store result
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
' this means switch

input portb.0
' This means information for motor rotation.
output portd.0
output portd.1
'how to know where pot is
output portb.7
main:
ADCIN 0, ADCvar
' Read channel 0 to adval
' serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)
ADCVar = ( ADCvar / 17)
'loop
'If the switch is off
'if ADCVar <= 125 then

high portb.7
'make pin 2 high
'These mean for motor
high portd.1
'make pin 1 low
low portd.0
'PWM comment ---duty of square wave , cycle of square wave of frequency
pwm portd.2,ADCVar,100
'else
'low portb.7
'make pin 2 high
'These mean motor stops
'low portd.1
'make pin 1 low
'low portd.0
'endif

'end loop
GoTo main

Saturday, July 16, 2005

DCMotor Control Pot Photocell

'"When the switch is on, the motor is going to rotate."

' Set the motor (see page258) and the switch into portb.0
' this means switch
input portb.0
' This means information for motor rotation
' because motor is connected by portd.0 and portd.1
output portd.0
output portd.1
main:
'loop
'If the switch is on, then...

if portb.0 = 1 then
'Motor is going to rotate
'make pin 1 (=portd.0) high
high portd.0
'make pin 2 (=portd.1) low
low portd.1
'Otherwise motor is stopped.
else
'make pin 2 high
LOW portd.1
'make pin 1 low
LOW portd.0
'if I want to make the motor is going to rotate backwards, I say
'LOW portd.1
'HIGH portd.0 (but this can't rotate backwards)
endif
'end loop
goto main

-------------------------------------------------------------------------
'"Make the switch stop with dialing Pot"

'set pot into AN0
' OSC=Oscirator 4mhz
' It's not necessary but recommended
DEFINE OSC 4
start:
'This is Analog INPUT definifition
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS
ADCvar VAR word
' Create variable to store result
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
' this means switch

input portb.0
' This means information for motor rotation.
output portd.0
output portd.1
'Set LED into portd.7 and know where pot is dialed now.
output portb.7
main:
ADCIN 0, ADCvar
' Read channel 0 to adval
ADCVar = ( ADCvar / 17)
'loop
'If the switch is off
'if ADCVar <= 125 then

high portb.7
'make LED high
'These mean for motor

high portd.1
'make pin 1 low
low portd.0
'PWM comment ---, duty of square wave , cycle of square wave of frequency
pwm portd.2,adcvar,100
'else'
low portb.7
'make pin 2 high
'These mean motor stops
'low portd.1
'make pin 1 low
'low portd.0
'endif

'end loop
GoTo main

--------------------------------------------------------------------------





''Photocell & 10K ohm are always together."
'set photocell into AN0 (Usually need 20 ohm resistor with photocell)
'photocell-can work as a sensor for the lightness.
'OSC=Oscirator 4mhz (crystal, capasitor)
'This define is not necessary but highly recommended

DEFINE OSC 4
start:
'This is Analog definifition
DEFINE ADC_BITS 10
'Set number of bits in result
DEFINE ADC_CLOCK 3
'Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
'Set sampling time in uS

'This is necessary for Analog INPUT = photocell
ADCvar VAR word
'Create variable to store result
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result

' this means switch (This is not working right now.)
input portb.0
' This means information for motor rotation.

'See motor is connected to portd.0 and portd.1
output portd.0
output portd.1
'how to know where pot is
'(Set LED into portb.7 and see where I am with dailing pot or shut the light for photocell.)
output portb.7

main:
'Analog Syntax (Sensor) IN
ADCIN 0, ADCvar
' Read channel 0 to adval
' serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out, '
' with linefeed and carriage return (10, 13)
'Try to change /"17" or another number for use divided and see the motor motion
ADCVar = ( ADCvar / 17)
'loop
'If the switch is off
'Just in case, <=, instead of only, <
high portb.7
'makes portb.7 high (LED)
'These mean for motor
high portd.1
low portd.0
'In order to use PWM, I need this statement.
'PWM comment ---, "duty" of square wave of frequency, "cycle" of square wave of frequency
pwm portd.2,ADCVar,100
'else
'low portb.7
'make pin 2 high
'These mean motor stops
'low portd.1
'make pin 1 low
'low portd.0
'endif
'end loop
GoTo main



Wednesday, July 13, 2005

How to see where I am picking now





Detach the serial cable from your serial output pin.
Attach an LED to the serial output pin with 220 ohm resistor through PIC.
Notice how the LED blinks when you are sending serial messages.
This can be an excellent way to test to make sure your chip is properly sending serial data out.

'Create frame animation 0-255, and send the data to computer, I can see the frame one by one.

Use Hyper Terminal / Debug Statements

'Run from Start menu, type "hypertrm"
Configure the connection for 9600 bits per second, 8 data bits, no parity, 1 stop bit, and no flow control, and save as my name, "yoshie HTerminal"


'Set serial cable to the breadboard.
' serial out is on portc.6 (transmit)
' serial in is on portc.7 (recieve)
' a digital input is on portb.0 (switch) : "DIGITAL"

'set a constant with the baudmode 9600-8-n-1-inverted:
inv9600 con 16468

' a byte to send out data:
thisByte var byte

' set portb.0 to input:
input portb.0

pause 500
' start program with a half-second delay

main:
' read the switch, convert it to a readable ASCII value:
thisByte = portb.0

' send it out the serial port:
serout2 portc.6, inv9600, [DEC thisByte]

goto main

--------------------------------

'Set Potentiometer to RA0: "ANALOG"

' PicBasic Pro program to display result of'
'10-bit A/D conversion through serial at 9600 baud''
'Connect analog input to channel-0 (RA0)
' Define ADCIN parameters
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS
'This is really necessary, use for VAR, see which I am using below as VAR

ADCvar VAR WORD
' Create variable to store result
thisByte Var byte
'This is really necessary for Analog Input
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
Pause 500
' Wait .5 second
'Set serial cable to the breadboard.

' serial out is on portc.6 (transmit)
' serial in is on portc.7 (recieve)
'set a constant with the baudmode 9600-8-n-1-inverted:
inv9600 con 16468
' a byte to send out data: convert WORD to BYTE

thisByte = ADCvar / 4
' instead of "thisByte VAR BYTE"

main:
'Always put this syntax here, means
'Read Channel 0 (wherever RA0-7, analog input is connected) to adva
ADCIN 0, ADCvar
' Read channel 0 to adval
'convert ADCVAR to BYTE
thisByte = ADCvar / 4
' send it out the serial port:
serout2 portc.6, inv9600, [DEC thisByte]
goto main

'Result: I can see 0 - 255 on the screen of Hyper Terminal

Monday, July 11, 2005

Servo Motor Pulse-Width var, POT



'set servoMotor into RC3
'set pot into AN0

' OSC=Oscirator 4mhz
DEFINE OSC 4

start:
'This is Analog definifition
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS

ADCvar VAR word
'ADCvar VAR byte
'ADCvar VAR byte
'ADCvar VAR byte

' Create variable to store result
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
pulseWidth var byte
' set up constants with the minimum and maximum pulsewidths
'constant
minPulse CON 50
'minPulse CON 50
'minPulse CON 0
'minPulse CON 50

maxPulse CON 250
'maxPulse CON 250
'maxPulse CON 255
'maxPulse CON 250


' set up a constant with the time between pulses:
refreshPeriod CON 20

' set an initial pulsewidth:
pulseWidth = minPulse

main:
ADCIN 0, ADCvar
' Read channel 0 to adval
' serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out, '
' with linefeed and carriage return (10, 13)

ADCVar = ( ADCvar / 4 )
'ADCVar = ADCvar + 50

'------ (nothing about ADCVar definition)

'------ (nothing about ADCVar definition)


'take the output pin low so we can pulse it high
Low PORTC.3
' pulse the pin
PulsOut PORTC.3, ADCVAr
' 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

Servo Motor Pulse-Width var




'set servoMotor into RC3
'OSC=Oscillator 4MHZ
DEFINE OSC 4

start:
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

Sunday, July 10, 2005

5LED blink and assign speed-change & switch with 2 potentiometers



'Set 5LEDs to portd.1, portd.0, portc.3, portc.2, portc.1 and set potentiometer (dail) to RA1, set potentiometer (slider) to RA0

' PicBasic Pro program to display result of
' 10-bit A/D conversion through serial at 9600 baud
' Connect analog input to channel-0 (RA0)

' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

'ADCvar0 means potentionmeter (slider) set into porta.0
ADCvar0 VAR WORD
' Create variable to store result
'ADCvar1 means potentionmeter (dial) set into porta.1
ADCvar1 VAR WORD
' Create variable to store result

TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result

'this defines a variable for the switch
switchVar var byte
'this defines a variable for the speed
speedVar var word
'speedvar = 200


'defining portb.0 as INPUT (This is another circuit)
input portb.0
'defining portb.7 as OUTPUT (This is another circuit)
output portb.7



Pause 500
' Wait .5 second


main:
'ADCIN Channel,Variablename
ADCIN 0, ADCvar0
' Read channel 0 to adval
ADCIN 1, ADCvar1
' Read channel 1 to adval
serout2 PORTC.6, 16468, [DEC ADCvar0, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)

'this code means portb.7 = the state of the switch (condition)
switchVar = portb.0
'Define Switchvar, equation order is important. Do not write down here as portb.7=switchvar
portb.7 = switchVar

if ADCVAR0 < 500 then
'If the potentiometer (slider) is less than 500
speedVar = (ADCvar1 / 4) +10
'Speed (LED-blink) will be changed with dialing of potentiometer (dial)
'everytime (devided by 4) plus 10 in order to NOT get NO-RESULT
high portd.1
pause speedvar
'instead of PAUSE 200 (We may write down PAUSE 200 here instead of PAUSE speedvar)
low portd.1
pause speedvar
high portd.0
pause speedvar
low portd.0
pause speedvar
high portc.3
pause speedvar
low portc.3
pause speedvar
high portc.2
pause speedvar
low portc.2
pause speedvar
high portc.1
pause speedvar
low portc.1
pause speedvar

endif
GoTo main
' Do it forever

Friday, July 08, 2005

Binary Reflects LED blinks, change blink-velocity

'How can we change the velocity of LED blink with dialing Pot?


COMING SOON


'Set 8LED to portb-line, For X=0 to 250
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS
'x, holder name of place

x var byte
trisb = %00000000
pause 500
' start program with a half-second delay
main:
'This line sets a random number between 0 - 255
for x = 0 to 255
portb = x
'send the random number to the ports in b line
pause 250
serout2 PORTC.6, 16468, [DEC x, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)
next
pause 750
goto main

Thursday, July 07, 2005

Binary Reflects LED blinks, see binary through Serial


'0 = all LED is light OFF, 255 = all LED is light ON.


DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

'x, holder name of place
x var byte
'zero var word
'one var word
'two var word
'three var word
'four var word
'five var word
'six var word
'seven var word
'turn those pin

'Set PORTB to all output
trisb = %00000000

pause 500
main:
'This line sets a random number between 0 - 255
for x = 0 to 255
portb = x
'send the random number to the ports in b line
pause 250
'adcin 0, zero 'send number of portb.0 to var zero
'adcin 1, one 'send number of portb.1 to var one
'adcin 2, two
'adcin 3, three
'adcin 4, four
'adcin 5, five
'adcin 6, six
'adcin 7, seven

'serout2 PORTC.6, 16468, [DEC zero, 13, 10]
'serout2 PORTC.6, 16468, [DEC one, 13, 10]
'serout2 PORTC.6, 16468, [DEC two, 13, 10]
'serout2 PORTC.6, 16468, [DEC three, 13, 10]
'serout2 PORTC.6, 16468, [DEC four, 13, 10]
'serout2 PORTC.6, 16468, [DEC five, 13, 10]
'serout2 PORTC.6, 16468, [DEC six, 13, 10]
'serout2 PORTC.6, 16468, [DEC seven, 13, 10]

serout2 PORTC.6, 16468, [DEC x, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)

next
pause 750
goto main

Binary Reflects LED blinks

'Set 8 LEDs into RB0 through RB7 and see this motion.

x var byte
trisb = %00000000
pause 500
' start program with a half-second delay

main:
for x = 0 to 255
portb = x
pause 500
next
pause 1500
goto main

Wednesday, July 06, 2005

Switch Var, counts the number of times the switch has been switched on

'Set Switch to RB0 and set LED to RB7
'this defines a variable for the switch
switchedOnVar var byte
'defining portb.0 as INPUT
input portb.0
'rest 500
pause 500
' start program with a half-second delay
main:
'If portb.0 is ON
if portb.0 = 1 then
'variable counts variable + 1 means, during switch on, program is running more and more. switchedOnVar = switchedOnVar + 1
endif'
'print it to serial out with linefeed and carriage return (10, 13)
serout2 portc.6, 16468, [DEC switchedOnVar, 13,10]
goto main

Tuesday, July 05, 2005

Switch Var, during Switch ON, LED lights


'Set Switch to portb.0 and set LED to portb.7
'During the switch on, LED lights.
switchVar var byte
'Switch as INPUT
input portb.0
'LED as OUTPUT
output portb.7
pause 500
' start program with half-second delay
main:
'this code means portb.7, LED = the state of the switch (condition)
switchVar = portb.0
portb.7 = switchVar
goto main

Monday, July 04, 2005

Analog Input with 2 Pots & Switch--5 LED blink


' PicBasic Pro program to display result of'
10-bit A/D conversion through serial at 9600 baud
' Connect analog input to channel-0 (RA0)
' Define ADCIN parameters
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS

'ADCvar0 means potentiometer(slider) porta.0
ADCvar0 VAR WORD
' Create variable to store result

'ADCvar1 means potentiometer (dial) porta.1
ADCvar1 VAR WORD
' Create variable to store result

TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result

'this defines a variable for the switch
switchVar var byte
'this defines a variable for the speed
speedVar var word
'speedvar = 200

'defining portb.0 as INPUT (---LED is set into portb.0)
input portb.0
'defining portb.7 as OUTPUT (---Switch is set into portb.7)
output portb.7

Pause 500
' Wait .5 second

main:
'ADCIN Channel,Variablename
ADCIN 0, ADCvar0
' Read channel 0 to adval
ADCIN 1, ADCvar1
' Read channel 1 to adval

serout2 PORTC.6, 16468, [DEC ADCvar0, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)

'this code means portb.7 = the state of the switch (condition)
switchVar = portb.0
portb.7 = switchVar

if ADCVAR0 < 500 then
speedvar = (ADCvar1 / 4) +10
'everytime (devided by 4) plus 10 means, in order to NOT get NO-RESULT when we use potentiometer (dial).

high portd.1
pause speedvar
'instead of PAUSE 200
low portd.1
pause speedvar
high portd.0
pause speedvar
low portd.0
pause speedvar
high portc.3
pause speedvar
low portc.3
pause speedvar
high portc.2
pause speedvar
low portc.2
pause speedvar
high portc.1
pause speedvar
low portc.1
pause speedvar
endif
GoTo main
' Do it forever

Sunday, July 03, 2005

Analog Input with Pot and LED blink

'This is Basic for Analog INPUT
' PicBasic Pro program to display result of'
'10-bit A/D conversion through serial at 9600 baud''
Set Potentiometer to channel-0 (RA0)
'Analog has 8 channel, RA0 - RA4, AN4 -AN7

'This is really necessary for Analog Input
' Define ADCIN parameters
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS

'This is really necessary, use for VAR
ADCvar VAR WORD
' Create variable to store result

'This is really necessary for Analog Input
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
Pause 500
' Wait .5 second

main:
'Always put this syntax here, means
'Read Channel 0 (wherever RA0-7, analog input is connected) to adval
ADCIN 0, ADCvar
' Read channel 0 to adval
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out,
' with linefeed(add the line from up and down) and carriage(add the text horizontally) return (10, 13)
GoTo main
' Do it forever

------------------------------






'Set Potentiometer to RA0 and set LED to portd.1

' PicBasic Pro program to display result of'
'10-bit A/D conversion through serial at 9600 baud''
'Connect analog input to channel-0 (RA0)

' Define ADCIN parameters
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS

ADCvar VAR WORD
' Create variable to store result
TRISA = %11111111
' Set PORTA to all input (---potentiometer is set into RA0 as Analog INPUT)
ADCON1 = %10000010
' Set PORTA analog and right justify result (---Analog Justify)

Pause 500
' Wait .5 second
main:
ADCIN 0, ADCvar
' Read channel 0 to adval

'''''' This is additional if-statement. If the pot is more than 500,
if ADCVAR > 500 then

'LED of portd.1 blinks.
high portd.1
pause 200
low portd.1
pause 200

'Otherwise,
else
high portd.1
endif
pause 100

additional if-statement is ended''''''

'Serial Cable connects RC6 as RX (receive) and RC7 as TX (transmit)
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)
GoTo main
' Do it forever

Saturday, July 02, 2005

Switch makes 3LEDblink.

'Set the Switch to portb.1 and set LED to portd.1, portd.0 , portd.3
input portb.1
output portd.1
main:
'When Switch is ON,
if portb.1 = 1 then
'portd.1 is off.
low portd.1
else
'otherwise, blink.
high portd.1
pause 500
high portd.0
pause 500
high portd.3
pause 500
low portd.1
pause 500
low portd.0
pause 500
low portd.3
pause 500
endif
goto main

Friday, July 01, 2005

Switch makes LED blink



'Set the switch to portb.0 and set LED to portd.0
input portb.0
output portd.0
main:
if portb.0 = 1 then
' if the switch is closed on pin RB0
low portd.0
' set pin RD0 low
else
high portd.0
' set RD0 high
endif
goto main