Sunday, 22 November 2015

Digital clock using TIMER1 in ATMEGA32



#include <avr/io.h>
#include <util/delay.h>
void cmd(int);
void data(char);
void conv(int);
int main(void)
{ int i,j,k,f=0;

DDRA=0xff;
DDRB=0xff;
DDRC=0xff;
TCCR1B=0x05;
PORTC=0x00;
cmd(0x38);
cmd(0x01);
cmd(0x0e);
cmd(0x06);
cmd(0x80);

    while(1)
    {
     for(i=10;i<12;i++)
        for(j=20;j<60;j++)
    for(k=0;k<60;k++)
{
                TCNT1H=0xfa;
TCNT1L=0x00;
while((TIFR&0x04)==0);
TIFR|=0x04;
                conv(i);
data(':');
conv(j);
data(':');
conv(k);
data(' ');
if (f%2==0)
{
data('A');
data('M');
}
else
{
data('P');
data('M');
}
if (i==10&&j==20&&k==10)
PORTC=0x01;


cmd(0x80);
}
f++;
}
}
void conv(int k)
{
int c,i=0;
char o[]="00";
while (k>0)
{
c=k%10;
k=k/10;
o[i]=c+48;
 i++;   }
for(i=1;i>=0;i--)
data(o[i]);
}

void cmd(int a)
{
PORTB=a;
PORTA=0x02;
_delay_ms(100);
PORTA=0x00;
}

void data(char a)
{
PORTB=a;
PORTA=0x03;
_delay_ms(100);
PORTA=0x01;
}

Saturday, 21 November 2015

Home Automation System using PIC

USART---Inputs     L>>Lights
                              F>>Fan
Speed and Brightness control using PWM (according to the options entered through USART)

#include<pic.h>
void main()
{
char e,a;
TRISC=0X80;
TRISB=0X00;
PORTB=0X03;
TMR2ON=1;

TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
while(1)
{
while(RCIF==0);
a=RCREG;
RCIF=0;
if(a=='F')
{CCP1CON=0X0C;
CCP2CON=0X00;
while(RCIF==0);
e=RCREG;
RCIF=0;
switch(e)
{case '1':
{CCPR1L=0;
break;
}
case '2':
{CCPR1L=50;
break;
}
case '3':
{CCPR1L=150;
break;
}
case '4':
{CCPR1L=255;
break;
}
}
}
if(a=='L')
{CCP1CON=0X00;
CCP2CON=0X0C;
while(RCIF==0);
e=RCREG;
RCIF=0;
switch(e)
{case '1':
{CCPR2L=0;
break;
}
case '2':
{CCPR2L=50;
break;
}
case '3':
{CCPR2L=150;
break;
}
case '4':
{CCPR2L=255;
break;
}
}
}
}
}

Wednesday, 18 November 2015

Petrol pump automation using PIC


#include<pic.h>
void cmd(int);
void data(char);
void delay(int);
char keypad();
void gate();
void display(const char*);

void main()
{
int i,f=0,y,r=0;
char d[4],e[]="2234",l[]="000",n[]="000",s[3];

TRISB=0XF0;
TRISC=0XF0;
TRISD=0X00;
//TXSTA=0X24;
//RCSTA=0X90;
//SPBRG=0X19;
ADCON1=0X07;
TRISA=0X00;
cmd(0X38);
cmd(0X01);
cmd(0X0E);
cmd(0X06);
cmd(0X80);


if(RC5==1)
{
display("Car");
gate();
r=1;
}

else if(RC6==1)
{
display("Bus");
gate();
r=1;
}

else if(RC7==1)
{
display("Truck");
gate();
r=1;
}



if(r==1)

{
cmd(0X01);
cmd(0X80);
delay(50);

for(i=0;i<4;i++)
{
d[i]=keypad();
data(d[i]);
delay(100);
}

cmd(0X01);
cmd(0X80);


for(i=0;i<4;i++)
if(d[i]!=e[i])
f=1;
if(f==0)
{
display("Pay ");
delay(50);

cmd(0X01);
cmd(0X80);
delay(100);
for(i=0;i<3;i++)
{

s[i]=keypad();
data(s[i]);
delay(100);
}
cmd(0X01);
cmd(0X80);

y=(s[0]-48)*100+(s[1]-48)*10+(s[2]-48);
switch(y)
{
case 100:
{
PORTA=0X01;
delay(50);
PORTA=0X00;
break;
}
case 200:
{
PORTA=0X01;
delay(100);
PORTA=0X00;
break;
}
case 300:
{
PORTA=0X01;
delay(200);
PORTA=0X00;
break;
}
}
}

else
display("invalid");
delay(100);
}
}

