LPC2148 basic programming tutorial: In the following LPC2148 tutorial i used books to learn fundamental knowledge about Embedded system. After that i install Keil compiler and Proteus simulator tool to implement following basic LPC2148 programming tutorial:
Interfacing of External RTC with LPC2148: In this tutorial External RTCis interfaced with ARM(LPC2148) controller. You need to enter password "1234#", you can use this tutorial for security checking projects. If you want to learn more kindly see tutorial on youtube as well.
>> External RTC interface with LPC2148 C Code: /*******************main.c*******************/ /* Arm lpc2148 based external rtc code Hardware connection LCD data -> P1.16-P1.23 LCD control -> P1.24-P1.31 RTC -> P0.0-P0.7 */ #include<lpc21xx.h> #include"delay.h" #include"lcd.c" #include"RTC_DS1307.h" int main(void){ lcd_init(); RTC_DS1307_init(); RTC_DS1307_set_time(12,42,12); RTC_DS1307_set_date(18,8,14,2); while(1){ Display_Time(0x80); Display_Date(0xc0); Display_Day(0xcA); } } /*************************** ex_i2c.c************************/ #define scl 2 #define sda 3 #define I2C_PORT IO0PIN #define I2C_DDR IO0DIR #define I2C_PIN IO0PIN
void exi2c_init(void){ I2C_DDR |= (1<<scl) | (1<<sda); I2C_PORT |= (1<<scl) | (1<<sda); } //************Start*****************ok void exi2c_start(void) { scl1; //init. scl high sda1; exi2c_delay(1); //then sda high to low sda0; } //***********Stop******************ok void exi2c_stop(void) { scl1; //init. scl high sda0; exi2c_delay(2); //then sda low to high sda1; exi2c_delay(2); //this delay must } //**********Send****************** ok //-----initially scl=low must void exi2c_send(unsigned char value) { unsigned char i=0,temp; scl0; //prs for(;i<8;i++) { temp = value; temp &= 0x80; if(temp ==0x80) sda1; else sda0;
scl1; exi2c_delay(2); scl0; value = value <<1; } exi2c_ack(); } //************Receive**************ok //-----initially scl=low must-------- char exi2c_recv(void) { unsigned char i =0,value =0x00; scl0; //prs I2C_DDR &= ~(1<<sda); sda1; //make sda as input for mc
for(i=0;i<8;i++) { exi2c_delay(2);//very important must value = value <<1; if((I2C_PIN & (1<<sda))) //sda == 1) { value |= 0x01; } scl1; exi2c_delay(2); scl0; }
switch(day) { case 1: lcd_string("SUN"); break; case 2: lcd_string("MON"); break; case 3: lcd_string("TUE"); break; case 4: lcd_string("WED"); break; case 5: lcd_string("THU"); break; case 6: lcd_string("FRI"); break; case 7: lcd_string("SAT"); break; default : lcd_string("Error"); }