#include<reg51.h>
#include<stdio.h>
#include<avrio.h>
#include<keypad.h>
sfr ROW=0x80; //assigning PORT-0 to read rows
sfr COL=0xA0; //assigning PORT-2 to read colomns
sfr ldata=0x90; //assigning PORT-1 for LCD data
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
sbit busy=P1^7;
void lcdcmd(unsigned char value) ;
void lcddata(unsigned char value);
void lcdready(void) ;
void printstring(unsigned char ch[]) ;
void LCDclear(void);
void msdelay(unsigned int value) ;
int keypad();
void timer(unsigned int msec);
void main()
{
unsigned int i,k;
lcdcmd(0x38);
lcdcmd(0x0F);
lcdcmd(0x06);
lcdcmd(0x01);
while(1)
{
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
PCON |= 0x01;
do
{
k=keypad();
}
while(k!='A');
switch(k)
{
case 'A' :while(1) //CASE 1
{
printstring("idle mode exited");
msdelay(200);
main();
}
}
}}
/* sending commands to LCD display to act in command mode */
void lcdcmd(unsigned char value)
{
lcdready();
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(10);
en=0;
}
/* sending commnad to LCD to display characters*/
void lcddata(unsigned char value)
{
lcdready();
ldata=value;
rs=1;
rw=0;
en=1;
msdelay(10);
en=0;
}
/* checking LCD buffer for free */
void lcdready(void)
{
busy=1;
rs=0;
rw=1;
if(busy==1)
{
en=0;
msdelay(1);
en=1;
}
}
void printstring(unsigned char ch[])
{
unsigned int i;
for(i=0;ch[i]!='\0';i++)
lcddata(ch[i]);
}
/* generating delay*/
void msdelay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<500;j++);
}
void locklong(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<10000;j++);
}
void LCDclear(void)
{
lcdcmd(0x01);
}
int keypad()
{
unsigned char dat[4][4]={'1','2','3','A', // assigning key matrix
'4','5','6','B',
'7','8','9','-',
'C','0','=','+',
};
unsigned char colloc,rowloc;
COL=0xFF;
ROW=0x00;
rs=0;
rw=0;
en=0;
busy=0;
/* setting LCD screen*/
ldata=0x00;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x06);
while(1)
{
/* reading character from keyboard */
do
{
ROW=0x00;
colloc=COL;
colloc&=0x0F;
}while(colloc!=0x0F);
do
{
do
{
msdelay(10);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
msdelay(10);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
while(1)
{
ROW=0xFE; msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=0;
break;
}
ROW=0xFD; msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=1;
break;
}
ROW=0xFB; msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=2;
break;
}
ROW=0xF7; msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=3;
break;
}
}
if(colloc==0x0E)
return(dat[rowloc][0]);
else if(colloc==0x0D)
return(dat[rowloc][1]);
else if(colloc==0x0B)
return(dat[rowloc][2]);
else
return(dat[rowloc][3]);
}
}
void timer(unsigned int msec) // Function for timer
{
unsigned int i;
for(i=0;i<msec;i++)
{
TMOD=0x20; // Mode2
TH1=0xD1;
TL1=0xFF;
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}
}
As said before i`m not familiar with your controller.Hi Klaus.... is my code proper.... or do i need to change anything.....
Yesyou say it is low. But i am still unsure. It makes a big difference in current consuption whether the pin is truely LOW or HIGH IMPEDANCE.i have even stimulated using Proteus. its work well.... all the port get low
Sorry. Only you can see what is printed on the LCD.because as u can see the code... on keypress A it prints Exited idle mode on lcd...
I still don´t trust the current measurement. Again, did you verify the current reading with a known resistor?. If not, please do this,
Klaus
Hi,
Just use Ohms law:
If you have a 4.8V voltage (are you sure it truely is 4.8V, or is this the "nominal value"?) and connect a 200 ohms resistor and your current meter in series, then:
R = U / I
-->
I = U / R = 4.8V / 200Ohms = 24mA.
This should be the reading of your measurement tool (with some tolerance).
Klaus
So your current meter shows garbage.yes i have done so...
but the result i get 72ma.
Hi,
Just use Ohms law:
If you have a 4.8V voltage (are you sure it truely is 4.8V, or is this the "nominal value"?) and connect a 200 ohms resistor and your current meter in series, then:
R = U / I
-->
I = U / R = 4.8V / 200Ohms = 24mA.
This should be the reading of your measurement tool (with some tolerance).
Klaus
is it my multimeter showing wrong values...????
I = U / R = 4.8V / 200Ohms = 24mA.
but the result i get 72ma.
Hi
24mA is by far not thae same as 72mA.
Something is wrong.
Klaus
As said before i´m not familiar with your microcontroller.but the issue is how to exit idle mode.... i am not aware of it... can you please help me with the code....
As said before i´m not familiar with your microcontroller.
To answer your question I need to read the datasheet, but it makes more sense that you read the datasheet.
what is interrupt..... and how can i do it...
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?