22 Nisan 2010 Perşembe

DS1307 + PIC16F877A Gerçek zamanlı saat


DS1307 + PIC16F877A    

Schematic of DS1307 and PIC16F877a or PIC16F887   





Ds 1307 ve PIC 16F877 A PIC kullanılarak yapılmış gerçek zaman saati alnızca Micro C Kompiler kullanmanızı tavsiye ederim kod aşşağıda verilmiştir





//Sample code for 
//DS1307 RTC Ineterfacing with PIC16F877A 
//Coded by Pynn Pynn 
//Compiler: mikroC 8.0.0 
//http://picnote.blogspot.com 
//07/06/2008 
//Use with your own risk 

unsigned short read_ds1307(unsigned short address );
unsigned short sec;
unsigned short minute;
unsigned short hour;
unsigned short day;
unsigned short date;
unsigned short month;
unsigned short year;
unsigned short data;
char time[9];
char ddate[11];

unsigned char BCD2UpperCh(unsigned char bcd);
unsigned char BCD2LowerCh(unsigned char bcd);

void main(){

I2C_Init(100000); //DS1307 I2C is running at 100KHzPORTB = 0;
TRISB = 0// Configure PORTB as output 
TRISC = 0xFF;
Lcd_Init(&PORTB); // Initialize LCD connected to PORTBLcd_Cmd(Lcd_CLEAR); // Clear displayLcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor offLcd_Out(11"TIME:");
Lcd_Out(21"DATE:");

while(1)
{
sec=read_ds1307(0); // read secondminute=read_ds1307(1); // read minutehour=read_ds1307(2); // read hourday=read_ds1307(3); // read daydate=read_ds1307(4); // read datemonth=read_ds1307(5); // read monthyear=read_ds1307(6); // read year

time[0] = BCD2UpperCh(hour);
time[1] = BCD2LowerCh(hour);
time[2] = ':';
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[5] = ':';
time[6] = BCD2UpperCh(sec);
time[7] = BCD2LowerCh(sec);
time[8] = '\0';

ddate[0] = BCD2UpperCh(date);
ddate[1] = BCD2LowerCh(date);
ddate[2] ='/';
ddate[3] = BCD2UpperCh(month);
ddate[4] = BCD2LowerCh(month);
ddate[5] ='/';
ddate[6] = '2';
ddate[7] = '0';
ddate[8] = BCD2UpperCh(year);
ddate[9] = BCD2LowerCh(year);
ddate[10] = '\0';

Lcd_Out(1,6,time);
Lcd_Out(2,6,ddate);
Delay_ms(500);
}
}

unsigned short read_ds1307(unsigned short address)
{
I2C_Start();
I2C_Wr(0xd0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0I2C_Wr(address);
I2C_Repeated_Start();
I2C_Wr(0xd1); //0x68 followed by 1 --> 0xD1
data=I2C_Rd(0);
I2C_Stop();
return(data);
}


unsigned char BCD2UpperCh(unsigned char bcd)
{
return ((bcd >> 4) + '0');
}

unsigned char BCD2LowerCh(unsigned char bcd)
{
return ((bcd & 0x0F) + '0');
}

Yukardaki kod isis simülatörü ile test edilmiş kodun çalıştığı görülmüştür

Hiç yorum yok:

Yorum Gönder

İzleyiciler

LED DİRENÇ HESAPLAMA

All LEDs require current limiting, without a current limiting mechanism the LED will usually burn out in under a second. Adding a simple resistor is the easiest way to limit the current. Use the calculator below to find out the value of resistor you require.

For example if you are wanting to power one of our_blank">red LEDs in an automotive application you would see that the typical forward voltage is 2.0 Volts and the maximum continuous forward current is 30mA. Therefore you would enter 14.5, 2.0 and 30 into the Single LED calculation box. After calculating you get 470ohm 1 watt as the result. Here is a that allows you to enter a resistor value and generate the corresponding color code.

Note: For automotive applications use the actual system voltage, not 12 Volts. Most 12 Volt system actually operate at around 14.5 Volts.

Supply Voltage
VOLTS
Voltage Drop Across LED
VOLTS
Desired LED Current
MILLIAMPS



Calculated Limiting Resistor
OHMS
Nearest higher rated 10% resistor

Calculated Resistor Wattage
WATTS
Safe pick is a resistor with
power rating of (common values are .25W, .5W, and 1W)
WATTS

LEDs in series

Several leds in series with one resistor
Supply Voltage
VOLTS
Voltage Drop Across LED
VOLTS
Desired LED Current
MILLIAMPS
How many LEDs connected




Calculated Limiting Resistor
OHMS
Nearest higher rated 10% resistor

Calculated Resistor Wattage
WATTS
Safe pick is a resistor with
power rating of (common values are .25W, .5W, and 1W)
WATTS
LM317 UYGULAMA DEVRELERİ HESAPLAMASI

 




Çıkış Voltajı
R1 resistor

R2 resistor

R1 resistor
R2 resistor

Çıkış Voltajı


Lm317 uygulama devreleri ve detayli bilgiye Buradan ulasabilirsiniz

LM555 - ASTABLE OSCILLATOR CALCULATOR

LM555 - ASTABLE OSCILLATOR CALCULATOR
Value Of R1 Ohms Value Of R2 Ohms
Value Of C1 Microfarads
Output Time HIGH SECONDS Output Time LOW SECONDS Output Period HIGH + LOW SECONDS Output Frequency HERTZ Output Duty Cycle PERCENT
Resistor values are in Ohms (1K = 1000) - Capacitor values are in Microfarads (1uF = 1)

NOTE: The leakage currents of electrolytic capacitors will affect the actual output results of the timers. To compensate for leakage it is often better to use a higher value capacitor and lower value resistances in the timer circuits.

LM555 Astable Oscillator Circuit Diagram


LM555 - ASTABLE CAPACITOR CALCULATOR

The next calculator can find the capacitance needed for a particular output frequency if the values of R1 and R2 are known.

Value Of R1 Ohms Value Of R2 Ohms
Frequency Desired Hertz
Capacitance uF
s

VOLT AMPER OHM ve WATT HESAPLAMA

Current:
kA (kiloamps) A (amps) mA (milliamps) µA (microamps)
Voltage:
kV (kilovolts) V (volts) mV (millivolts) µV (microvolts)