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
0 Comments:
Post a Comment
<< Home