/* 
 * File:   my_defines.h
 * Author: arne
 *
 * Created on 31 de Julho de 2024, 14:56
 */

#ifndef MY_DEFINES_H
#define	MY_DEFINES_H

//******************************************************************************
// Se nenhuma freqüência foi definida, assume 4MHz
// Esta definição é exigida para calibrar as funções __delay_us() e __delay_ms()
//
#define _XTAL_FREQ 4000000

//******************************************************************************
// Definições importantes do módulo
//
#define TRUE        1
#define FALSE       0

//*****************************************************************************
// Tipos definidos pelo usuário
//
#ifndef _MYDEFS_
#define _MYDEFS_
typedef unsigned char byte;
typedef unsigned char Uint8;
typedef unsigned short Uint16;
#endif

#define __DEBUG__       0x01
#define __PIC16F6xx__   0x01
//#define __PIC16F8x__    0x01
//#define __PIC16F87x__ 0x01

//******************************************************************************
// Configuração para pinos de I/O
//
#define TRIS_A      0xFF        // portA é entrada
#define TRIS_B      0x00        // portB é saída

//*****************************************************************************
// Pinos de I/O e macros de controle
//
#define PORTKEYS    PORTA
#define PKS1        0x08                // RA3
#define PKS2        0x04                // RA2

#define readS1   (!(PORTKEYS & PKS1))   // leitura de RA3
#define readS2   (!(PORTKEYS & PKS2))   // leitura de RA2

#define PORTLEDS    PORTB
#define LED_live    0x10                // RB4
#define LED2        0x80                // RB7
#define LED3        0x40                // RB6

#define LEDLon      PORTLEDS |= LED_live
#define LEDLoff     PORTLEDS &= ~LED_live
#define toggleLEDL  PORTLEDS ^= LED_live


#define LED2on      PORTLEDS |= LED2
#define LED2off     PORTLEDS &= ~LED2
#define toggleLED2  PORTLEDS ^= LED2

#define LED3on      PORTLEDS |= LED3
#define LED3off     PORTLEDS &= ~LED3
#define toggleLED3  PORTLEDS ^= LED3

#define PA4988      PORTB
#define ENBA4988    0x01                // RB0
#define RESETA4988  0x02                // RB1
#define DIRA4988    0x04                // RB2
#define STEPSA4988  0x08                // RB3

#define RESA4988on  PA4988 |= RESETA4988
#define RESA4988off PA4988 &= ~RESETA4988

#define STPA4988on  PA4988 |= STEPSA4988
#define STPA4988off PA4988 &= ~STEPSA4988
#define toggleSTPA4988 PA4988 ^= STEPSA4988

#define DIRA4988on  PA4988 |= DIRA4988
#define DIRA4988off PA4988 &= ~DIRA4988

#define ENA4988on   PA4988 |= ENBA4988
#define ENA4988off  PA4988 &= ~ENBA4988

//******************************************************************************
// Definições importantes 
//
#define ON  1
#define OFF 0

#define ena_ints    (INTCONbits.GIE = 1)
#define ena_intsP   (INTCONbits.PEIE = 1)

#define dis_ints    (INTCONbits.GIE = 0)
#define dis_intsP   (INTCONbits.PEIE = 0;)


#endif	/* MY_DEFINES_H */

