c_cpp SPISlaveμC(带中断)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp SPISlaveμC(带中断)相关的知识,希望对你有一定的参考价值。
/*
* File : newmain.c
* Author : Ligo George
* Company : electroSome
* Project : SPI Slave Example
* Microcontroller : PIC 16F877A
* Created on April 15, 2017, 5:59 PM
*/
// PIC16F877A Configuration Bit Settings
// 'C' source line config statements
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage In-Circuit Serial Programming Enable bit
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit
#pragma config WRT = OFF // Flash Program Memory Write Enable bits
#pragma config CP = OFF // Flash Program Memory Code Protection bit
#include <xc.h>
#include <pic16f877a.h>
#include "spi.h"
#define _XTAL_FREQ 8000000
void interrupt SPI_Slave_Read()
{
if(SSPIF == 1)
{
PORTD = spiRead();
spiWrite(PORTB);
SSPIF = 0;
}
}
void main()
{
nRBPU = 0; //Enable PORTB internal pull up resistor
TRISB = 0xFF; //PORTB as input
TRISD = 0x00; //PORTD as output
PORTD = 0x00; //All LEDs OFF
GIE = 1;
PEIE = 1;
SSPIF = 0;
SSPIE = 1;
ADCON1 = 0x07;
TRISA5 = 1;
spiInit(SPI_SLAVE_SS_EN, SPI_DATA_SAMPLE_MIDDLE, SPI_CLOCK_IDLE_LOW, SPI_IDLE_2_ACTIVE);
while(1)
{
//Do something here
__delay_ms(5);
}
}
以上是关于c_cpp SPISlaveμC(带中断)的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp SPIMasterμC
c_cpp I2CSlaveμC
c_cpp I2CMasterμC
μC/OS-III---I笔记13---中断管理
μC/OS-II任务代码
μC/OS-III 概述