
////-------------		Definitionen		---------------------
//#define RM_RESET_VECTOR            0x000800 // define relocated vector addresses
//#define High_Priority_IRQ   0x000808
//#define Low_Priority_IRQ    0x000818

#define EP1IN_Count_Adrs    0x40D
#define BD1iADRL_Adrs       0x40E
#define BD1iADRH_Adrs       0x40F
#define EP1_OUT_BUFF_Adrs	0x420
#define	EP1_IN_BUFF_Adrs 	0x460           // Für Daten zum PC-Host schicken          
#define	Daten_Buffer_Adrs	0x4A0           // Für gesendete daten vom PC-Host
//#define EP1_BUFF_SIZE       0x40            // 64 Byte
//// EP0_IN_BUFF           res	8	    // von 0x418 bis	0x420	(equal the EP0_BUFF_SIZE)
//// EP1_OUT_BUFF			res	0x40	// von 0x420 bis	0x460
//// EP1_IN_BUFF			res	0x40	// von 0x460 bis	0x4A0
//// Daten_Buffer			res	0x40	// von 0x4A0 bis	0x4E0	
////-------------		Timer0 Definitionen		---------------------
#define	T0PS_Maske	0xF8		// b'1111.1000,zum clear des prescalar bit
// T0-flag Bit definitionen 
//#define	T0_OVF		b0	//Timer 0 Overflow bit,in IRQ=LOW gesetzt 	

/** S T R U C T U R E S ******************************************************/

//typedef union _USER_DATA
//{
////    byte _byte[USBGEN_EP_SIZE];  	// for byte access
////    word _word[USBGEN_EP_SIZE/2];	// for word access(USBGEN_EP_SIZE must be even)
//    struct
//    {
//        enum
//        {
//			LCD				= 0x00,		// LCD 
//			ADC_cfg         = 0x01,		// ADC configurieren und/oder Benutzen
//			PWM_cfg			= 0x02,		// CMD:2  PWM   configurieren
//			Flash_RD		= 0x03,		// CMD:3  flash read
//			COM_cfg			= 0x04,		// CMD:4 Comperator Configurieren
//			RAM_RD			= 0x05,		// CMD:5	RAM Lesen
//			Sample_RD		= 0x06		// CMD:6	448 Sample(7*64) aus 0x460...7E0 aus RAM Lesen            
//        }CMD;
//    };
//    struct
//    {
//        byte DATA[63];
//    };
//
//} USER_DATA;

/** T Y P E S ****************************************************************/
typedef unsigned char   byte;           // 8-bit
//typedef unsigned int    word;           // 16-bit
//typedef unsigned long   dword;          // 32-bit

typedef union _BYTE
{
    byte _byte;
    struct
    {
        unsigned b0:1;
        unsigned b1:1;
        unsigned b2:1;
        unsigned b3:1;
        unsigned b4:1;
        unsigned b5:1;
        unsigned b6:1;
        unsigned b7:1;
    };
} BYTE;
//typedef union _POINTER
//{
//    struct
//    {
//        byte bLow;
//        byte bHigh;
//        byte bUpper;
//    };
////    word _word;           // bLow & bHigh   
//    //pFunc _pFunc;         // Usage: ptr.pFunc(); Init: ptr.pFunc = &<Function>;
//    ram near byte* bRam;    // Ram byte pointer: 2 bytes pointer point                 			// to 1 byte of data
////    word* wRam;        	// Ram word poitner: 2 bytes poitner pointing
//                         	// to 2 bytes of data
// //   rom far byte* bRom;       // Size depends on compiler setting
////    rom word* wRom;
//    //rom near byte* nbRom;    // Near = 2 bytes pointer
//    //rom near word* nwRom;
//    //rom far byte* fbRom;     // Far = 3 bytes pointer
//    //rom far word* fwRom;
//} POINTER;

/** V A R I A B L E S ********************************************************/

//main_var	udata_acs  0x00		; 15 Byte RAM
#pragma udata access boot=0x00		// Important, otherwise compiler do it what he wants

