La mia piccola fusione fredda privata

Sperimentando la fusione fredda

Il contatore Geiger : ContatoreGeiger.h

Posted Sunday, April 19th, 2015

#define SERNUM      1000
#define VERNUMH     1
#define VERNUML     0

//#define FLASH_TIME 7
#define USA_SW_RTC 1

enum {
MILLIROENTGEN=0,
CPS,
UGY,
USV,
UCKG
};
enum {
SBM20=0,
LND712
};
enum {
CO60,
RA226,
CS137
};
enum {
SLEEP=0,
READY
};

struct COMM_STATUS {
// errori/flag in CommStatus Seriale, (LSB prima – right-aligned)
unsigned int FRAME_2SEND:1;         // c’e’ da mandare un frame
unsigned int WAIT_4ACK  :1;
unsigned int FRAME_REC  :1;         // c’e’ un frame ricevuto
unsigned int COMM_OVRERR:1;                    // overrun seriale
unsigned int COMM_OVL   :1;         // errore di overflow buffer in ricezione
unsigned int COMM_TOUT  :1;         // errore di timeout in ricezione frame
unsigned int COMM_FRERR :1;         // errore di framing (START/STOP) in ricezione
unsigned int COMM_PERR  :1;         // errore di parita’ in ricezione  (0×80)
unsigned int BUSY  :1;                            // occupato
unsigned int LINE_BUSY  :1;         // linea intasata, impossibile inviare
unsigned int COMM_CRCERR  :1;         // errore di checksum in ricezione
};

#define CR           0xd
#define LF           0xa
//#define SYN        22
//#define EOT        4
//#define STX        2            // Fine messaggio di Utente
//#define ACK        6
//#define NACK    21

#define BUF_232_SIZE 32
#define BAUD_RATE 9600

// il Timer0 conta ogni 62.5nSec*prescaler… (@32MHz CPUCLK => 16MHz) su PIC24
#define TMR0BASE  (1010-11)    // 500uS ; reale=500.00025 10/2/11;
//#define DELAY_CORREZ (10)        // 22/1/2006, v.anche pelucheUSB.c
#define TMR2BASE (25010-11)        //   10Hz per timer
#define TMR3BASE (2510-11)        //   100Hz per capture

#define BEEP_STD_FREQ 100

#define EEscrivi(a,b) EEscrivi_(a,b)            // per lcd
void EEscrivi_(BYTE *addr,BYTE n);
BYTE EEleggi(BYTE *addr);
void EEscriviDword(BYTE *addr,DWORD n);
DWORD EEleggiDword(BYTE *addr);
void EEscriviWord(BYTE *addr,WORD n);
WORD EEleggiWord(BYTE *addr);
#define EEcopiaARAM(p) { *p=EEleggi(p); }
#define EEcopiaAEEPROM(p) EEscrivi_(p,*p)

void prepOutBuffer(BYTE );
void clearOutBuffer(void);
void prepStatusBuffer(BYTE);

#define DELAY_SPI_FAST 5
#define Delay08()    __delay_us(TIME_GRANULARITY)            // 1 bit-time
#define Delay_SPI() __delay_us(DELAY_SPI_FAST /*DelaySPIVal*/)
#define Delay_1uS() __delay_us(1)
#define Delay_uS(x) __delay_us(x)
#define Delay_mS(x) __delay_ms(x)
#define Delay_1mS() Delay_mS(1)
void I2CDelay(void);

void Beep(void);

void UserTasks(void);
BYTE KBInit(void);
void scanKBD(void);
void handleKBD(void);
void updLCD(void);

void LCDWriteNum(BYTE ,BYTE ,WORD ,signed char );
void LCDWriteStr(BYTE ,BYTE ,char *);
void LCDWriteBool(BYTE ,BYTE ,BYTE );
void LCDPutCharXY(BYTE ,BYTE ,char );

#define SCHERMATA_SPLASH 0
#define SCHERMATA_PRINCIPALE 1
#define PRIMA_SCHERMATA_VISUALIZZAZIONE (SCHERMATA_PRINCIPALE)        // qua sono la stessa… non c’è il pre-menu
#define ULTIMA_SCHERMATA_VISUALIZZAZIONE (PRIMA_SCHERMATA_PROGRAMMAZIONE-1)
#define PRIMA_SCHERMATA_PROGRAMMAZIONE 7
#define ULTIMA_SCHERMATA_PROGRAMMAZIONE (PRIMA_SCHERMATA_PROGRAMMAZIONE+10+3)        // tolto max min e la media/deviazione… aggiunto USB,lcd,baudrate, formatt.

enum MENU {
MENU_IDLE=0,
//    MENU_MAIN, qua no
MENU_VISUALIZZAZIONE,
//    MENU_PROGRAMMAZIONE_MENU,
MENU_PROGRAMMAZIONE
};

struct LCD_ITEM {
BYTE x,y;
BYTE size;
WORD valMin,valMax;
WORD *var;
BYTE varSize;
};
struct LCD_ITEM_GROUP {
struct LCD_ITEM item[2];
};

// PIC24 RTCC Structure
typedef union {
struct {
unsigned char   mday;       // BCD codification for day of the month, 01-31
unsigned char   mon;        // BCD codification for month, 01-12
unsigned char   year;       // BCD codification for years, 00-99
unsigned char   reserved;   // reserved for future use. should be 0
};                              // field access
unsigned char       b[4];       // byte access
unsigned short      w[2];       // 16 bits access
unsigned long       l;          // 32 bits access
} PIC24_RTCC_DATE;

// PIC24 RTCC Structure
typedef union {
struct {
unsigned char   sec;        // BCD codification for seconds, 00-59
unsigned char   min;        // BCD codification for minutes, 00-59
unsigned char   hour;       // BCD codification for hours, 00-24
unsigned char   weekday;    // BCD codification for day of the week, 00-06
};                              // field access
unsigned char       b[4];       // byte access
unsigned short      w[2];       // 16 bits access
unsigned long       l;          // 32 bits access
} PIC24_RTCC_TIME;

DWORD   PIC24RTCCGetTime( void );
DWORD   PIC24RTCCGetDate( void );
void    PIC24RTCCSetTime( WORD weekDay_hours, WORD minutes_seconds );
void    PIC24RTCCSetDate( WORD xx_year, WORD month_day );
void    UnlockRTCC( void );

BYTE to_bcd(BYTE );
BYTE from_bcd(BYTE );

//cmd #
enum {
CMD_NOP=0,
CMD_GETID=1,
CMD_GETCAPABILITIES=2,
CMD_GETCONFIG=3,
CMD_SETCONFIG,

CMD_GETSTATUS=8,
CMD_SETSTATUS,

CMD_TEST=16,
CMD_BEEP=17,
CMD_LCD=18,
CMD_GETLOG,

CMD_WRITEEEPROM=24,
CMD_WRITERTC=25,
CMD_READEEPROM=26,
CMD_READRTC=27,

CMD_RESET_IF=30,
CMD_DEBUG_ECHO=31,
CMD_READ_IDLOCS=63
};