PComp Assignment 3
Posted on September 29, 2005 at 10:38 PM by sj695
For this week's assignment we are to communicate with a computer with our pic chip via the serial port. In the last week's lab I used a potentiometer instead of a switch to turn on the led, so this weeks lab was quite simple requiring nothing more than code midification. I must say it was quite amazing to see those numbers run down the screen in hyperterminal.
Here is the code I used:
' 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
ADCON1 = %10000010 ' Set PORTA analog and right justify result
Pause 500 ' Wait .5 second
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)
GoTo main ' Do it forever
