'Aim: to use adc bits as inputs, apply sinusoidal input and
'upgrade the blink project a little further. The next step is going to
'be using interrupt.
'OpenADC(ADC_FOSC_32&ADC_RRIGHT_JUST&ADC_12_TAD,AD C_CH0&ADC_INT_OFF,0)
' I do not really know how to activate ADC, and use it. The above one
'is actually a c code.
Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
ADC_intstatus var PortB.0
On Interrupt Goto ADC_interrupt
INTCON=%10010000 ' Enable RBO interrupt
Outvalue var PORTD.0
adc_result var word ' Create adc_'result to store result
Outvalue= 0 'Set PORTD.0 output
TRISA = %11111111 'Set PORTA to all input, so I can use ADC
' bits as input
ADCON1 = %10000010' Set PORTA analog and right justify result
DISABLE
ADC_interrupt:
Pause 500 ' Wait .5 second while (Busy adc()) ' while it is busy keep it in a loop
ADCIN 0, adc_result ' Read channel 0 to adcresult
if adc_result> 125 then Outvalue =! Outvalue ' I thought if it is 8 bits, then 2^8=256
RESUME
ENABLE
End
Thanks for the comments, Skimask. I was busy studying as u suggested. It is the reason for the late reply. This is the new code, with 'interrupt' in it.
My pic is dead, I've ordered a new one. I cannot try it right now.
I'm working with PIC18F4550. Want to use A/D pins as inputs, and make PORTD.0 to blink led.
Bookmarks