+---------------+
| | +--------------------------------------------+
| | | |
| |-----------------o-->| |
| | DB0-DB7 | | |
| |--------------o--|-->| |
| | | | | LCD 1 |
| |--o----RS-----|--|-->| |
| |--|-o--R/W----|--|-->| |
| | | | | | | |
| |--|-|--EN-----|--|-->| |
| | | | | | | |
| | | | | | +--------------------------------------------+
| 89c51 | | | | |
| | | | | | +--------------------------------------------+
| | | | | | | |
| | | | | +-->| |
| | | | | | |
| | | | +----->| |
| | | | | LCD 2 |
| | +-|--RS----------->| |
| | +--R/W---------->| |
| | | |
| |-------EN----------->| |
| | | |
| | +--------------------------------------------+
+---------------+
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 #include <REGX51.H> sfr keypad = 0xB0; //port 3 sfr lcd_output = 0x90; //port 1 sbit RS = 0xA0; //port 2.0 sbit RW = 0xA1; //port 2.1 sbit EN = 0xA2; //port 2.2 void delay(unsigned int value){ unsigned int i, j; for(i=0;i<=value;i++){ for(j=0;j<=1000;j++){ } } } void lcd_cmd(unsigned char value){ lcd_output = value; RS = 0; RW = 0; EN = 1; delay(1); EN = 0; return; } void lcd_data(unsigned char value){ static int a =1; a++; if(a==17){ a=1; lcd_cmd(0x01); } lcd_output = value; RS = 1; RW = 0; EN = 1; delay(1); EN = 0; return; } void lcd_init(){ lcd_cmd(0x38); lcd_cmd(0x0C); lcd_cmd(0x80); } void main(){ unsigned char arr[4][3] = {'1','2','3', '4','5','6', '7','8','9', '*','0','#'}; unsigned int row, col; lcd_init(); while(1){ keypad=0xF0; while(keypad != 0xF0); //check for key not pressed while(keypad==0xF0); //check for key pressed if(keypad==0xE0){ //check for row 0 row = 0; keypad=0xFF; keypad=0xEF; if(keypad==0xEB) col = 0; if(keypad==0xED) col = 1; if(keypad==0xEE) col = 2; lcd_data(arr[row][col]); } else if(keypad==0xD0){ //check for row 1 row = 1; keypad=0xFF; keypad=0xDF; if(keypad==0xDB) col = 0; if(keypad==0xDD) col = 1; if(keypad==0xDE) col = 2; lcd_data(arr[row][col]); } else if(keypad==0xB0){ //check for row 2 row = 2; keypad=0xFF; keypad=0xBF; if(keypad==0xBB) col = 0; if(keypad==0xBD) col = 1; if(keypad==0xBE) col = 2; lcd_data(arr[row][col]); } else if(keypad==0x70){ //check for row 3 row = 3; keypad=0xFF; keypad=0x7F; if(keypad==0x7B) col = 0; if(keypad==0x7D) col = 1; if(keypad==0x7E) col = 2; lcd_data(arr[row][col]); } } }
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?