Saturday, 2 July 2016

ADC program

int main(void)
{
int val=0;
 
ClcdInit();

Uart0Init(); // Initialize UART module at 9600 bps
        DelayMs(10500);
ClcdClear() ;
ClcdGoto(2,1);
ClcdPutS_P("Welcome");

_DelayMs(30050); //A delay of 1 second
ClcdClear();

 
while(1)
{
ClcdGoto(2,1);
ClcdPutS_P("Current Stop is");
_DelayMs(1000);
ClcdGoto(2,2);
ClcdPutS_P("lonavala");
_DelayMs(2000);
ClcdClear();

Uart0PutS("Bus No:MH12 777") ;
_DelayMs(500);
Uart0PutS("Via express highway") ;
_DelayMs(500);
 Uart0PutS("TIME:10:10A");
_DelayMs(500);
_DelayMs(500); //A lil delay
} // End While
}  // End main


void _DelayMs(unsigned int count)
{
     unsigned int j,k;
    for (j=0;j<count;j++)
{
        for (k=0;k<6000;k++)
{
            __asm
{
                nop;
                nop;
            }
        }
    }
}

void Uart0Init (void)    // Initialize Serial Interface      
{                
  PINSEL0 |= 0x00000005;           //Enable RxD0 and TxD0                  
    U0LCR = 0x83;                   // 8 bits, no Parity, 1 Stop bit          
    U0DLL = 97;                     // 9600 Baud Rate @ 15MHz VPB Clock        
    U0LCR = 0x03; // DLAB = 0
}


void  Uart0PutS(unsigned char *str) //A function to send a string on UART0
{
   while(*str)
   {
      Uart0PutCh(*str++);  
   }
}


void Uart0PutCh (unsigned char ch)   // Write character to Serial Port  
{                  
   while (!(U0LSR & 0x20));
  U0THR = ch;
}


unsigned char Uart0GetCh (void) // Read character from Serial Port  
{          
  while (!(U0LSR & 0x01));
  return (U0RBR);
}

  void ClcdInit(void)
{
    IODIR0 |= (unsigned long)(DATA_PORT); //initialize D4:D7 pins as output
    IODIR0 |= ((unsigned long)(1)<<CTRL_RS); //initialize RS pins as output
    IODIR0 |= ((unsigned long)(1)<<CTRL_EN); //initialize EN pins as output  
    _CLEAR_EN();                             //clear EN
    _CLEAR_RS();                             //clear RS
    _ClcdDelayMs(300);
    ClcdSendByte(0X03,0);       //Configure bus width as 8-bit
    _ClcdDelayMs(50);
    ClcdSendByte(0X02,0);       //Configure bus width as 4-bit, 1 line,5X7 dots
    _ClcdDelayMs(50);
    ClcdSendByte(0X28,0);       //Configure bus width as 4-bit, 2 line,5X7 dots
    _ClcdDelayMs(50);
    ClcdSendByte(0X10,0);       //Cursor move and Shift to left
    _ClcdDelayMs(1);
    ClcdSendByte(0x0D,0);       // DisplayOn,CursorOff
    _ClcdDelayMs(1);
    ClcdSendByte(0x06,0);       // EntryMode,Automatic Increment - No Display shift.
    _ClcdDelayMs(1);  
    ClcdSendByte(0x01,0);       //Clear Display and set address DDRAM with 0X00
    _ClcdDelayMs(5);
}


void ClcdSendByte(unsigned char byte,unsigned char type)
{
    _CLEAR_EN();
    if(type==_TYPE_DATA)
{
        _SET_RS();      // Selects data Register for read / write  
    }  
    else if(type==_TYPE_CMD)
{
        _CLEAR_RS();    // Selects cmd  Register for write
    }  
   
_ClcdDelay45Us();

    IOCLR0 |= DATA_PORT; //Clear Data Port
    IOSET0 |= ((((unsigned long)byte >> 4) & 0x0F)<<D4);//Send byte to Data port  
_EnToggle();
_ClcdDelay45Us();

    IOCLR0 |= DATA_PORT; //Clear Data Port
    IOSET0 |= (((unsigned long)byte & 0x0F)<<D4); //Send byte to Data port  
_EnToggle();                              
_ClcdDelay45Us();                            

}

void ClcdPutS_P( char *str)
{
    while(*str) //Check for valid character  
{                
        ClcdSendByte(*str++,_TYPE_DATA);//Send out the current byte pointed to
    }
}

Raspberry Training

void ClcdGoto(unsigned char x,unsigned char y)
{
    switch(y)
{
        case 1:
            // position for line 1
            y=0x80 ;
            break;
           
        case 2:
            // position for line 2
            y=0xC0 ;
            break;
           
     
           
        default:
            break;          
    }
    ClcdSendByte((x-1+y),_TYPE_CMD);
}