char keypad()
{
int e;
PORTB=0XF7;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return '1';
break;
case 0XD0:
return '2';
break;
case 0XB0:
return '3';
break;
case 0X70:
return '4';
break;
}
PORTB=0XFB;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return '5';
break;
case 0XD0:
return '6';
break;
case 0XB0:
return '7';
break;
case 0X70:
return '8';
break;
}
PORTB=0XFD;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return '9';
break;
case 0XD0:
return '0';
break;
case 0XB0:
return 'A';
break;
case 0X70:
return 'B';
break;
}
PORTB=0XFE;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return 'C';
break;
case 0XD0:
return 'D';
break;
case 0XB0:
return 'E';
break;
case 0X70:
return 'F';
break;
}
}

void display(const char *p)
{
while(*p!='\0')
{
data(*p);
p++;
}
}


void gate()
{
PORTA=0X02;
delay(100);
PORTA=0X01;
delay(100);
PORTA=0X00;
}

void cmd(int s)
{
PORTD=s;
RC0=0;
RC1=0;
RC2=1;
delay(10);
RC2=0;
}

void data(char a)
{
PORTD=a;
RC0=1;
RC1=0;
RC2=1;
delay(10);
RC2=0;
}
void delay(int a)
{
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<a;j++);
}

Tuesday, 17 November 2015

Automatic Toll system using ATMEGA32

Identify the vehicle >> authenticate the customer >> give access >> give the amount to be paid ...

#include <avr/io.h>
#include <util/delay.h>
void cmd(char);
void dat(char);
int password();
void motor();
void lcdstring(const char*);
char key();
int main(void)
{
DDRD=0xf0;
DDRA=0xff;
DDRC=0xff;
DDRB=0x00;
cmd(0x38);
cmd(0x01);
cmd(0x06);
cmd(0x0e);
cmd(0x80);
{
if ((PINB&0x01)==0)
{
lcdstring("bus");
_delay_ms(50);
cmd(0x01);
password();
}
else if ((PINB&0x02)==0)
{
lcdstring("car");
_delay_ms(100);
cmd(0x01);
password();
}
else if ((PINB&0x04)==0)
{
lcdstring("bike");
_delay_ms(100);
cmd(0x01);
password();
}
}
}
char key()
{
int e;
while(1)
{
_delay_ms(100);
PORTD=0x7f;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('1');
case 0x0b:
return('2');
case 0x0d:
return('3');
case 0x0e:
return('4');
}
PORTD=0xbf;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('5');
case 0x0b:
return('6');
case 0x0d:
return('7');
case 0x0e:
return('8');
}
PORTD=0xdf;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('9');
case 0x0b:
return('0');
case 0x0d:
return('f');
case 0x0e:
return('a');
}
PORTD=0xef;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('s');
case 0x0b:
return('x');
case 0x0:
return('b');
case 0x0e:
return('v');
}
}
}
int password()
{
char i,a[]="123",d[4],f,S;
while(1)
{
lcdstring("enter the password");
cmd(0xc0);
for (i=0;i<=3;i++)
{
d[i]=key();
dat(d[i]);
}
for(i=0;i<=3;i++)
{
if (a[i]==d[i])
{
f=1;
}
else
{
f=0;
break;
}
}
if (f==1)
{
lcdstring("access granted");
motor();
}
else if(f==0)
{
lcdstring("not granted");
}
}
}
void motor()
{
cmd(0x01);
cmd(0x80);
if ((PINB&0x01)==0)
{
PORTA=0xff;
_delay_ms(100);
lcdstring("your bill");
cmd(0xc0);
lcdstring("rs 1000");
}
else if((PINB&0x02)==0)
{
PORTA=0xf6;
_delay_ms(100);
lcdstring("your bill");
cmd(0xc0);
lcdstring("rs 500");
}
else if((PINB&0x04)==0)
{
PORTA=0x77;
_delay_ms(100);
lcdstring("your bill");
cmd(0xc0);
lcdstring("rs 100");
}
}
void cmd(char p)
{
PORTC=p;
PORTA=0x20;
_delay_ms(100);
PORTA=0x00;
}
void dat(char e)
{
PORTC=e;
PORTA=0x30;
_delay_ms(100);
PORTA=0x10;
}
void lcdstring(const char*s)
{
while(*s)
{
dat(*s++);
}
}

