freescale
来自「Freescale 系列单片机常用模块与综合系统设计」· 代码 · 共 102 行
TXT
102 行
/** ###################################################################
** Filename : IIC_Master.C
** Project : IIC_Master
** Processor : MC9S08JM60CLHE
** Version : Driver 01.11
** Compiler : CodeWarrior HCS08 C Compiler
** Date/Time : 2010-1-15, 8:45
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/* MODULE IIC_Master */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "I2C_Master.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
word rec_count;
word bytes_to_trans;
char IIC_Data[9];
char IIC_Rec_Data[9];
char Alarm = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
void main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
I2C_Master_SelectSlave(0x0a);
PTAPE_PTAPE2 =1; //Enable Pull ups on SW pins
PTAPE_PTAPE3 =1;
/* Write your code here */
for(;;) {
//select channel here
if (PTAD_PTAD2 == 0)
{
while (PTAD_PTAD2 ==0); //WAIT WHILE PIN IS LOW
IIC_Data [0] = 0x01; //Set Threshold
IIC_Data [1] = 0xff; //
IIC_Data [2] = 0x00; //Select Channel
while (IICC_MST == 1); //Wait till IIC is stopped
I2C_Master_SendBlock(&IIC_Data, 0x03, &bytes_to_trans); // Transmit commands and Threshold
}
if (PTAD_PTAD3 == 0)
{
while (PTAD_PTAD3 ==0); //WAIT WHILE PIN IS LOW
IIC_Data [0] = 0x01; //Set Threshold
IIC_Data [1] = 0xff; //
IIC_Data [2] = 0x01; //Select Channel
while (IICC_MST == 1); //Wait till IIC is stopped
I2C_Master_SendBlock(&IIC_Data, 0x03, &bytes_to_trans);
}
while (IICC_MST == 1); //Wait till IIC is stopped
I2C_Master_RecvBlock(&IIC_Rec_Data, 0x03, &rec_count);
if (IICS_BUSY == 0)
{
if (IIC_Rec_Data[2] == 0x01)//Examine Recieved data here
{
//Turn on Alarm Indicator
Alarm = 0x01;
} else
{
Alarm =0x00;
}
}
}
}
/* END IIC_Master */
/*
** ###################################################################
**
** This file was created by Processor Expert 3.07 [04.34]
** for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?