Thursday, 9 February 2017

ARM LPC 2148 Embedded 'C' CODES-II

PROGRAM 1:


PROGRAM TO INTERFACE REAL TIME CLOCK WITH LCD

#include <lpc21xx.h>
#include <stdio.h>
void LCD(unsigned char);
void cmd(unsigned int);
void data(unsigned int);
char arr1[10];
unsigned char l,m,n;

void rtc(void)
{
PREINT=0X5A;
PREFRAC=0XC6C0;
CCR=0X00;
SEC=0X00;
MIN=0X24;
HOUR=0X03;
CCR=0X01;
}

void serial()
{
   PINSEL0=0X0000005;         //select TXD0 and RXD0 lines                                            IODIR1 = 0X00ff0000;                   //define as o/p lines
   U0LCR  = 0X00000083;                  //enable baud rate divisor loading and
  U0DLM = 0X00;                              //select the data format
   U0DLL = 0x13;                               //select baud rate 9600 bps
   U0LCR  = 0X00000003;
 }

void delay(void)
{
int i;
for (i=0;i<200000;i++);
}
unsigned int i,x,y,z;

void LCD(unsigned char msg)
{
  unsigned int c[] = {0x20,0x80,0x30,0x38,0x0c,0x01};
  unsigned int i;
  IODIR0 = 0x000000FC;
  for(i=0;i<7;i++)
  {
   cmd(c[i]);
   delay();
  }

                   
    cmd (0x80);
          delay();
          data(msg);
          delay();
          cmd(0x01);
 }
void cmd(unsigned int x)
{
  unsigned int value;
  value = x;
  value = value & 0xF0;
  IOCLR0 = 0xF0;
  IOCLR0 = 0x04; //Rs is reset. Enters command mode.
  IOSET0 = value;
  IOSET0 = 0x08; //Enable is set.
  delay();
  IOCLR0 = 0x08; //Enable is reset.
  value = x;
  value = value & 0x0F;
  value = value << 4;
  IOCLR0 = 0xF0;
  IOCLR0 = 0x04; //Rs is reset. Enters command mode.
  IOSET0 = value;
  IOSET0 = 0x08; //Enable is set.
  delay();
  IOCLR0 = 0x08; //Enable is reset.
}

void data(unsigned int p)
{
  unsigned int value;
  value = p;
  value = value & 0xF0;
  IOCLR0 = 0xF0;
  IOSET0 = 0x04; //Rs is set. Enters write mode.
  IOSET0 = value;
  IOSET0 = 0x08; //Enable is set.
  delay();
  IOCLR0 = 0x08; //Enable is reset.
  value = p;
  value = value & 0x0F;
  value = value << 4;
  IOCLR0 = 0xF0;
  IOSET0 = 0x04; //Rs is set. Enters write mode.
  IOSET0 = value;
  IOSET0 = 0x08; //Enable is set.
  delay();
  IOCLR0 = 0x08; //Enable is reset.
}

int main()
{
serial();
          rtc();
          while(1)
          {
          i=0;
                   x=SEC;
             sprintf(arr1,"sec:%d",x);
          while (arr1[i] != '\0')
          {       
                    while (!(U0LSR & 0x20));
                    U0THR = arr1[i];
          }
           
             { while (!(U0LSR & 0x01));
                   U0RBR = U0THR;
                   l=U0RBR;
                   LCD(l);
                   i++;
             }
         
          delay();        delay();        delay();
          y=MIN;
          i=0;
                    sprintf(arr1,"min:%d",y);
          while (arr1[i] != '\0')
          {
                    while (!(U0LSR & 0x20));
                    U0THR = arr1[i];
                   i++;
          }
           {
              while (!(U0LSR & 0x01));
                   U0RBR = U0THR;
                   m=U0RBR;
                   LCD(m);
                   i++;
            }
          U0THR='\n';
          i=0;
                             delay();
                              z=HOUR;
                             sprintf(arr1,"hour:%d",z);
          while (arr1[i] != '\0')
          {
                    while (!(U0LSR & 0x20));
                    U0THR = arr1[i];
                   i++;
          }
            {
              while (!(U0LSR & 0x01));
                   U0RBR = U0THR;
                   n=U0RBR;
                   LCD(n);
                   i++;
             }
          U0THR='\n';
          i=0;
            delay();

    }
}

