#include "utils.h" #ifndef _PICINTERFACE_H #define _PICINTERFACE_H /* Port API */ BIT_AT(PORTB_ADDR,0) PIN_B0; BIT_AT(PORTB_ADDR,1) PIN_B1; BIT_AT(PORTB_ADDR,2) PIN_B2; BIT_AT(PORTB_ADDR,3) PIN_B3; BIT_AT(PORTB_ADDR,4) PIN_B4; BIT_AT(PORTB_ADDR,5) PIN_B5; BIT_AT(PORTB_ADDR,6) PIN_B6; BIT_AT(PORTB_ADDR,7) PIN_B7; BIT_AT(PORTC_ADDR,0) PIN_C0; BIT_AT(PORTC_ADDR,1) PIN_C1; BIT_AT(PORTC_ADDR,2) PIN_C2; BIT_AT(PORTC_ADDR,3) PIN_C3; BIT_AT(PORTC_ADDR,4) PIN_C4; BIT_AT(PORTC_ADDR,5) PIN_C5; BIT_AT(PORTC_ADDR,6) PIN_C6; BIT_AT(PORTC_ADDR,7) PIN_C7; BIT_AT(PORTD_ADDR,0) PIN_D0; BIT_AT(PORTD_ADDR,1) PIN_D1; BIT_AT(PORTD_ADDR,2) PIN_D2; BIT_AT(PORTD_ADDR,3) PIN_D3; BIT_AT(PORTD_ADDR,4) PIN_D4; BIT_AT(PORTD_ADDR,5) PIN_D5; BIT_AT(PORTD_ADDR,6) PIN_D6; BIT_AT(PORTD_ADDR,7) PIN_D7; BIT_AT(PORTE_ADDR,0) PIN_E0; BIT_AT(PORTE_ADDR,1) PIN_E1; BIT_AT(PORTE_ADDR,2) PIN_E2; #define input(p) p #define output_high(p) p = 1 #define output_low(p) p = 0 #define output_bit(p, bit) p = bit #define SET_TRIS_A(tris) TRISA = tris #define SET_TRIS_B(tris) TRISB = tris #define SET_TRIS_C(tris) TRISC = tris #define SET_TRIS_D(tris) TRISD = tris #define SET_TRIS_E(tris) TRISE = tris /* Interrupt handling API */ #define INT_EXT 0 #define INT_RTCC 1 #define INT_TIMER1 2 #define INT_TIMER2 3 #define INT_TIMER3 4 #define GLOBAL 5 #define H_TO_L 0 #define L_TO_H 0 #ifdef _PIC18F #define EXT_INT_EDGE(edge) INTEDG0 = edge #else #define EXT_INT_EDGE(edge) INTEDG = edge #endif void enable_interrupts(int int_source); void disable_interrupts(int int_source); /* EEPROM API */ #define read_eeprom(address) 0 #define write_eeprom(address, val) /* ADC API */ /* Definitions used for SETUP_ADC_PORTS */ #define ALL_ANALOG 0x80 #define ANALOG_RA3_REF 0x81 #define A_ANALOG 0x82 #define A_ANALOG_RA3_REF 0x83 #define NO_ANALOGS 0x86 /* Definitions used for SETUP_ADC */ #define ADC_OFF 0 #define ADC_CLOCK_DIV_2 1 #define ADC_CLOCK_DIV_8 0x41 #define ADC_CLOCK_DIV_32 0x81 #define ADC_CLOCK_INTERNAL 0xc1 #define ADC_CLOCK_DIV_4 0x101 #define ADC_CLOCK_DIV_16 0x141 #define ADC_CLOCK_DIV_64 0x181 #define SETUP_ADC(settings) \ ADCON0 = settings & 0xff; ADCON1 |= settings >> 2 #define SETUP_ADC_PORTS(ports) ADCON1 = ports #define SET_ADC_CHANNEL(channel) ADCON0 &= 0xc7; ADCON0 |= channel << 3 #define READ_ADC ADG0 = 1; for ( ; ADG0; ) ; (ADRESH << 8) | ADRESL /* Timer API */ #define RTCC_INTERNAL 0 enum { RTCC_DIV_2, RTCC_DIV_4, RTCC_DIV_8, RTCC_DIV_16, RTCC_DIV_32, RTCC_DIV_64, RTCC_DIV_128, RTCC_DIV_256 }; #define setup_counters(settings, prescale) T0CON = settings | prescale #define T1_DISABLED 0 #define T1_INTERNAL 0x85 #define T1_EXTERNAL 0x87 #define T1_EXTERNAL_SYNC 0x83 #define T1_DIV_BY_1 0 #define T1_DIV_BY_2 0x10 #define T1_DIV_BY_4 0x20 #define T1_DIV_BY_8 0x30 #define setup_timer_1(settings) T1CON = settings #define set_timer1(t) TMR1H = t >> 8; TMR1L = t & 0xff #define get_timer1() TMR1H << 8 | TMR1L enum { T2_DISABLED = 0 T2_DIV_BY_1 = 4, T2_DIV_BY_4, T2_DIV_BY_16 }; #define setup_timer_2(settings, duty, postscale) \ T2CON = settings | (postscale << 3); PR2 = duty /* PWM definitions */ #define CCP_PWM 0xc0 #define setup_ccp1(mode) CCP1CON = mode #define setup_ccp2(mode) CCP2CON = mode #define set_pwm1_duty(duty) CCPR1L = duty #define set_pwm2_duty(duty) CCPR2L = duty /* SPI API */ #define SPI_MASTER 0x20 #define SPI_SLAVE 0x24 #define SPI_SS_DISABLED 1 #define SPI_H_TO_L 0x40 #define SPI_L_TO_H 0 #define SPI_CLK_DIV_4 0 #define SPI_CLK_DIV_16 1 #define SPI_CLK_DIV_64 2 #define SPI_CLK_T2 3 #define setup_spi(conf) SSPSTAT |= conf & 0x40; \ // Set SSPSTAT: Set SMP to 0 and set CKE SSPCON = 0x10 | (conf & 0x3f); // Set SSPCON: Enable SSPEN, set CKP to 1, set SSPM0-SSPM3 int spi_read(void); #define spi_write(data) SSPBUF = data; for ( ; !STAT_BF; ) ; SSPBUF; #endif // _PICINTERFACE_H