Добрый день, господа! Прошу Вашей помощи.
Код
#include <../../../../../../../../include/xc.h>
#include <../../../../../../include/pic16f1518.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config VCAPEN = OFF // Voltage Regulator Capacitor Enable bit (VCAP pin function disabled)
#pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#define _XTAL_FREQ 16000000
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
unsigned char Tmp;
main(void)
{ OSCCON = 0b01111010; // Internal OSC @ 16MHz
SSPCON1=0b00101000; //I2C master
SSPCON3bits.SDAHT = 1; // Minimum of 300 ns hold time on SDA
// after the falling edge of SCL
SSPSTAT=0b10000000; //slew rate control disabled
SSPADD=0x27; //100 kHz
SSPIF = 0; // Clear the serial port interrupt flag
BCLIF = 0; // Clear the bus coll interrupt flag
BCLIE = 1; // Enable bus collision interrupts
SSPIE = 1; // Enable serial port interrupts
PEIE = 1; // Enable peripheral interrupts
GIE = 1; // Enable global interrupts
PORTC = 0x00; // Clear PORTC
LATC = 0x00; // Clear PORTC latches
TRISC = 0b00011000; // Set RC3, RC4 as inputs for I2C
PORTB=0x00;
LATB=0x00;
TRISB=0x00;
__delay_ms(100);
do{
SSPCON2bits.SEN = 1; // set start bit
SSPBUF=0x30;
do{}while(!SSPIF);
SSPIF=0;
// SSPBUF=0x55;
// do{}while(!SSPIF);
// SSPIF=0;
SSPCON2bits.PEN = 1; // set stop bit
PORTBbits.RB5=1;
__delay_ms(100);
PORTBbits.RB5=0;
__delay_ms(100);
}while(1);
}
На RB5 - светодиод. Без строчек с SSP все мигает. При загрузке приведенного кода мигания нет. При запуске в отладке с PicKit3 происхдят "перескоки" на начало программы (даже если в теле программы про SSP только одна строчка старт-бита). Контроллер PIC16F1518, XC8 1.31, MPLAB-X 1.9, код слизан с AN734. Пните пожалуйста в нужном направлении.