pic24_dspic33.py

Go to the documentation of this file.
00001 # This file is Copyright 2007, 2009 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 # 
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 ## @file
00014 #  @brief PIC24/dsPIC33-specific Python functions
00015 #
00016 
00017 """__NATIVE__
00018 #include <pic24_all.h>
00019 #include "pyFuncsInC.h"
00020 """
00021 
00022 ## This class provides basic digital I/O for the PIC.
00023 #  Configuring a given pin overrides any previous
00024 #  configuration (as an analog input, other digitial
00025 #  I/O, peripheral such as UART, SPI, etc.)
00026 class digital_io(object):
00027     ## Configures a pin for digital operation.
00028     #  Parameters:
00029     #  @param port The port, specified as a one-letter string,
00030     #              which must be from "A" to "G".
00031     #  @param pin  The pin of the port to configure. Must be
00032     #              a number between 0 and 15.
00033     #  @param isInput True to configure the pin as an input,
00034     #              false to configure the pin as an output.
00035     #  @param isOpenDrain True to configure the pin's output
00036     #              drivers to be 
00037     #              <a href="http://en.wikipedia.org/wiki/Open_collector">open drain</a>,
00038     #              false to configure the pin's output drivers
00039     #              as a standrard
00040     #              <a href="http://en.wikipedia.org/wiki/Totem_pole_output">push-pull</a>
00041     #              output. <em>IMPORTANT</em>: Not all pins
00042     #              have open-drain ability; therefore, the only
00043     #              valid selection for this parameter may be false.
00044     #              All pins have standard, push-pull drivers.
00045     #  @param pullDir A value > 0 to enable a 
00046     #              <a href="http://en.wikipedia.org/wiki/Pull-up_resistor">pull-up resistor</a>
00047     #              on the pin, a value < 0 to enable a pull-down
00048     #              resistor on the pin, or 0 to disable both.
00049     #              <em>IMPORTANT</em>: Not all pins have pull-up
00050     #              or pull-down capability. Valid values for
00051     #              some pins are 0 (neither pull-up nor pull-down
00052     #              resistors are available), or >=0 (only
00053     #              pull-up resistors are available).
00054     def __init__(self, port, pin, isInput, isOpenDrain=False, pullDir=0):
00055         """__NATIVE__
00056         return configDigitalPinPy(ppframe);
00057         """
00058         pass
00059 
00060     ## Set a pin's output to be high or low (True or False). The pin
00061     #  must be configured as an output for this value to appear on the pin.
00062     #  @param isHigh True to set the pin high, False to set it low.
00063     def set(self, isHigh):
00064         """__NATIVE__
00065         return setDigitalPinPy(ppframe);
00066         """
00067         pass
00068 
00069     ## Read a pin's value. If the pin is an input, read the pin;
00070     #  if it's an output, read the last value written.
00071     def get(self):
00072        """__NATIVE__
00073        return readDigitalValuePy(ppframe);
00074        """
00075        pass
00076 
00077     ## Read the current digital voltage (high or low / True or False) on
00078     #  a pin.
00079     def getPin(self):
00080        """__NATIVE__
00081        return readDigitalPinPy(ppframe);
00082        """
00083        pass
00084 
00085     ## Read the last value written to this pin (that is, the value stored
00086     #  in the pin's latch).
00087     def getLatch(self):
00088        """__NATIVE__
00089        return readDigitalLatchPy(ppframe);
00090        """
00091        pass
00092 
00093 
00094 ## This class provides basic analog input for the PIC.
00095 #  Configuring a given pin overrides any previous
00096 #  configuration (as a digital input, other digital
00097 #  I/O, peripheral such as UART, SPI, etc.)
00098 class analog_input(object):
00099     ## Create the class for a specific analog pin, numbered ANxx on the
00100     #  data sheet. Configures the pin as an analog input.
00101     #  @param analogPin Pin to configure.
00102     def __init__(self, analogPin):
00103         """__NATIVE__
00104         return configAnalogPinPy(ppframe);
00105         """
00106         pass
00107 
00108     ## Read the code produced by the ADC, a value from 0 to 4095
00109     #  which is linearly proportional to the input voltage.
00110     def getCode(self):
00111         """__NATIVE__
00112         return readAnalogCodePy(ppframe);
00113         """
00114         pass
00115 
00116     ## Read the voltage produced by the ADC, resulting in a
00117     #  returned value between 0 and 3.3V.
00118     def getVoltage(self):
00119         """__NATIVE__
00120         return readAnalogFloatPy(ppframe, 3.3/4096.0);
00121         """
00122         pass
00123 
00124     ## Read the voltage produced by the ADC, resulting in a
00125     #  normalized value ranging from 0 to 1.
00126     def getNorm(self):
00127         """__NATIVE__
00128         return readAnalogFloatPy(ppframe, 1.0/4096.0);
00129         """
00130         pass
00131 
00132 ## This class provides basic control of the pulse-width
00133 #  modulation peripheral for the PIC.
00134 class pwm(object):
00135     ## Create the class instance for a PWM output.
00136     #  @param freq Frequency at which the PWM will operate, in Hz.
00137     #  @param isTimer2 True to use timer2, false to use timer3 for
00138     #      PWM.
00139     #  @param oc Output compare module to use.
00140     #  @param ocPin For remappable devices, the port P pin on
00141     #      which to map the PWM output. For non-remappable devices,
00142     #      this value must be < 0.
00143     def __init__(self, freq, isTimer2, oc, ocPin=-1):
00144         """__NATIVE__
00145         return configPwmPy(ppframe);
00146         """
00147         pass
00148 
00149     ## Set the duty cycle for a PWM output.
00150     #  @param ratio The desired duty cycle, ranging from 0 (off
00151     #      completely) to 1 (maximum, 100% duty cycle).
00152     def set(self, ratio):
00153         """__NATIVE__
00154         return setPwmRatioPy(ppframe);
00155         """
00156         pass
00157 
00158     ## Set the duty cycle for a PWM output.
00159     #  @param counts The number of PR2/3 counts which gives the on
00160     #      time of the PWM wave to generate.
00161     def setCounts(self, counts):
00162         """__NATIVE__
00163         return setPwmCountsPy(ppframe);
00164         """
00165         pass
00166 

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9