PROGRAM 2:

PROGRAM TO INTERFACE REAL TIME CLOCK WITH UART

#include <lpc21xx.h>
#include <stdio.h>
 char arr1[10];
void rtc(void)
{
PREINT=0X5A;
PREFRAC=0XC6C0;
CCR=0X00;
SEC=0X00;
MIN=0X24;
HOUR=0X03;
CCR=0X01;
}

   void serial()
   {
      PINSEL0=0X0000005;                 
       IODIR1 = 0X00ff0000;       
      U0LCR  = 0X00000083;              
       U0DLM = 0X00;
        U0DLL = 0x13;               
        U0LCR  = 0X00000003;
                   }
void delay(void)
{
int i;
for (i=0;i<200000;i++);
}
unsigned int i,x,y,z;
int main()
{
serial();
          rtc();
          while(1)
          {
          i=0;
                   x=SEC;
             sprintf(arr1,"sec:%d",x);
          while (arr1[i] != '\0')
          {       
                    while (!(U0LSR & 0x20));
                    U0THR = arr1[i];
                   i++;
          }
          delay();        delay();        delay();
          y=MIN;
          i=0;
                    sprintf(arr1,"min:%d",y);
          while (arr1[i] != '\0')
          {
                    while (!(U0LSR & 0x20));
                    U0THR = arr1[i];
                   i++;
          }
          U0THR='\n';
          i=0;
                             delay();
                              z=HOUR;
                             sprintf(arr1,"hour:%d",z);
          while (arr1[i] != '\0')
          {
                    while (!(U0LSR & 0x20));
                    U0THR = arr1[i];
                   i++;
}
          U0THR='\n';
          i=0;
            delay();
  }
}


PROGRAM 3:

PROGRAM TO IMPLEMENT REAL TIME CLOCK AS ALARM

#include<LPC21XX.h>
#include<stdio.h>
char arr1[20];
void delay(void)
{
int i;
for(i=0;i<200000;i++);
}
 void start_ALARM_ISR (void) __irq
{
PINSEL0=0X00000000;
IODIR0=0X00FF0200;
IOSET0=0X00FF0200;
//IOCLR0=0X00000200;
if(ILR==0x02)
ILR=0X02;
VICVectAddr=0;
          }
void rtc(void)
{
PREINT=0X5A;
PREFRAC=0X46C0;
CCR=0X00;
SEC=0X00;
MIN=0X00;
HOUR=0X03;
CCR=0X01;
}
void serial()
{
PINSEL0=0X00000005;
U0LCR=0X00000083;
U0DLM=0X00;
U0DLL=0X61;
U0LCR=0X00000003;
}


unsigned int i,x,y,z;
int main()
{
IODIR0=0X00000200;
serial();
rtc();
AMR = 0xFE;
ALSEC=0XA;
VICVectAddr0  = (unsigned long int) &start_ALARM_ISR;
VICVectCntl0  = 0x20 | 13;              // Interrupt priority
VICIntEnable = 0X00002000;
while(1)
{
i=0;
x=SEC;
sprintf(arr1,"SEC:%d\n",x);
while(arr1[i]!='\0')
{
while(!(U0LSR & 0X20));
U0THR=arr1[i];
i++;
}
U0THR=arr1[i];
i=0;
 y=MIN;
sprintf(arr1,"MIN:%d\n",y);
while(arr1[i]!='\0')
{
           while(!(U0LSR & 0X20));
U0THR=arr1[i];
i++;
}
i=0;
delay();
z=HOUR;
sprintf(arr1,"hour:%d",z);
while(arr1[i]!='\0')
{
           while(!(U0LSR & 0X20));
U0THR=arr1[i];
i++;
}
i=0;
}

}

No comments:

Post a Comment

we are hear to discuss your queries ,so please feel free to ask any of your queries.

Wikipedia

Search results