Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/25/08 07:46
Read: times


 
#157721 - the entire code
Responding to: ???'s previous message
#include<reg51.h>

void sfwdmtrcntrl (void);
void tfwdmtrcntrl(void);
void fan1cntrl(void);
void Key_Scan(void);
void DelayMs(unsigned int);

unsigned char ch , C , R ;
unsigned char keypad[4][4] = {'1','2','3','4', //Matrix Keypad Character
'5','6','7','8', //Initialization
'9','0','A','B',
'C','D','E','F',
};


sbit f1=P1^4;
sbit fl1=P1^6;
sbit l1=P3^2;
sbit sfwd=P1^0;
sbit srev=P1^1;
sbit l2=P3^3;
sbit tfwd=P1^2;
sbit trev=P1^3;

void fan1cntrl()
{ f1=~f1;
fl1=~fl1;
}

void ex0_isr (void) interrupt 0
{
if(l1==1)
{
sfwd=1;
srev=0;
}
else
{ sfwd=0;
srev=0;
}

}

void sfwdmtrcntrl()
{
if (l1==1)
{
sfwd=1;
srev=0;
}
else
{
sfwd=0;
srev=0;
}

}

void ex1_isr (void) interrupt 2
{
if (l2==1)
{tfwd=1;
trev=0;
}
else{tfwd=0;
trev=0;}
}

void tfwdmtrcntrl()
{
if (l2==1)
{tfwd=1;
trev=0;
}
else{tfwd=0;
trev=0;}
}


void main()
{ P3=0xFF; //port 3 as an input port
P1=0x00; //port 1 as an output port,for LEDs

while(1)
{

//DelayMs(45);
EA=1;

EX0 = 1;// Enable EX0 Interrupt,by default as level triggered

EX1 = 1;



Key_Scan();
ch = keypad[R][C];

switch (ch)
{
case '1' : sfwdmtrcntrl();
break;
case '2' : tfwdmtrcntrl();
break;
case '3' : fan1cntrl();
break;
default : break;
}


}
}

void Key_Scan()
{
unsigned int i = 0;

//Scanning for Row Value

P2 = 0x0F; //Initialize Port2 to 0Fh
while(P2 == 0x0F);
if(P2 == 0x0E) //Checking for Row0
R = 0;
else if(P2 == 0x0D) //Checking for Row1
R = 1;
else if(P2 == 0x0B) //Checking for Row2
R = 2;
else if(P2 == 0x07) //Checking for Row3
R = 3;

//Scanning for Column Value

P2 = 0xF0; //Initialize Port2 to F0h
while(P2 == 0xF0);
if(P2 == 0xE0) //Checking for Column0
C = 0;
else if(P2 == 0xD0) //Checking for Column1
C = 1;
else if(P2 == 0xB0) //Checking for Column2
C = 2;
else if(P2 == 0x70) //Checking for Column3
C = 3;
}

void DelayMs (unsigned int value)
{
unsigned int x,y;
for(x=0;x<1275;x++)
for(y=0;y<value;y++);
}



...replace this with your code...


List of 24 messages in thread
TopicAuthorDate
pls help....8051 external interrupts            01/01/70 00:00      
   show definition of "a" variable            01/01/70 00:00      
      definiton : sbit a=P3^2;            01/01/70 00:00      
   Need more information            01/01/70 00:00      
      the entire code            01/01/70 00:00      
         keyscan            01/01/70 00:00      
         How the LED are connected?            01/01/70 00:00      
         One tip            01/01/70 00:00      
   P3.2= iNT0            01/01/70 00:00      
      P3.2= INT0            01/01/70 00:00      
         pin 3.2            01/01/70 00:00      
            P3.2= INT0..1            01/01/70 00:00      
   Obvious Reason            01/01/70 00:00      
      time duration            01/01/70 00:00      
         mistake            01/01/70 00:00      
            ok thanks alot            01/01/70 00:00      
               ?            01/01/70 00:00      
   GATE0/1 ?            01/01/70 00:00      
      no            01/01/70 00:00      
      try            01/01/70 00:00      
         Debounce maybe?            01/01/70 00:00      
      Solution            01/01/70 00:00      
   interrupt flag bit clear            01/01/70 00:00      
      Detecting Both Edges - A very old trick            01/01/70 00:00      

Back to Subject List