Friday, 9 December 2016
Monday, 14 November 2016
Temperature monitoring system using lm35 in atmega32
#include<avr/io.h>
#include<util/delay.h>
#include<stdio.h>
void cmd()
{
PORTB=0x04;
_delay_ms(150);
PORTB=0x00;
}
void display()
{
PORTB=0x05;
_delay_ms(150);
PORTB=0x01;
}
void lcdstring(unsigned char *p)
{
while(*p!='\0')
{
PORTC=*p;
display();
p++;
}
}
unsigned char arr[]={0x38,0x0e,0x80,0x06};
unsigned int a;
unsigned char res[4];
int i;
void main()
{
DDRA=0x00;
DDRB=0xff;
DDRC=0xff;
for(i=0;i<=3;i++)
{
PORTC=arr[i];
cmd();
}
lcdstring("Temperature is");
ADMUX=0xc0;
ADCSRA=(1<<ADEN)|(1<<0);
while(1)
{
ADCSRA|=(1<<ADSC);
while(!(ADCSRA&(1<<ADIF)));
a=(ADC)/4;
sprintf(res,"%d",a);
PORTC=0xc0;
cmd();
lcdstring(res);
}
}
#include<util/delay.h>
#include<stdio.h>
void cmd()
{
PORTB=0x04;
_delay_ms(150);
PORTB=0x00;
}
void display()
{
PORTB=0x05;
_delay_ms(150);
PORTB=0x01;
}
void lcdstring(unsigned char *p)
{
while(*p!='\0')
{
PORTC=*p;
display();
p++;
}
}
unsigned char arr[]={0x38,0x0e,0x80,0x06};
unsigned int a;
unsigned char res[4];
int i;
void main()
{
DDRA=0x00;
DDRB=0xff;
DDRC=0xff;
for(i=0;i<=3;i++)
{
PORTC=arr[i];
cmd();
}
lcdstring("Temperature is");
ADMUX=0xc0;
ADCSRA=(1<<ADEN)|(1<<0);
while(1)
{
ADCSRA|=(1<<ADSC);
while(!(ADCSRA&(1<<ADIF)));
a=(ADC)/4;
sprintf(res,"%d",a);
PORTC=0xc0;
cmd();
lcdstring(res);
}
}
Saturday, 12 November 2016
interfacing of LCD in 4 bit mode on same port in atmega16/32
#include <avr/io.h>
#include<util/delay.h>
#define rs PA0
#define rw PA1
#define en PA2
void cmd()
{
PORTA&=(~(1<<rs));
PORTA&=(~(1<<rw));
PORTA|=(1<<en);
_delay_ms(200);
PORTA&=(~(1<<en));
}
void display()
{
PORTA|=(1<<rs);
PORTA&=(~(1<<rw));
PORTA|=(1<<en);
_delay_ms(200);
PORTA&=(~(1<<en));
}
unsigned char arr1[]={0x02,0x0e,0x01,0x80,0x06};
unsigned char arr2[]={"welcome in TBA"};
void main()
{
while(1)
{
int i;
DDRA=0XFF;
for(i=0;i<=5;i++)
{
PORTA=arr1[i]&0xf0;
cmd();
PORTA=(arr1[i]<<4)&0xf0;
cmd();
}
for(i=0;i<=14;i++)
{
PORTA=arr2[i]&0xf0;
display();
PORTA=(arr2[i]<<4)&0xf0;
display();
}
}
}
#include<util/delay.h>
#define rs PA0
#define rw PA1
#define en PA2
void cmd()
{
PORTA&=(~(1<<rs));
PORTA&=(~(1<<rw));
PORTA|=(1<<en);
_delay_ms(200);
PORTA&=(~(1<<en));
}
void display()
{
PORTA|=(1<<rs);
PORTA&=(~(1<<rw));
PORTA|=(1<<en);
_delay_ms(200);
PORTA&=(~(1<<en));
}
unsigned char arr1[]={0x02,0x0e,0x01,0x80,0x06};
unsigned char arr2[]={"welcome in TBA"};
void main()
{
while(1)
{
int i;
DDRA=0XFF;
for(i=0;i<=5;i++)
{
PORTA=arr1[i]&0xf0;
cmd();
PORTA=(arr1[i]<<4)&0xf0;
cmd();
}
for(i=0;i<=14;i++)
{
PORTA=arr2[i]&0xf0;
display();
PORTA=(arr2[i]<<4)&0xf0;
display();
}
}
}
interfacing of LCD using arr
#include<avr/io.h>
#include<util/delay.h>
void cmd()
{
PORTA=0B00000100;
_delay_ms(300);
PORTA=0B00000000;
}
void display()
{
PORTA=0B00000101;
_delay_ms(300);
PORTA=0B00000001;
}
unsigned char arr1[]={0x38,0x0e,0x01,0x80,0x06};
unsigned char arr3[]={"welcome in TBA"};
void main ()
{
while(1)
{
int i;
DDRA=0xff;
DDRB=0xff;
for(i=0;i<=4;i++)
{
PORTB= arr1[i];
cmd();
}
for(i=0;i<=14;i++)
{
PORTB=arr3[i];
display();
}
}
}
Interfacing of LCD and introduction.
Introduction
of lcd and interfacing
Lcd(liquid crystal display):-
Series for embedded is
16x1 means 1 row 16 columns
16x2
means 2 row 16 columns
16x4
means 4 row 16 columns
20x1
means 1 row 20 columns
20x2
means 2 row 20 columns
40x1
means 1 row 40 columns
40x2
means 2 row 40 columns
· Lcd
is a individually an embedded product. It is preceed 8-bit data at a time.
· It
has 8 select data line by this 8-bit data is transferred at a time.
· In
this 16 pin in which 15 and 16 pin is provide lcd backlight. Pin 1 and 2
provides power to lcd and 3rd pin vee stands for variable resistance
this is used for control the contrast of lcd.
· Lcd
have 2 registers
1. Command register
2. Data
register
Both
registers are 8-bit.
Pin 4, 5 and 6 are RS, RW and EN
RS-
Register select
Send 0 for command
Send 1 for data.
RW-
READ WRITE
Send 1 for read
Send 0 for write
EN-
ENABLE
send 1 for command
send 1 for data.
after giving delay enable will be zero.
LCD has some predefined commands:-
· 0x01 for clear display screen.
· 0x04
for decrement cursor.
· 0x06 for increment cursor.
· 0x80 force cursor to the beginning
of first line.
· 0xc0
force cursor to the beginning of second line.
· 0x90
force cursor to the beginning of third line.
· 0xdo
force cursor to the beginning of fourth line.
· 0x0e for display on cursor
blinking.
· 0x0f
for display on cursor not blinking.
· 0x02
for select 4 bit mode.
· 0x28
selects 5x7 matrix for 4 bit mode.
· 0x38 selects 5x7 matrix for 8 bit
mode.
· 0x18
fir moving entire display left.
· 0x1c
for moving entire display right.
We are using commonly
these bold commands.
program to display A on LCD screen.
#include<avr/io.h>
#include<util/delay.h>
void cmd()
{
PORTA=0B00000100;
_delay_ms(300);
PORTA=0b00000000;
}
void display()
{
PORTA=0b00000101;
_delay_ms(300);
PORTA=0b00000001;
}
void main()
{
DDRA=0xff;
DDRB=0xff;
PORTB=0X38;
cmd();
PORTB=0X0e;
cmd();
PORTB=0X01;
cmd();
PORTB=0X80;
cmd();
PORTB=0X06;
cmd();
PORTB='A';
display();
}
interfacing of motor in atmega16/32
#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRA=0XFF;
while(1)
{
PORTA=0x0a;
}
}
#include<util/delay.h>
void main()
{
DDRA=0XFF;
while(1)
{
PORTA=0x0a;
}
}
There are two types of motor generally used in embedded
system:-
1.
DC motor
2.
Stepper motor
Commands for two DC motor:-
Forward = 10 10 = 0x0a
Backward = 01 01 = 0x05
Right move = 10 00 = 0x08
Left move = 00 10 = 0x02
Stop = 00 00 = 0x00
Using these commands operate two
DC motors.
In proteus or hardware I need a
motor driver to operate it that’s called L293D
in which 4 inputs and 4 outputs pins , 2 VCC pin , 4 pin for GND, 2
enable pin. This is total 16 pin IC.
interfacing of switch with 7segment in atmega16/32
#include<avr/io.h>
#include<util/delay.h>
int arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void main()
{
int i;
while(1)
{
DDRA=0XFF;
DDRC=0X00;
if(PINC&0X01)
{
for(i=0;i<=9;i++)
{
PORTA=arr[i];
_delay_ms(1000);
}
}
else
{
PORTA=0X00;
}
}
}
In this we are using int arr[]={…………….}; means hex form of 0-9 on segment .
#include<util/delay.h>
int arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void main()
{
int i;
while(1)
{
DDRA=0XFF;
DDRC=0X00;
if(PINC&0X01)
{
for(i=0;i<=9;i++)
{
PORTA=arr[i];
_delay_ms(1000);
}
}
else
{
PORTA=0X00;
}
}
}
In this we are using int arr[]={…………….}; means hex form of 0-9 on segment .
format:-
0= 0x3F
1= 0X06
2 = 0X5B
3= 0X4F
4= 0X66
5= 0X6D
6= 0X7D
7= 0X07
8= 0X7F
9=0X6F
And for loop is using for complete the loop 0-9.
PINC&0X01 means PC0 is active high and by this way we
can make high any pin as a switch.
And according to this program we can write more for programs Like
as using 2 segments and two switch. Like as 1 segment using two switch. Using more
loops etc.
Friday, 11 November 2016
interfacing of switch in atmega16/32
#include <avr/io.h>
void main()
{
while(1)
{
DDRA=0XFF;
DDRC=0X00;
{
if(PINC&0X01)
{
PORTA=0b00000001;
}
else
{
PORTA=0X00;
}
}
}
}
And led is connected on PA0 so PORTA=0b00000001 .
void main()
{
while(1)
{
DDRA=0XFF;
DDRC=0X00;
{
if(PINC&0X01)
{
PORTA=0b00000001;
}
else
{
PORTA=0X00;
}
}
}
}
In this we are using PORTC=0x00 means as input port and
PORTA as output port.
Using if condition for switch if (PINC&0X01) means PC0
is press than this pin is high as input.
In proteus search button for switch and earth is connected
for doing earth after pressing otherwise pin is high for all time. We also use
here pull-down register that’s 10k ohm in hardware also.
And led is connected on PA0 so PORTA=0b00000001 .
0-99 display on 7segment in atmega16/32
#include <avr/io.h>
#include<util/delay.h>
int arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void main()
{
int i,j;
DDRA=0xFF;
DDRB=0xFF;
while(1)
{
for(i=0;i<=1;i++)
{
PORTA=arr[i];
for(j=0;j<=9;j++)
{
PORTB=arr[j];
_delay_ms(1000);
}
}
}
}
#include<util/delay.h>
int arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void main()
{
int i,j;
DDRA=0xFF;
DDRB=0xFF;
while(1)
{
for(i=0;i<=1;i++)
{
PORTA=arr[i];
for(j=0;j<=9;j++)
{
PORTB=arr[j];
_delay_ms(1000);
}
}
}
}
In this program when we are taking i loop 0-9 and j loop 0-9 then
display 0-99 on segment and
for loop is working.
0-19 display on 7segment in atmega16/32
#include <avr/io.h>
#include<util/delay.h>
int arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void main()
{
int i,j;
DDRA=0xFF;
DDRB=0xFF;
while(1)
{
for(i=0;i<=1;i++)
{
PORTA=arr[i];
for(j=0;j<=9;j++)
{
PORTB=arr[j];
_delay_ms(1000);
}
}
}
}
#include<util/delay.h>
int arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void main()
{
int i,j;
DDRA=0xFF;
DDRB=0xFF;
while(1)
{
for(i=0;i<=1;i++)
{
PORTA=arr[i];
for(j=0;j<=9;j++)
{
PORTB=arr[j];
_delay_ms(1000);
}
}
}
}
In this program when we are taking i loop 0-1 and j loop 0-9 then
display 0-19 on segment and
for loop is working.
Thursday, 10 November 2016
interfacing of 7segment basic
#include <avr/io.h>
void main()
{
while (1)
{
DDRA=0XFF;
{
PORTA=0X3F;
}
}
}
void main()
{
while (1)
{
DDRA=0XFF;
{
PORTA=0X3F;
}
}
}
there are two types of 7 segment :
1. Common anode
2. Common cathode
IN 7 segments we are using 7-segment common cathode and colour are own choice.
In this there are some pins:
A, B, C, D, E, F, G and last is dp.
This segment is display 0-9 no. of digits.
In hex form that can be written as:
0= 0x3F
1= 0X06
2 = 0X5B
3= 0X4F
4= 0X66
5= 0X6D
6= 0X7D
7= 0X07
8= 0X7F
9=0X6F
9=0X6F
use this hex form and display any no.
Subscribe to:
Posts (Atom)