'---------------------------------------------------------------------------------------- ' ' Solar Experiments PICAXE Code ' ' file: picaxe_solar_basic.bas ' ' created: 6-30-2009 ' updated: 6-30-2009 ' ' owner: LearnOnLine, Inc. ' author: John Gavlik ' ' created for the PicAxe 28X2 microprocessor uisng internal 8Mhz oscillator ' '---------------------------------------------------------------------------------------- '---------------------------------------------------------------------------------------- ' ' A/D Setup - Use all A/D channels ' '---------------------------------------------------------------------------------------- let adcsetup = %0000000011111111 'use ADC0,1,2,3,8,9,10,11,12 '---------------------------------------------------------------------------------------- ' ' Defines ' '---------------------------------------------------------------------------------------- #com4 'change com port number to match your system #picaxe 28X2 'don't change this!!! '---------------------------------------------------------------------------------------- ' ' Important I/O Pins for PIC 28X2 Microprocessor ' '---------------------------------------------------------------------------------------- ' voltage ADC11 pin 25 ' oneOhmDrop ADC12 pin 21 ' serin pin 6 ' serout pin 7 ' reset pin 1 ' gnd pin 8 & 19 ' +5v pin 20 '---------------------------------------------------------------------------------------- ' ' Variables ' '---------------------------------------------------------------------------------------- symbol i = b0 symbol cksum = b1 'for data transmission to PC symbol voltage = w1 'input voltage symbol current = w2 'computed current '---------------------------------------------------------------------------------------- ' ' Main Routine ' '---------------------------------------------------------------------------------------- Solar_Exp: GOSUB Get_Solar_Panel_Voltage ' get current measurement and convert to millivolts current = 0 ' no current measurement GOSUB Plot_It ' transmit the value to the computer pause 300 ' allow computer to process data GOTO Solar_Exp ' Repeat '---------------------------------------------------------------------------------------- ' ' Sub Routines ' '---------------------------------------------------------------------------------------- Get_Solar_Panel_Voltage: readadc10 11,voltage voltage = voltage */$04E1 'convert count to millivolts (multiply by 4.88 mv/count) return '---------------------------------------------------------------------------------------- '---------------------------------------------------------------------------------------- ' ' Note: Keep the bytes in the order shown as the PC software depends on having them transmitted ' exactly in this sequence. ' Plot_It: cksum = b3 + b2 + b5 + b4 serout A.4,N9600_8,(b3,b2,b5,b4,cksum) return '---------------------------------------------------------------------------------------- end