Sei sulla pagina 1di 8

DAR ES SALAAM INSTITUTE OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND TELECOMMUNICATION ENGINEERING


B.ENG 12T
ETU07421: MICROPROCESSOR APPLICATIONS.
ASSIGNMENT5
GROUP SIX (6) MEMBERS.
1. OMARY M. SAID (120647472643)
2.FELIX MWAMBASHI (120647412621)
3.SITTA GEMBEGE(120647492649)
4. ASWILE NIKUSUMA(120647402611)
5.JOHNCHACHA (100602G8002)
6.BRUNO SONZOGO (100602G8317)















AIM: TO INTERFACE MULTIMEDIA MEMORY CARD(MMC) WITH MICROCONTROLLER

TOOLS/EQUIPMENTS:
Display unit (LCD 16X2)
PIC18F4550
Temperature sensor(LM 35)
Series Real Time Clock(DS 1307)
Proteus simulating software
MikroC software for PIC


PROCEDURE:
Circuit diagram

From the above circuit the temperature sensor is required to measure the value of temperature
(in volts), when the value is measured it is converted to degrees centigrade by the
microcontroller and displayed on the lcd and at the same time the value of the temperature is
recorded on the multimedia memory card showing the time of recording and the value of
temperature.

By using MikroC software to the write the codes for measuring the values of temperature,
displaying on the lcd and recording the values and time on the multimedia memory card

Source codes used:
//Memory Card Chip Select Connection
sfrsbitMmc_Chip_Select at RB2_bit;
sfrsbitMmc_Chip_Select_Direction at TRISB2_bit;
//

// Software I2C connections
sbit Soft_I2C_Scl at RB3_bit;
sbit Soft_I2C_Sda at RB4_bit;
sbit Soft_I2C_Scl_Direction at TRISB3_bit;
sbit Soft_I2C_Sda_Direction at TRISB4_bit;
// End Software I2C connections

// LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_RW at RD1_bit;
sbit LCD_EN at RD2_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbitLCD_RS_Direction at TRISD0_bit;
sbitLCD_EN_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

unsigned char filename[] = "TEMP.TXT";
unsigned char error;
unsigned char i;
unsignedintadc_value;
unsigned char Temperature_Log[BUFFER_SIZE];

char seconds, minutes, hours, day, month, year; // Global date/time variables
charprev_minutes=0;
unsigned char BCD2UpperCh(unsigned char bcd)
{
unsigned char temp;
temp = bcd>> 4;
temp = temp | 0x30;
return(temp);
}
unsigned char BCD2LowerCh(unsigned char bcd)
{
unsigned char temp;
temp = bcd& 0x0F; //Making the Upper 4-bits
temp = temp | 0x30;
return(temp);
}
unsigned char rtc1307_Read(unsigned char address)
{
unsigned char temp;
Soft_I2C_Start();
Soft_I2C_Write(0xD0);
Soft_I2C_Write(address);
Soft_I2C_Start();
Soft_I2C_Write(0xD1);
temp = Soft_I2C_Read(0);
Soft_I2C_Stop();
return temp;
}

voidDisplay_Time() {

Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_FIRST_ROW);
Lcd_Out(1, 1,"DATE:"); // Prepare and output static text on LCD
Lcd_Chr(1, 7,BCD2UpperCh(day));
Lcd_Chr(1, 8,BCD2LowerCh(day));
Lcd_Chr(1, 9,'/');
Lcd_Chr(1, 10,BCD2UpperCh(month));
Lcd_Chr(1,11,BCD2LowerCh(month));
Lcd_Chr(1,12,'/');
Lcd_Chr(1,13, BCD2UpperCh(year));
Lcd_Chr(1,14,BCD2LowerCh(year));

Lcd_Out(2, 1,"TIME:");
Lcd_Chr(2, 7,BCD2UpperCh(hours));
Lcd_Chr(2, 8,BCD2LowerCh(hours));
Lcd_Chr(2, 9,':');
Lcd_Chr(2, 10,BCD2UpperCh(minutes));
Lcd_Chr(2,11,BCD2LowerCh(minutes));
Lcd_Chr(2,12,':');
Lcd_Chr(2,13,BCD2UpperCh(seconds));
Lcd_Chr(2,14,BCD2LowerCh(seconds));
}

