Você está na página 1de 3

/* ###################################################################

** Filename : main.c
** Project : temperatura
** Processor : MKL25Z128VLK4
** Version : Driver 01.01
** Compiler : GNU C Compiler
** Date/Time : 2017-04-17, 19:44, # CodeGen: 0
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.01
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "WAIT1.h"
#include "KSDK1.h"
#include "sensor.h"
#include "BitIoLdd1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert
) */
int i, biti;
uint8_t dado=0, sensor[9];
uint16_t temperatura;
float temp;
void resetar(void) {
sensor_SetOutput();
sensor_ClrVal();
WAIT1_Waitus(490);
sensor_SetInput();
WAIT1_Waitus(62);
if(sensor_GetVal() == 0){
//Serial.println("Sensor Localizado");
}
else{
//Serial.println("Sensor no localizado");
}
WAIT1_Waitus(490);
}
void envia(uint8_t valor) {
uint8_t serial;
for (i = 0; i < 8; i++) {
sensor_SetOutput();
sensor_ClrVal();
WAIT1_Waitus(2);
serial=valor&1;
sensor_PutVal(serial);
valor = valor >> 1;
WAIT1_Waitus(60);
sensor_SetInput();
WAIT1_Waitus(2);
}
}
void le_byte(void) {
int j;
dado = 0;
for(j=0; j<9; j++){
for (i = 0; i < 8; i++) {
dado = dado>>1;
sensor_SetOutput();
sensor_ClrVal();
WAIT1_Waitus(2);
sensor_SetInput();
WAIT1_Waitus(8);
biti = sensor_GetVal();
//Serial.println(biti);
biti=biti<<7;
dado = dado + biti;
biti=0;
WAIT1_Waitus(120);
}
sensor[j]=dado;
//Serial.println(sensor[j]);
//WAIT1_Waitus(2);
}
temperatura=((sensor[1]<<8)+sensor[0]);
temp=temperatura*0.0625;
}
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */
uint8_t temp_alto, temp_baixo, byte2, byte3, byte4, byte5, byte6, byte7,
byte8;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!!
***/
PE_low_level_init();
/*** End of Processor Expert internal initialization.
***/
/* Write your code here */
/* For example: */
for (;;) {
resetar();
envia(0xCC);
envia(0x44);
WAIT1_Waitms(750);
resetar();
envia(0xCC);
envia(0xbe);
le_byte();
}
/*** Don't write any code pass this line, or it will be deleted during c
ode generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component.
DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is
defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.5 [05.21]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

Você também pode gostar