123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- #ifndef CORE_H
- #define CORE_H
- #include <config.h>
- #include <pic18fregs.h>
- #include <boardconfig.h>
- #include <boardio.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <typedefs.h>
- void coreInit();
- void setup();
- void loop();
- void highInterrupts();
- void lowInterrupts();
- void eeWriteByte(unsigned char address, unsigned char value);
- unsigned char eeReadByte(unsigned char address);
- #define CALL_FUN(x,a) x(a)
- #define CALL_FUN2(x,a,b) x(a,b)
- #define CALL_FUN3(x,a,b,c) x(a,b,c)
- #define CALL_FUN4(x,a,b,c,d) x(a,b,c,d)
-
- #define KPROP(k, prop) k##prop
- #define KPORT(k) CALL_FUN2(KPROP, k, PORT)
- #define KBIT(k) CALL_FUN2(KPROP, k, BIT)
- #define KAN(k) CALL_FUN2(KPROP, k, AN)
- #define KINT(k) CALL_FUN2(KPROP, k, INT)
- #define DIGITALREAD_(connport,connbit) (PORT##connport##bits.R##connport##connbit)
- #define DIGITALWRITE_(connport,connbit,val) do{ \
- if((val) != 0) LAT##connport##bits.LAT##connport##connbit = 1; \
- else LAT##connport##bits.LAT##connport##connbit = 0; \
- }while(0)
- #define DIGITALCLEAR_(connport,connbit) do{ LAT##connport##bits.LAT##connport##connbit = 0; }while(0)
- #define DIGITALSET_(connport,connbit) do{ LAT##connport##bits.LAT##connport##connbit = 1; }while(0)
- #define PIN_MODE_DIGITAL_IN_(connport,connbit) do{\
- TRIS##connport##bits.TRIS##connport##connbit=1;\
- bitclr(*(__data unsigned char*)((int)&PORT##connport + (int)&ANSELA-(int)&PORTA),connbit);\
- } while(0)
- #define PIN_MODE_ANALOGIN_(connport,connbit) do{\
- TRIS##connport##bits.TRIS##connport##connbit=1;\
- bitset(*(__data unsigned char*)((int)&PORT##connport + (int)&ANSELA-(int)&PORTA),connbit);\
- } while(0)
- #define PIN_MODE_DIGITAL_OUT_(connport,connbit) do{\
- TRIS##connport##bits.TRIS##connport##connbit=0;\
- } while(0)
- #define digitalRead(conn) CALL_FUN2(DIGITALREAD_,KPORT(conn),KBIT(conn))
- #define digitalWrite(conn,val) CALL_FUN3(DIGITALWRITE_,KPORT(conn),KBIT(conn),val)
- #define digitalClear(conn) CALL_FUN2(DIGITALCLEAR_,KPORT(conn),KBIT(conn))
- #define digitalSet(conn) CALL_FUN2(DIGITALSET_,KPORT(conn),KBIT(conn))
- #define pinModeDigitalIn(conn) CALL_FUN2(PIN_MODE_DIGITAL_IN_,KPORT(conn),KBIT(conn))
- #define pinModeAnalogIn(conn) CALL_FUN2(PIN_MODE_ANALOGIN_,KPORT(conn),KBIT(conn))
- #define pinModeDigitalOut(conn) CALL_FUN2(PIN_MODE_DIGITAL_OUT_,KPORT(conn),KBIT(conn))
- #define setPinAnsel(conn,val) CALL_FUN3(SET_PIN_ANSEL_,KPORT(conn),KBIT(conn),(val)!=0)*/
- #define BIT_COPY(dest,src) do{ if((src)!=0) dest = 1 ; else dest = 0 ; } while(0)
- #define bitset(var,bitno) ((var) |= (1 << (bitno)))
- #define bitclr(var,bitno) ((var) &= ~(1 << (bitno)))
- #define bittst(var,bitno) (unsigned char)((var & (1 << (bitno)))!=0)
- #ifndef abs
- #define abs(x) ((x)<0?-(x):(x))
- #endif
- extern volatile DWORD Now;
- #define elapsed(since) ((time()-(unsigned long)(since))&0x7FFFFFFF)
- #define microToTime(T) (((unsigned long)T*(FOSC/64000UL))/1000)
- #define timeToMicro(T) (((unsigned long)T*(FOSC/64000UL))/1000)
- unsigned unsigned long int time(void);
- #define timeISR() (Now._dword)
- typedef unsigned long t_time;
- typedef unsigned long t_delay;
- #define delayStart(delay, micros) delay = time() + microToTime(micros)
- #define delayFinished(delay) (elapsed(delay) < 0x3FFFFFFF)
- typedef union
- {
- struct
- {
- unsigned RZ0 : 1;
- unsigned RZ1 : 1;
- unsigned RZ2 : 1;
- unsigned RZ3 : 1;
- unsigned RZ4 : 1;
- unsigned RZ5 : 1;
- unsigned RZ6 : 1;
- unsigned RZ7 : 1;
- };
- } __PORTZbits_t;
- typedef union
- {
- struct
- {
- unsigned LATZ0 : 1;
- unsigned LATZ1 : 1;
- unsigned LATZ2 : 1;
- unsigned LATZ3 : 1;
- unsigned LATZ4 : 1;
- unsigned LATZ5 : 1;
- unsigned LATZ6 : 1;
- unsigned LATZ7 : 1;
- };
- } __LATZbits_t;
- typedef union
- {
- struct
- {
- unsigned TRISZ0 : 1;
- unsigned TRISZ1 : 1;
- unsigned TRISZ2 : 1;
- unsigned TRISZ3 : 1;
- unsigned TRISZ4 : 1;
- unsigned TRISZ5 : 1;
- unsigned TRISZ6 : 1;
- unsigned TRISZ7 : 1;
- };
- struct
- {
- unsigned RZ0 : 1;
- unsigned RZ1 : 1;
- unsigned RZ2 : 1;
- unsigned RZ3 : 1;
- unsigned RZ4 : 1;
- unsigned RZ5 : 1;
- unsigned RZ6 : 1;
- unsigned RZ7 : 1;
- };
- } __TRISZbits_t;
- typedef struct
- {
- unsigned ANSZ0 : 1;
- unsigned ANSZ1 : 1;
- unsigned ANSZ2 : 1;
- unsigned ANSZ3 : 1;
- unsigned ANSZ4 : 1;
- unsigned ANSZ5 : 1;
- unsigned ANSZ6 : 1;
- unsigned ANSZ7 : 1;
- } __ANSELZbits_t;
- #define _PORTZ_ADDR 0x0480
- #define _PORT_TO_LAT 0x09
- #define _PORT_TO_TRIS 0x12
- #define _PORT_TO_ANSEL (-0x48)
- extern __at(_PORTZ_ADDR) volatile unsigned char PORTZ;
- extern __at(_PORTZ_ADDR) volatile __PORTZbits_t PORTZbits;
- extern __at(_PORTZ_ADDR + _PORT_TO_LAT) volatile unsigned char LATZ;
- extern __at(_PORTZ_ADDR + _PORT_TO_LAT) volatile __LATZbits_t LATZbits;
- extern __at(_PORTZ_ADDR + _PORT_TO_TRIS) volatile unsigned char TRICZ;
- extern __at(_PORTZ_ADDR + _PORT_TO_TRIS) volatile __TRISZbits_t TRISZbits;
- extern __at(_PORTZ_ADDR + _PORT_TO_ANSEL) volatile unsigned char ANSELZ;
- extern __at(_PORTZ_ADDR + _PORT_TO_ANSEL) volatile __ANSELZbits_t ANSELZbits;
- #define KZ0PORT Z
- #define KZ0BIT 0
- #define KZ1PORT Z
- #define KZ1BIT 1
- #define KZ2PORT Z
- #define KZ2BIT 2
- #define KZ3PORT Z
- #define KZ3BIT 3
- #define KZ4PORT Z
- #define KZ4BIT 4
- #define KZ5PORT Z
- #define KZ5BIT 5
- #define KZ6PORT Z
- #define KZ6BIT 6
- #define KZ7PORT Z
- #define KZ7BIT 7
- #endif
|