void main()
{
unsigned char ones,tens,hundreds,fractional;
unsignedint temp;

TRISD = 0x00;
Soft_I2C_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(100);
Lcd_Out(1,1," TEMP. RECORDER");
Lcd_Out(2,1," EMBEDDED LAB");
Delay_ms(1000);
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0xD0); // Address DS1307
Soft_I2C_Write(0x00);
Soft_I2C_Write(0x00);
Soft_I2C_Stop();

ADCON0 = 0b00000001; //A/D Converter Power Up
ADCON1 = 0x0E;
ADCON2 = 0b10111110; //Right Justfied and Slowest Clock for better accuracy
ADC_Init();

SPI1_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE,
_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Delay_us(10);

error = MMC_Init();
while(error == 1)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1," CARD NOT FOUND");
error = MMC_Init();
}

Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1," CARD DETECTED!");
Lcd_Out(2,1,"CARD INITIALIZED");
Delay_ms(1000);

MMC_Fat_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE,
_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);

Mmc_Fat_Assign(&filename,0xA0);

while(1)
{
seconds = rtc1307_Read(0x00);
minutes = rtc1307_Read(0x01);
hours = rtc1307_Read(0x02);
day = rtc1307_Read(0x04);
month = rtc1307_Read(0x05);
year = rtc1307_Read(0x06);
Display_Time();

adc_value = ADC_Read(0); //Read Temperature from ADC
adc_value = adc_value*488;
adc_value = adc_value/10;

temp = adc_value/100;
ones = temp%10;
temp = temp/10;
tens = temp%10;
temp = temp/10;
hundreds = temp%10;

ones = ones|0x30;
tens = tens|0x30;
hundreds = hundreds|0x30;
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"TEMPERATURE:");
Lcd_Chr(2,1,hundreds);
Lcd_Chr(2,2,tens);
Lcd_Chr(2,3,ones);
adc_value = adc_value/10;
fractional = adc_value%10;
fractional |= 0x30;
Lcd_Chr(2,4,'.');
Lcd_Chr(2,5,fractional);
Lcd_Chr(2,6,'C');
// if(minutes != prev_minutes)
{
Temperature_Log[0] = BCD2UpperCh(hours);
Temperature_Log[1] = BCD2LowerCh(hours);
Temperature_Log[2] = ':';
Temperature_Log[3] = BCD2UpperCh(minutes);
Temperature_Log[4] = BCD2LowerCh(minutes);
Temperature_Log[5] = ':';
Temperature_Log[6] = BCD2UpperCh(seconds);
Temperature_Log[7] = BCD2LowerCh(seconds);
Temperature_Log[8] = ',';
Temperature_Log[9] = BCD2UpperCh(day);
Temperature_Log[10] = BCD2LowerCh(day);
Temperature_Log[11] = '/';
Temperature_Log[12] = BCD2UpperCh(month);
Temperature_Log[13] = BCD2LowerCh(month);
Temperature_Log[14] = '/';
Temperature_Log[15] = BCD2UpperCh(year);
Temperature_Log[16] = BCD2LowerCh(year);
Temperature_Log[17] = ',';
Temperature_Log[18] = '+';
Temperature_Log[19] = hundreds;
Temperature_Log[20] = tens;
Temperature_Log[21] = ones;
Temperature_Log[22] = '.';
Temperature_Log[23] = tens;
Temperature_Log[24] = 'C';
Temperature_Log[25] = '\r';
Temperature_Log[26] = '\n';
Mmc_Fat_Append();
Mmc_Fat_Write(Temperature_Log,27);
prev_minutes = minutes;
}
Delay_ms(1000);
}
}

SIMULATION:
After loading the codes into the PIC18F4550 and simulating the circuit the output of the
circuit was as shown in the figure below:
OUTPUT 1:


OUTPUT 2:



CONLUSION:
The laboratory task was successfully achieved because the temperature sensor measured the
temperature values correctly and the values were successful recording on the multimedia
memory card.
The values recorded on the memory card can be viewed from the text file created during the
simulation. From simulation the text file is shown below.

Potrebbero piacerti anche