Lab Five

Lab Five - Lab Five - LCD Real-time Desk Clock (Combined...

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

View Full Document Right Arrow Icon
Lab Five - LCD Real-time Desk Clock (Combined Timer, Interrupt, LCD) Wallace Kerrigan, 1541317 wallace.kerrigan@uconn.edu 17 October 2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
Part One Figure 1. Flow Chart of Microcontroller with LCD Real- time Clock Code #define F_CPU 1000000UL
Background image of page 2
#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 int DataSize; //Global variable used to hold string lengths //value before transmitting in SendLcdData() unsigned int count = 0; unsigned int hour = 0+11, hour1 = 48+1, hour2 = 48+1, min1 = 48+5, min2 = 48+9; unsigned int sec1 = 48+5, sec2 = 48+5, noon = 65, countnoon = 1; //------------------------------------------------------------------------- //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 = 0x02; //Sets SCL frequency to ?kHz. f should be <100khz. See datasheet page 206 TWCR = 0x44; //Enables TWI interface, see page 225 TWSR = 0xF8; //Sets prescaler (TWPS bits) to have prescaler value of ?, p. 227 } //------------------------------------------------------------------------- //Transmission error handler //------------------------------------------------------------------------- void ERROR(void) { // no error handling at this time }
Background image of page 3

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

View Full DocumentRight Arrow Icon
//------------------------------------------------------------------------- //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 //condition 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. This indicates that the SLA+W has been //transmitted, and ACK/NACK has been received. if ((TWSR & 0xF8) != MT_SLA_ACK); //Check value of TWI Status Register.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

Lab Five - Lab Five - LCD Real-time Desk Clock (Combined...

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