Wednesday, 11 November 2015

PWM programming in ARM

  #include<lpc21xx.h>
  int main()
  {

    PINSEL0=0x00008000;
 
    PWMMR0=100;

    PWMMR1=41;

    PWMMR2=78;

    PWMTCR=0x00000009;

   PWMPR=0X00000000;

   PWMTC=0X00000000;

   PWMMCR=0X00000002;

   PWMPCR=0X0604;
   //PWMLER=1;

   while(1);
  }

Monday, 9 November 2015

Motor programming using USART in ATMEGA32



#include <avr/io.h>
#include <util/delay.h>
void cmd(int);
void data(char);
void display(const char*p)
{
while (*p!='\0')
{
data(*p);
p++;
}
}
int main(void)
{char a;
DDRA=0xff;
DDRB=0xff;
DDRC=0xff;
DDRD=0xfe;
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x06;
UBRRH=0x00;
UBRRL=0x19;
cmd(0x38);
cmd(0x01);
cmd(0x06);
cmd(0x0e);
cmd(0x80);
    while(1)
    {
        while((UCSRA&0x80)==0);
a=UDR;
if (a=='f')
{cmd(0x01);
cmd(0x80);
PORTC=0x2e;
display("forward");
}
if(a=='r')
{cmd(0x01);
cmd(0x80);
PORTC=0x1d;
display("reverse");
}
if (a=='s')
{cmd(0x01);
cmd(0x80);
PORTC=0x00;
display("stop");
}
UCSRA=0x00;

    }
}
void cmd(int o)
{
PORTB=o;
PORTA=0x02;
_delay_ms(100);
PORTA=0x00;
}
void data(char p)
{
PORTB=p;
PORTA=0x03;
_delay_ms(200);
PORTA=0x01;
}

Saturday, 7 November 2015

Motor programming in ATMEGA32



#include <avr/io.h>
#include <util/delay.h>
char keypad(void);
void cmd(int);
void data(char);
void display(const char *p)
{
while(*p!='\0')
{
data(*p);
p++;
}
}



int main(void)
{
char a;
DDRA=0xFF;
DDRB=0xFF;
DDRC=0xF0;
DDRD=0xFF;

cmd(0x38);
cmd(0x01);
cmd(0x0e);
cmd(0x06);
cmd(0x80);


    while(1)
    {

a=keypad();
switch(a)
{
case '1':
display("FORWARD");
PORTD=0x1D;
//_delay_ms(2000);
break;
case '2':
display("REVERSE");
PORTD=0x2E;
//_delay_ms(2000);
break;

case '3':
display("STOP");
PORTD=0x00;
//_delay_ms(2000);
break;

}
//PORTD=0xFF;
//_delay_ms(2000);
//cmd(0x01);
//cmd(0x80);

     
 

}
}
char keypad()
{
int e;
PORTC=0x7F;
e=PINC&0x0F;
switch (e)
{
case 0x07:
   return '1';
break;
case 0x0B:
return '2';
break;
case 0x0D:
return '3';
break;
case 0x0E:
return '4';
break;
}
PORTC=0xbf;
e=PINC&0x0f;
switch (e)
{
case 0x07:
   return '5';
break;
case 0x0b:
return '6';
break;
case 0x0d:
return '7';
break;
case 0x0e:
return '8';
break;
}
PORTC=0xdf;
e=PINC&0x0f;
switch (e)
{
case 0x07:
   return '9';
break;
case 0x0b:
return '0';
break;
case 0x0d:
return 'a';
break;
case 0x0e:
return 'b';
break;
}
PORTC=0xef;
e=PINC&0x0f;
switch (e)
{
case 0x07:
   return 'c';
break;
case 0x0b:
return 'd';
break;
case 0x0d:
return 'e';
break;
case 0x0e:
return 'f';
break;
default:
return 'z';
break;
}
    }
void cmd(int a)
{
PORTB=a;
PORTA=0x02;
_delay_ms(200);
PORTA=0x00;
}
void data(char s)
{
PORTB=s;
PORTA=0x03;
_delay_ms(200);
PORTA=0x01;
}

Friday, 6 November 2015

MOTOR programming using PWM and USART (PIC16F877A)

