Thanks Darrel,
I commented out my ADCON0 = %00000000 and put the loop back in, and confirmed my loop is looping. My result seems to be stuck at 24543, 40910 or 8142 each time I reset. Basically giving me random numbers as best I can tell. But despite the loop looping, the numbers do not change, until I remove power from the unit, then apply power again.
Code:DEFINE OSC 48 include "modedefs.bas" include "LCD_3310.pbp" TRISD = 0 PORTD.0 = 1 'turn on g sensor PORTD.1 = 0 'select scale for g sensor PORTD.2 = 0 'select scale for g sensor TRISA = %00000111 'set porta.0, 1, and 2 as inputs TRISB = 0 CM1CON = 7 CM2CON = 7 TRISC = 0 TRISE = 0 ADCON0 = %00000001 'turn on adc ADCON1 = %00000010 'fosc/32 ?? 'am I translating c language ADCON1=0x10 above correctly? resx var word x var word y var word z var word adval var word x=0 y=0 z=0 adval = 0 PORTD.0 = 1 'turn on g sensor (again) '************************************************* @ bsf WDTCON,ADSHR ;set shared address SFR with WTCON<4> - is this right? ADCON0 = %11111110 ' channel with a 0 is analog input, all others digital @ bcf WDTCON,ADSHR ADCON1 = %10111110 'right justified, AD=20AD, A/D clock=fosc/64 ADCON0.0 = 1 'turn on adc ADCON0.2 = 0 'channel select bit CHS0(should already be a 0) ADCON0.3 = 0 'Channel select bit CHS1(should already be a 0) start: Pause 500 ' Wait .5 second loop: ADCON0.1 = 1 'Start Conversion adval = 0 'clear result word notdone: pause 5 if ADCON0.1 = 1 Then notdone 'wait for low on bit-2 of ADCON0, conversion finished adval.highbyte = ADRESH 'move HIGH byte of result to adval adval.lowbyte = ADRESL 'move LOW byte of result to adval 'ADCON0 = %00000000 'turn off adc 'Lcdout $fe, 1 'Clear screen 'Lcdout "Value: ", DEC adval 'Display the decimal value x = x +1 'test to see if loop is working @ PrintStr 0,0, "Z= " ;display on Nokia 3310 @ PrintVar 24,0, _adval ;display result on 3310 @ PrintVar 0,1, _x ;show if loop is looping Pause 100 'Wait .1 second Goto loop 'Do it forever End




Bookmarks