??? 09/11/08 09:54 Read: times |
#158179 - code Responding to: ???'s previous message |
#include<reg51.h> void sfwdmtrcntrl (void); void tfwdmtrcntrl(void); void fan1cntrl(void); void Key_Scan(void); void automanual(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', }; int i=2,j=2,k=2,x=0; sbit l1=P0^0; sbit sfwd=P0^2; sbit srev=P0^3; sbit l2=P0^1; sbit tfwd=P0^4; sbit trev=P0^5; void sfwdmtrcntrl() { if((i%2)==0) { sfwd=1; srev=0; while(!l1); sfwd=0; srev=0; } else{sfwd=0;srev=0;} i++; } void main() { while(1) { Key_Scan(); ch = keypad[R][C]; switch (ch) {case '1' :sfwdmtrcntrl(); break; case '2' :automanual() ; break; case '3' : tfwdmtrcntrl(); break; case '4' :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++); } |
Topic | Author | Date |
HELP:regular monitoring of inputs 8051 | 01/01/70 00:00 | |
Use a timer ? | 01/01/70 00:00 | |
Explain | 01/01/70 00:00 | |
NOT WORKING | 01/01/70 00:00 | |
instant doesn't exist | 01/01/70 00:00 | |
Make your mind up! | 01/01/70 00:00 | |
bounce | 01/01/70 00:00 | |
Sounds strange ... | 01/01/70 00:00 | |
sampling | 01/01/70 00:00 | |
Please post legible source code | 01/01/70 00:00 | |
What debounce? | 01/01/70 00:00 | |
code | 01/01/70 00:00 | |
Did you check the preview? | 01/01/70 00:00 | |
Broken code | 01/01/70 00:00 | |
indentation | 01/01/70 00:00 | |
Simulation | 01/01/70 00:00 | |
Regular | 01/01/70 00:00 | |
Why not reading from main loop? | 01/01/70 00:00 | |
PLEASE HELP | 01/01/70 00:00 | |
have a look at Rate This Post | 01/01/70 00:00 | |
Study the state machine tutorial... | 01/01/70 00:00 | |
Is it here?![]() | 01/01/70 00:00 |