Lab Eight

Lab Eight - Lab Eight Temperature Monitoring/Alarm...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab Eight - Temperature Monitoring/Alarm System (Combined ADC, LCD, and Sensor) Wallace Kerrigan, 1541317 [email protected] 7 November 2011 Part One Figure 1. Flow Chart of Analog-to-Digital Reading of Temperature Sensor and LCD Display Code #define F_CPU 1000000UL #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> #define START 0x08 //TWSR code for start condition transmission #define MT_SLA_ACK 0x18 //TWSR code for SLA_W transmission and ACK received #define MT_DATA_ACK 0x28 //TWSR code for data byte transmitted and ACK received #define SLA_W 0x50 //Slave address (zeroth bit = 1 read command, 0 = write command) unsigned voltage = 0, voltage1 =0, voltage2 =0; unsigned char string2[16]; unsigned int DataSize; //Global variable used to hold string lengths //value before transmitting in SendLcdData() unsigned int ReadADC(unsigned char channel); // Assigning RaedADC as an unsigned integer void InitADC(void); //------------------------------------------------------------------------- //My delay function //------------------------------------------------------------------------- void my_delay_in_ms(unsigned int millisecs) { unsigned int i; for (i=0; i <= millisecs; i++) _delay_ms(1); } //------------------------------------------------------------------------- //Initialize the two wire interface (I2C) //------------------------------------------------------------------------- void I2C_Init(void) { TWBR = 0x44; //Sets SCL frequency to close to 0 kHz. f should be <100khz. See datasheet page 206 TWCR = 0xA5; //Enables TWI interface, see page 225 the 2nd bit TWSR = 0x01; //Sets prescaler (TWPS bits) to have prescaler value of 64, p. 227 } //------------------------------------------------------------------------- //Transmission error handler //------------------------------------------------------------------------- void ERROR(void) { // no error handling at this time } //------------------------------------------------------------------------- //The function that sends data strings to the LCD //------------------------------------------------------------------------- void SendLcdData(unsigned char data) { //--- Send Start condition ---// TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); //Send start condition while (!(TWCR & (1<<TWINT))); //Wait for TWINT Flag set. This indicates that the START //condi tion has been transmitted if ((TWSR & 0xF8) != START); //Check value of TWI Status Register. Mask prescaler bits. If status { //different from START go to ERROR ERROR(); } //--- Send address and "write" command ---// TWDR = SLA_W; //Load SLA_W (slave address, write) into TWDR register TWCR = (1<<TWINT) | (1<<TWEN); //Clear TWINT bit in TWCR to start transmission of address while (!(TWCR & (1<<TWINT))); //Wait for TWINT Flag set....
View Full Document

This note was uploaded on 11/21/2011 for the course ECE 3411 taught by Professor Park during the Fall '11 term at UConn.

Page1 / 21

Lab Eight - Lab Eight Temperature Monitoring/Alarm...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online