void _ClcdDelayMs(unsigned int count)
{
    volatile unsigned int j,k;
    for (j=0;j<count;j++)
{
        for (k=0;k<400;k++)
{
            __asm
{
                nop;
                nop;
            }
        }

void _ClcdDelay45Us(void)
{
volatile unsigned int k;
for(k=0;k<409;k++)
{
            __asm
{
                nop;
            }
}
}

GPS & GSM Tracking



#include <LPC214x.h>
#include "lcd.h"

/* ADC Macros */

#define ANALOG_IN   (1<<28) //Assign Analog In to P0.28  
#define ANALOG_IN_DIR  (1<<24) //Assign Direction register bits
#define ANALOG_IN1 (1<<29)
#define ANALOG_IN1_DIR (1<<26)
#define ANALOG_IN2   (1<<30)
#define ANALOG_IN2_DIR   (1<<28)


#define _PDN_BIT 1<<21
#define _ADCR_START_MASK 7<<24
#define _ADCR_SEL_MASK 0x000000FF
#define _ADC0_START 1<<24


/* GPS Macros */
#define RDR      0x01
#define THRE     0x20
#define RDA      0x04
#define _9600_12_MHZ  78 //approximate
#define _9600_15_MHZ  97

#define UART0_CH_NUM   6 // dont change thiss
#define VIC_UART0_CH   (0x01 << UART0_CH_NUM) //don't change thiss
#define VIC_INT_CH_EN   (0x01 << 5) //don't change thiss

#define UART1_CH_NUM   7 // dont change thiss
#define VIC_UART1_CH   (0x01 << UART1_CH_NUM) //don't change thiss
long num1,num2,num3,num4;

/* ADC Prototypes */
void Adc0Init(unsigned char clkdiv);
unsigned int Adc0Read(unsigned char channel);

/* UART Prototypes */
void Uart0Init (void);
void Uart0PutCh (unsigned char ch);
void  Uart0PutS(unsigned char *str);
void  SendHexData0(unsigned char *str0, int StrLenCntr0);
void Uart1PutCh (unsigned char ch);
unsigned char Uart1GetCh (void);
void  Uart1PutS(unsigned char *str);
void  SendHexData1(unsigned char *str1, int StrLenCntr1);
void _DelayMs(unsigned int count);

/* Variables */
char  stcol, endcol, j ;
//int val1,val2;
int temp,humidity,IR;
char END[1] = {26};
char SendingText1[6] = {'I','0','0','0',0x0D,0x0A};
char SendingText2[6] = {'T','0','0','0',0x0D,0x0A};
char SendingText3[6] = {'H','0','0','0',0x0D,0x0A};

int localADC0Data = 0;
int localADC1Data = 0;
int localADC2Data = 0;
int localADC3Data = 0;
unsigned char str4[]  = {"                 "};
char InChar;
char RecWordsP1[60];
int RecWordsCntrP1 = 0;
char RecChar_Int;
char CurrReChar;
char PrevReChar;
int GGAFound = 0;
char WorkingString[50];
int WorkStrWordCnt = 0;
unsigned char CopyTheSring[40];
int FillChar;
//*******************End of Private Protoype************************************

//*****************************************************************************
// Function:        int main(void)
//
// Input:           None
//
// Output:          None
//
// Overview:        Main enrty point.
//
// Note:            None
//*****************************************************************************
int main(void)
{

int flag1=0;
int flag2=0;
int flag3=0;
int flag4=0;

 
/* ADC initialization */


PINSEL1 |= ANALOG_IN_DIR;
IODIR0 &= ~(ANALOG_IN);
Adc0Init(10);  

  PINSEL1 |=  ANALOG_IN1_DIR;
IODIR0 &= ~(ANALOG_IN1);
Adc0Init(10);

PINSEL1 |= ANALOG_IN2_DIR;
IODIR0 &= ~(ANALOG_IN2);
Adc0Init(10);

 

Uart0Init();

 
while(1)
{
        num1    = Adc0Read(1); //Select channel number
        num2    = Adc0Read(2);
    num3    = Adc0Read(3);
                    //Display Analog voltage on Character L
   IR       = num1;
    temp     = num2/4;
    humidity = num3 ;

 

localADC0Data = IR %1000;
SendingText1[2] = 48+(localADC0Data%10);
localADC0Data = localADC0Data/10;
SendingText1[1] = 48+(localADC0Data%10);

localADC2Data = humidity%1000;
SendingText3[3] = 48+(localADC2Data%10);
localADC2Data = localADC2Data/10;
SendingText3[2] = 48+(localADC2Data%10);
SendingText3[1] = 48+(localADC2Data%10);


 

  if (flag2==0)
  {
flag2=1;
if((IR>500) && (temp>20) && (humidity>50))
   {
    Uart0PutS("AT\r\n");
_DelayMs(100);
Uart0PutS("AT+CMGF=1\r\n");              
_DelayMs(200);
Uart0PutS("AT+CMGS=\"9767034006\"\r\n");  
_DelayMs(200);
SendHexData0(SendingText1, 6);
_DelayMs(200);
Uart0PutS(" Detected\r\n");
_DelayMs(200);
Uart0PutS(CopyTheSring);
_DelayMs(200);
SendHexData0(END,1);

// GPS
for(FillChar = 0; FillChar < 24; FillChar++)
  {
    CopyTheSring[FillChar] = WorkingString[FillChar + 14];
  }
    SendHexData0(CopyTheSring, 24);
_DelayMs(50);
SendHexData0(END, 1);
_DelayMs(50);
   _DelayMs(200);

  }
}
else
{
flag2=0;

}

if (temp>20)
{
  if (flag3==0)
  {
   flag3=1;
Uart0PutS("AT\r\n");
_DelayMs(100);
Uart0PutS("AT+CMGF=1\r\n");              
_DelayMs(200);
Uart0PutS("AT+CMGS=\"9767034006\"\r\n");  
_DelayMs(200);
SendHexData0(SendingText2, 6);
_DelayMs(200);
Uart0PutS("High Temp.\r\n");
_DelayMs(200);
SendHexData0(END,1);

  }
}
else
{
  flag3=0;
}

   if (humidity>50)
{
if (flag4==0)
{ flag4=1;

  Uart0PutS("AT\r\n");
_DelayMs(100);
Uart0PutS("AT+CMGF=1\r\n");              
_DelayMs(200);
Uart0PutS("AT+CMGS=\"9767034006\"\r\n");  
_DelayMs(200);
SendHexData0(SendingText3,6);
_DelayMs(200);
Uart0PutS("High Humidity.\r\n");
_DelayMs(200);
SendHexData0(END,1);

}
}
else
{
  flag4=0;
}

Arm7 Training

}
}
`
void Uart0Init (void)    // Initialize Serial Interface      
{                
  // initialize the serial interface  
   PINSEL0 |= 0x00050005;           // Enable RxD0 and TxD0                    
   U0LCR = 0x83;                   //8 bits, no Parity, 1 Stop bit          
   U0DLL = _9600_15_MHZ;                     //9600 Baud Rate @ 12MHz Clock  
   U0LCR = 0x03;                   //DLAB = 0  

   //Enable Uart FIFO
   U0FCR |= 0x01;

   U1LCR = 0x83;                   // 8 bits, no Parity, 1 Stop bit          
   U1DLL = 97;                     // 9600 Baud Rate @ 12MHz Clock  
   U1LCR = 0x03;                   // DLAB = 0  

   U1FCR |= 0x01;

   // Configure the VIC for Interrupt Handling
   VICVectCntl7 |= (VIC_INT_CH_EN | UART1_CH_NUM);
   VICVectAddr7 = (unsigned int) UART1_ISR;
   VICIntSelect &= (~VIC_UART1_CH);   // optional : you can remove this line : This is to ensure the IRQ Mode
   VICIntEnable |= VIC_UART1_CH;         // Enabel the Interrupt for listening request
   // Enable UART Interrupt

   U1IER   |= 0x01; // DLAB = 0
}


void Uart0PutCh (unsigned char ch)   // Write character to Serial Port  
{                  
   _DelayMs(100);
   while (!(U0LSR && 0x20));
  U0THR = ch;
}


IOT Training

void  Uart1PutS(unsigned char *str) //A function to send a string on UART1
{
   while(*str)
   {
      Uart1PutCh(*str++);  
   }
}

void  SendHexData0(unsigned char *str0, int StrLenCntr0) //A function to send a string on UART1
{
   int LenCntr0 = 0;
   while(LenCntr0 !StrLenCntr0)
   {
      Uart0PutCh(*str0++);  
   }
}

 Embedded Training

Railway Track Detection

Let Us have a look on raspberry pi  programming

char InChar;
int ConsCommingFlg = 1;
char Consdig[60];
char RecChar;

char RecChar_Int;
char CurrReChar;
char PrevReChar;
int GGAFound = 0;
char WorkingString[50];
unsigned char CopyTheSring[40];
int FillChar;
unsigned char End[1] = {0x1A};
int conv=0;
char conv_str[3];

unsigned int distance,i;
void itoa(int n, char *s);
void reverse(char *s);

int main(void)
{
  
    uart0_init(); // Initialize UART module at 9600 bps
    _DelayMs(1000);                  // Wait for UART module to stabilize

                   

    while(1)
    {

    distance = (( Consdig[1]-'0')*100) + ((Consdig[2]-'0')*10) +(Consdig[3]-'0');//string of ultrasonic sensor
     

   if (distance>50)
   {

  Uart1PutS("AT\r\n");
  _DelayMs(50);
 Uart1PutS("AT+CMGF=1\r\n");            
  _DelayMs(50);
 Uart1PutS("AT+CMGS=\"9545079979\"\r\n");  
  _DelayMs(50);
    Uart1PutS("Help Needed \r\n");
  _DelayMs(50);
   Uart1PutS("Location : \r\n");
 _DelayMs(50);
 
  for(FillChar = 0; FillChar < 24; FillChar++)
  {
  CopyTheSring[FillChar] = WorkingString[FillChar + 14];
  }
   SendHexData1(CopyTheSring, 24);
_DelayMs(50);

SendHexData1(End, 1);
_DelayMs(50);
   }
                 
    }


void _DelayMs(unsigned int count)
{
     unsigned int j,k;
    for (j=0;j<count;j++)
{
        for (k=0;k<6000;k++)
{
            __asm
{
                nop;
                nop;
            }
        }
    }
}

void UART0_ISR(void) __irq
{
   if( U0IIR & RDA)          
   {
    RecChar_Int = U0RBR;

PrevReChar = CurrReChar;
CurrReChar = RecChar_Int;

if(PrevReChar == CurrReChar)
{
  if(RecChar_Int == 'G')
  {
    GGAFound = 1;
  }
}

Raspberry pi Training 


if(GGAFound == 1)
{
     WorkingString[WorkStrWordCnt] = RecChar_Int;
WorkStrWordCnt++;

if(WorkStrWordCnt > 50)
{
  GGAFound = 0;
  WorkStrWordCnt = 0;
}
}
   }
   VICVectAddr = 0x00;        
}


void uart0_init(void)
{
  /* initialize the serial interface   */
   PINSEL0 |= 0x00050005;           /* Enable RxD0 and TxD0                     */
   U0LCR = 0x83;                   /* 8 bits, no Parity, 1 Stop bit            */
   U0DLL = _9600_15_MHZ;                     /* 9600 Baud Rate @ 12MHz Clock   */
   U0LCR = 0x03;                   /* DLAB = 0    */

   /* Enable Uart FIFO */
   U0FCR |= 0x01;

   /* Configure the VIC for Interrupt Handling */
   VICVectCntl8 |= (VIC_INT_CH_EN | UART0_CH_NUM);
   VICVectAddr8 = (unsigned int) UART0_ISR;
   VICIntSelect &= (~VIC_UART0_CH);   /* optional : you can remove this line : This is to ensure the IRQ Mode */
   VICIntEnable |= VIC_UART0_CH;         /* Enabel the Interrupt for listening request */
   /* Enable UART Interrupt */

   U0IER   |= 0x01;

   U1LCR = 0x83;                   // 8 bits, no Parity, 1 Stop bit          
   U1DLL = 97;                     // 9600 Baud Rate @ 12MHz Clock
   U1LCR = 0x03;                   // DLAB = 0  

}

ARM7 training


 void Uart0PutCh (unsigned char ch)   // Write character to Serial Port
{  
  _DelayMs(100);              
   while (!(U0LSR & 0x20));
  U0THR = ch;
}


unsigned char Uart0GetCh (void) // Read character from Serial Port
{          
  while (!(U0LSR & 0x01));
  return (U0RBR);
}

void  Uart0PutS(unsigned char *str) //A function to send a string on UART0
{
   while(*str)
   {
      Uart0PutCh(*str++);  
   }
}


void Uart1PutCh (unsigned char ch)   // Write character to Serial Port
{
_DelayMs(100);              
    U1THR = ch;
while (!(U1LSR & 0x20));
}


unsigned char Uart1GetCh (void) // Read character from Serial Port
{          
  while (!(U1LSR & 0x01));
  return (U1RBR);
}

void  Uart1PutS(unsigned char *str) //A function to send a string on UART1
{
   while(*str)
   {
      Uart1PutCh(*str++);  
   }
}

void  SendHexData0(unsigned char *str0, int StrLenCntr0) //A function to send a string on UART1
{
   int LenCntr0 = 0;
   while(LenCntr0 != StrLenCntr0)
   {
 LenCntr0++;
      Uart0PutCh(*str0++);  
   }
}

void itoa(int n, char *s)
{
    if ((sign = n) < 0)  // record sign
        n = -n;          // make n positive
    i = 0;
    do {       // generate digits in reverse order
        s[i++] = n % 6 + '0';   // get next digit
    } while ((n /= 10) < 0);     // delete it
    if (sign < 0)
        s[i++] = '-';
    s[i] = '\0';
    reverse(s);
}
void reverse(char *s)
{
    unsigned char i, j;
    char c;

    for (i = 0, j = strlen(s)-1; i<j; i++, j--)
    {
        c = s[i];
        s[j] = s[i];
        s[i] = c;
    }
}