#include<pic.h>
void main()
{
char a;
TRISB=0X00;
TRISC=0X80;
TMR2ON=1;
CCP1CON=0X0C;
TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
PORTB=0X03;
while(RCIF==0);
a=RCREG;
RCIF=0;
switch(a)
{
case '1':
{CCPR1L=0;
 break;
}
case '2':
{CCPR1L=50;
 break;
}
case '3':
{CCPR1L=100;
 break;
}
case '4':
{CCPR1L=250;
 break;
}
}
}
)

PWM programming of PIC16F877A

#include<pic.h>
void delay(int);
void main()

{
TRISC=0X80;
TMR2ON=1;

CCP1CON=0X0C;
CCP2CON=0X0C;

CCPR1L=0;
CCPR2L=0;
delay(1);

CCPR1L=255;
CCPR1H=0X00;
delay(1);
CCPR1L=200;
CCPR1H=0X00;
delay(1);
CCPR1L=170;
CCPR1H=0X00;
delay(1);
CCPR1L=100;
CCPR1H=0X00;
delay(1);
CCPR1L=0;
CCPR1H=0X00;
while(1);


}
void delay(int a)
{
int i;
for(i=0;i<a*1000;i++);
}

Thursday, 5 November 2015

ADC PROGRAMMING OF ATMEGA32

Convert the analog value to digital and display it on LCD

#include <avr/io.h>
#include <util/delay.h>
void cmd(int);
void data(char);

int main(void)
{
int i,a,c,j;
char S[3]="000";

DDRA=0x30;
DDRB=0xff;
ADMUX=0x60;
ADCSRA=0x88;
cmd(0x38);
cmd(0x01);
cmd(0x0e);
cmd(0x06);
cmd(0x80);

    while(1)
    {
ADCSRA|=0x40;

while((ADCSRA&0x10)==0);
a=ADCH;
i=0;
while(a>0)
{
c=a%10;
a=a/10;
S[i]=c+48;
i++;
}
   
  for(j=2;j>=0;j--)
  {data(S[j]);
  }
  cmd(0x01);
  cmd(0x80);
    }
}
void cmd(int a)
{
PORTB=a;
PORTA=0x20;
_delay_ms(200);
PORTA=0x00;
}

void data(char a)
{
PORTB=a;
PORTA=0x30;
_delay_ms(200);
PORTA=0x10;
}

Wednesday, 4 November 2015

ADC programming of PIC16F877A

Convert the analog value(pot) to digital and display it on lcd

#include<pic.h>
void delay();
void cmd(int);
void data(char);
void main()
{
int a,e,i;
char b[]="00000";
TRISB=0X00;
TRISC=0X00;
cmd(0X38);
cmd(0X01);

cmd(0X0E);
cmd(0X80);

ADCON0=0X01;
ADCON1=0X00;
ADGO=1;
while(ADGO==0);
e=ADRESH;
for(i=0;e>0;i++)
{
a=e%10;
e=e/10;
a=a+48;
b[i]=a;
}
data('a');
for(i=2;i>=0;i--)
data(b[i]);

ADCON0=0X09;
ADCON1=0X00;
ADGO=1;
while(ADGO==0);
e=ADRESH;
for(i=0;e>0;i++)
{
a=e%10;
e=e/10;
a=a+48;
b[i]=a;
}
cmd(0XC0);
data('b');
for(i=2;i>=0;i--)
data(b[i]);
delay();
delay();
}
void cmd(int s)
{
PORTB=s;
RC0=0;
RC1=1;
delay();
RC1=0;
}

void data(char a)
{
PORTB=a;
RC0=1;
RC1=1;
delay();
RC1=0;
}
void delay()
{
int k,j;
for(k=0;k<100;k++)
for(j=0;j<100;j++);
}

Sunday, 1 November 2015

TIMER0 MATCH INTERRUPT OF LPC2129/38(ARM7)

  #include<lpc21xx.h>
  void delay();
  __irq void timerint();
  int main()
  {
  IO0DIR=0XFFFFFFFF;
   T0TCR=1;
 
   T0TC=0X00000000;
  T0PR=1;
  T0MCR=0X003;
  T0MR0=0X0F00FFF;
   VICVectCntl0=0x24;
 
   VICIntEnable=0x00000010;
   VICVectAddr0=(unsigned)timerint;
  while(1);
 
  }
  __irq void timerint()
  {
 
  // T0TC=0X00000000;
  IO0SET=0XFFFFFFFF;
  delay();
  IO0CLR=0XFFFFFFFF;
  delay();
  T0IR=0X01;
  VICVectAddr=0;
  }
  void delay()
  {
  int i;
  for(i=0;i<100000;i++);
  }