pic14.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004-2005 by Daniel Clarke                              *
00003  *   daniel.jc@gmail.com                                                   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef PIC14_H
00022 #define PIC14_H
00023 
00024 #include "expression.h"
00025 #include "microbe.h"
00026 
00027 #include <qstring.h>
00028 #include <qstringlist.h>
00029 #include <qvaluelist.h>
00030 
00031 class Code;
00032 class Microbe;
00033 class Parser;
00034 
00038 class PortPin
00039 {
00040         public:
00041                 PortPin( const QString & port, int pin );
00045                 PortPin();
00049                 QString port() const { return m_port; }
00053                 int portPosition() const;
00057                 int pin() const { return m_pin; }
00058                 
00059         protected:
00060                 QString m_port;
00061                 int m_pin;
00062 };
00063 typedef QValueList<PortPin> PortPinList;
00064 
00065 
00070 class PIC14
00071 {
00072         public:
00073                 enum Type
00074                 {
00075                         P16C84,
00076                         P16F84,
00077                         P16F627,
00078                         P16F628,
00079                         unknown,
00080                 };
00081                 enum LocationType
00082                 {
00083                         num = 1,
00084                         work = 2,
00085                         var = 3,
00086                 };
00090                 enum DelaySubroutine
00091                 {
00092                         Delay_None      = 0,
00093                         Delay_3uS       = 1,
00094                         Delay_768uS     = 2,
00095                         Delay_200mS     = 3,
00096                         Delay_50S       = 4,
00097                 };
00098                 
00099                 PIC14( Microbe * master, Type type );
00100                 ~PIC14();
00101                 
00106                 static Type toType( const QString & text );
00110                 Type type() const { return m_type; }
00114                 QString minimalTypeString() const;
00120                 PortPin toPortPin( const QString & portPinString );
00124                 uchar gprStart() const;
00125                 
00126                 void setParser(Parser *parser) { m_parser = parser; }
00127                 void setCode( Code * code ) { m_pCode = code; }
00128                 void mergeCode( Code * code );
00129         
00130                 void setConditionalCode( Code * ifCode, Code * elseCode );
00131                 Code * ifCode();
00132                 Code * elseCode();
00133         
00134                 Code * m_ifCode;
00135                 Code * m_elseCode;
00136 
00137                 void postCompileConstruct( const QStringList &interrupts );
00138 
00143                 bool isValidPort( const QString & portName ) const;
00148                 bool isValidPortPin( const PortPin & portPin ) const;
00149                 bool isValidTris( const QString & trisName ) const;
00150                 bool isValidInterrupt( const QString & interruptName ) const;
00151 
00152                 void Sgoto(const QString &label);
00153                 void Slabel(const QString &label);
00154                 void Send();
00155                 void Ssubroutine(const QString &procName, Code * compiledProcCode);
00156                 void Sinterrupt(const QString & procName, Code * compiledProcCode);
00157                 void Scall(const QString &name);
00158         
00159                 void Ssetlh( const PortPin & portPin, bool high);
00160         
00161                 void add( QString val1, QString val2, LocationType val1Type, LocationType val2Type );
00162                 void subtract( const QString & val1, const QString & val2, LocationType val1Type, LocationType val2Type );
00163                 void mul( QString val1, QString val2, LocationType val1Type, LocationType val2Type);
00164                 void div( const QString & val1, const QString & val2, LocationType val1Type, LocationType val2Type);
00165         
00166                 void assignNum(const QString & val);
00167                 void assignVar(const QString & val);
00168         
00169                 void saveToReg(const QString &dest);
00174                 void saveResultToVar( const QString & var );
00176                 void equal( const QString &val1, const QString &val2, LocationType val1Type, LocationType val2Type );
00178                 void notEqual( const QString &val1, const QString &val2, LocationType val1Type, LocationType val2Type );
00180                 void greaterThan( const QString &val1, const QString &val2, LocationType val1Type, LocationType val2Type );
00182                 void lessThan( const QString &val1, const QString &val2, LocationType val1Type, LocationType val2Type );
00184                 void greaterOrEqual( const QString &val1, const QString &val2, LocationType val1Type, LocationType val2Type );
00186                 void lessOrEqual( const QString &val1, const QString &val2, LocationType val1Type, LocationType val2Type );
00187 
00188                 void bitwise( Expression::Operation op, const QString &val1, const QString &val2, bool val1IsNum, bool val2IsNum );
00189         
00190                 void Swhile( Code * whileCode, const QString &expression);
00191                 void Srepeat( Code * repeatCode, const QString &expression);
00192                 void Sif( Code * ifCode, Code * elseCode, const QString &expression);
00193                 void Sfor( Code * forCode, Code * initCode, const QString &expression, const QString &variable, const QString &step, bool stepPositive);
00194         
00195                 void Spin( const PortPin & portPin, bool NOT);
00196                 void addCommonFunctions( DelaySubroutine delay );
00197         
00198                 //BEGIN "Special Functionality" functions
00204                 void Sdelay( unsigned length_us, Code::InstructionPosition pos = Code::Middle );
00210                 void SsevenSegment( const Variable & pinMap );
00215                 void Skeypad( const Variable & pinMap );
00216                 //END "Special Functionality" functions
00217         
00218                 void SincVar( const QString &var );
00219                 void SdecVar( const QString &var );
00220                 void SrotlVar( const QString &var );
00221                 void SrotrVar( const QString &var );
00222         
00223                 void Stristate( const QString &port );
00224         
00225                 void Sasm(const QString &raw);
00226         
00227         protected:
00228                 void multiply();
00229                 void divide();
00230         
00232                 Type m_type;
00233         
00234                 Parser * m_parser;
00235                 Microbe * mb;
00236                 Code * m_pCode;
00237         
00238                 void ifInitCode( const QString &val1, const QString &val2, LocationType val1Type, LocationType val2Type );
00239         
00245                 void rearrangeOpArguments( QString * val1, QString * val2, LocationType * val1Type, LocationType * val2Type);
00246         
00250                 int interruptNameToBit(const QString &name, bool flag);
00251 };
00252 
00253 #endif

Generated on Tue May 8 17:05:31 2007 for KTechLab by  doxygen 1.5.1