"Global.h" "Avr/io.h"
"Global.h" "Avr/io.h"
* temp_sensor.h
*
* Created: 9/20/2017 1:32:18 PM
* Author: uidn2752
*/
#include "Global.h"
#include "avr/io.h"
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include "HD44780.h"
#ifndef TEMP_SENSOR_H_
#define TEMP_SENSOR_H_
#define LCD_E 1
#define LCD_RS 0
#define DAT4 2
#define DAT5 3
#define DAT6 4
#define DAT7 5
#define LED 5
#define ClearBit(x,y) (x&=~(1<<(y)))
#define SetBit(x,y) (x|=1<<(y))
#define ReadBit(x,y) (x&=(1<<(y)))
#endif /* TEMP_SENSOR_H_ */
/*
* temp_sensor.c
*
* Created: 9/20/2017 1:31:59 PM
* Author: uidn2752
*/
#include "temp_sensor.h"
uint8 therm_Reset()
{
uint8 i;
THERM_OUTPUT(); // set pin as output
THERM_LOW(); // pull pin low for 480uS
_delay_us(480);
THERM_INPUT(); //set pin as input
_delay_us(60); // wait for 60uS
i=THERM_READ(); // get pin value
_delay_us(420); // wait for rest of 480uS period
return i;
}
uint8 therm_ReadBit()
{
uint8 bit=0;
THERM_OUTPUT(); // set pin as output
THERM_LOW(); // pull pin low for 1uS
_delay_us(1);
THERM_INPUT(); // release pin& wait 14 uS
_delay_us(14);
if(THERM_READ())
bit=1; // read pin value
_delay_us(45); //wait rest of 60uS period
return bit;
}
uint8 therm_ReadByte()
{
uint8 i=8, data=0;
while(i--) // for 8 bits:
{
data>>=1; // shift all bits right
data|=(therm_ReadBit()<<7); // get next bit (LSB first)
}
return data;
}
*t0=therm_ReadByte();
// first byte
*t1=therm_ReadByte();
// second byte
}
void InitAVR()
{
DDRC=0x3F; // 0011.1111; set B0-B5 as outputs
DDRD=0x00; // 0000.0000; set PORTC as inputs
}
void FlashLED()
{
SetBit(PORTB,LED);
msDelay(250);
ClearBit(PORTB,LED);
msDelay(250);
}
void PulseEnableLine()
{
SetBit(PORTB,LCD_E); // take LCD enable line high
_delay_us(40); // wait 40 microseconds
ClearBit(PORTB,LCD_E); // take LCD enable line low
}
void HexDigit(uint8 data) // lower 4 bits of input -> output hex digit
// helper function for other LCD
hex routines
{
if (data<10)
data+='0';
else
data+='A'-10;
LCD_Char(data);
}
void LCD_Integer(int data) // displays the integer value of DATA at current LCD
cursor position
{
char st[8]=""; // save enough space for result
itoa(data,st,10); // convert to ascii
LCD_WriteText(st); // display in on LCD
}
void TempProgram()
{
while(1)
{
int whole=0, decimal=0;
LCD_GoTo(0,1);
LCD_WriteText("Temp1 = ");
therm_ReadTempC(&whole,&decimal);
LCD_Integer(whole);
LCD_Char('.');
//LCD_PadInteger(decimal,4,'0');
_delay_ms(1000);
FlashLED();
}
}