near BYTE Mode_State;		// this Location is the same as bootloader definition

#pragma udata access user_section=0x15	// Important, otherwise bootloader overwrites this area
//#pragma udata gpr0=0x60
// Access RAM area (0x000 - 0x014) is reserved for boot loader
volatile near byte T0_Delay;		// Timer0 Delay value location
//volatile near BYTE T0_Flag;			// Timer0 Flag für Controlle
volatile near byte CMD;
//volatile near BYTE Mode_State;

#pragma udata gpr0=0x60
//#pragma udata
volatile far ram char * Outbuf_ptr;		// define byte Pointer

#pragma udata usb4=0x420 				// #define EP1_OUT_BUFF_Adrs	0x420

volatile far char EP1OutBuff[0x40];		// 64 byte
//volatile far char EP1InBuff[0x40];		// #define	EP1_IN_BUFF_Adrs 	0x460 

/** P R I V A T E  P R O T O T Y P E S ***************************************/
void main (void);
void InitDevice(void );
void High_Priority_IRQ (void);
void Low_Priority_IRQ (void);
void Procces_USB_Data(void);
void Set_T0_Delay(void);
extern void Usb_Irq (void);
extern void Usb_Init (void);

//#pragma udata 
//near byte dummy;
//near byte SWREG;				// Save WREG
//near byte Data_Count;				// Anzahl der Byte für IN und OUT send/Empfangen
//near byte flash_count;
//near byte Error_Code;
//near byte Setup_Count;	
//near byte P1L;					// Pointer 1 LOW
//near byte P1H;					// Pointer 1 High
//near byte Char_RestH;
//near byte Char_RestL;
//near byte NibleL;
//near byte NibleH;
//near byte T0HOffSet;				// Timer0 Offset High Byte
//near byte mcount;					// Zum Zest für ADC resolt
//near byte SampleEn;				// Sample Enable/Busy
//near byte ADC_countH;
//near byte ADC_countL;
//near word Sample_Count;

//near unsigned int anzahl;
//near byte stepindex;
//near byte mode;
//near unsigned int pos;
//near BYTE stepmotor;		// enthält flag b'xxxxxxdir'.
//near byte MSSP_Mode;		// SPI oder I2C
//near byte EP_Buff_Count;
//BOOL dir;			// = stepmotor.b0;
// #pragma udata
//#pragma idata 
//byte step[0x08];// = {0x99,0x90,0x96,0x06,0x66,0x60,0x69,0x09};
//#pragma idata
//unsigned char* pRAM;                       // Data source pointer(byte*)
//#pragma udata

// USER_DATA User_Data;		// User Command für Firmware

// POINTER pRAM;
// POINTER pROM;
//volatile far ram char * Outbuf_ptr = &EP1OutBuff[0];
//volatile far ram char * Inbuf_ptr = &EP1InBuff[0];
//ram char * Outbuf_ptr = &EP1OutBuff[0];
//ram char * Inbuf_ptr = EP1InBuff;

 
//volatile far ram char * Inbuf_ptr;
//volatile far ram byte * step_ptr;
//volatile far rom char * rom_ptr;
//Far program memory pointer  rom far char * fpmp;  24 bits 
//volatile byte step[8];		//= {0x99,0x90,0x96,0x06,0x66,0x60,0x69,0x09};






////void USB_Init(void );			// wenn USB modul verwendet, Adressse ist 004A
//void ADC_Int(void);
//void Procces_LCD(void);
//void Procces_ADC(void); 
//void Procces_PWM(void); 
//void FlashRD(void); 
//void Procces_COMP(void); 
//void Sample_Read(void);
//void Read_RAM(void); 
//void Procces_IOPort(void);
//void Procces_MSSP(void);
////byte Steper(unsigned int , BOOL, byte, unsigned int);
//
//extern void SendLCD_OK(void );			
//extern void Init_LCD(void );
//extern void Procces_LCD_CMD(void); 
