Menu

using the Analog input

Help
2008-05-19
2013-05-30
  • Ryan Mystique

    Ryan Mystique - 2008-05-19

    I have a 12f675 and want to have it read the AN0 every 10 seconds and if the analog input is below 0.75volts turn on GPIO.1 and if it is above 0.75 volts turn on GPIO.2, I don't need to store the value or anything just real time monitoring, what code do I need for this, I tried using the light meter example to make a code but no success.
    Thanks,
    ryan

     
    • kent_twt4

      kent_twt4 - 2008-05-20

      How about the ReadAD example on the online help? http://gcbasic.sourceforge.net/help/

      Just substitute the Port pins, values x/256 = 0.75/5, and you are good to go.  If you are still having problems, then post your code.

       
    • Ryan Mystique

      Ryan Mystique - 2008-05-25

      I m getting a assembly error when I use this code, why?
      #chip 12F675, 4 'mhz
      #config OSC=INTOSC, MCLRE=off, WDT=off

      'Set the pin directions
      dir GPIO.0 in
      dir GPIO.1 out
      dir GPIO.2 out

      'Main routine
      Start:
      if ReadAD(AN0) >= 41 then set GPIO.1 on
      if ReadAD(AN0) < 41 then set GPIO.2 on

      goto start

       
    • kent_twt4

      kent_twt4 - 2008-05-26

      The configuration word error happens to me all the time, especially when cutting and pasting code to another device.  So I have to look up the device in the chipdata folder, to see what's allowed.  Thats going to be right 99% of the time, OSC=INTRC_OSC_NOCLKOUT.

       
    • Ryan Mystique

      Ryan Mystique - 2008-05-26

      the error is from the "IF" line because when I take it out it goes through, it says something about a undefined character

       
    • Ryan Mystique

      Ryan Mystique - 2008-05-26

      the message is :
      compiled.asm:125:Error [113] Symbol not prevously defined (CHS2).
      and
      compiled.asm:146:Error [113] Symbol not prevously defined (CHS2).

       
    • kent_twt4

      kent_twt4 - 2008-05-26

      Beg your pardon on the config, it looks to compile both ways.  This program compiles and works fine for me.

      Presuming you have GCBasic 9.3 installed, have you got the most recent update zip installed?  The error is from the a-d.h file, the 12f675 does not have a CHS2, so that's why you are getting that error.

      If the above still does not work, I have e-mailed you a copy of my a-d.h file, to keep you going.

       
    • Hugh Considine

      Hugh Considine - 2008-06-30

      For anyone who reads this later, Kent's a-d.h file is now included in update.zip. Please see http://gcbasic.sourceforge.net/update.html

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.