E có một bàn phím 4x4.
E muốn giao tiếp và hiển thị lên led 7 đoạn anh chị tư vấn giúp e với!
E đọc trên mạng nhưng chưa hiểu ?
E muốn giao tiếp và hiển thị lên led 7 đoạn anh chị tư vấn giúp e với!
E đọc trên mạng nhưng chưa hiểu ?
#include <reg52.h> #include <stdio.h> unsigned int i,j; sbit hang_0=P0^4; sbit hang_1=P0^5; sbit hang_2=P0^6; sbit hang_3=P0^7; unsigned char m_hang[4]; unsigned char dem=0,hang; /* ham hien thi.Led A chung*/ void hienthiso(unsigned char tam) { switch(tam) { case 0:{P2=0xC0;break;} case 1:{P2=0xf9;break;} case 2:{P2=0xA4;break;} case 3:{P2=0xB0;break;} case 4:{P2=0x99;break;} case 5:{P2=0x92;break;} case 6:{P2=0x82;break;} case 7:{P2=0xf8;break;} case 8:{P2=0x80;break;} case 9:{P2=0x90;break;} case 10:{P2=0x88;break;} case 11:{P2=0x83;break;} case 12:{P2=0xc6;break;} case 13:{P2=0xa1;break;} case 14:{P2=0x86;break;} case 15:{P2=0x8e;break;} } } /* ham quet phim*/ void quetphim() { int n[4]={0xfe,0xfd,0xfb,0xf7}; for(i=0;i<4;i++) { P0 = n[i]; if(hang_0==0) { dem=0*4+i; hienthiso(dem); } else if(hang_1==0) { dem=1*4+i; hienthiso(dem); } else if(hang_2==0) { dem=2*4+i; hienthiso(dem); } else if(hang_3==0) { dem=3*4+i; hienthiso(dem); } else { } } } /* chuong trinh chinh*/ void main(void) { while(1) { quetphim(); } }
#byte KeyPort = getenv("SFR:PORTD") #byte KeyTris = getenv("SFR:TRISD") #bit Col0 = KeyPort.0 #bit Col1 = KeyPort.1 #bit Col2 = KeyPort.2 #bit Col3 = KeyPort.3 #bit Row0 = KeyPort.4 #bit Row1 = KeyPort.5 #bit Row2 = KeyPort.6 #bit Row3 = KeyPort.7 unsigned int KeyCode; int1 key_pressed(void) { int1 keyhit; unsigned int i, j, temp, mask; KeyTris = 0xF0; keyhit = FALSE; mask = 0xF7; // start at column 3 for(i = 0; i < 4; i++) { KeyPort = mask; // active column 3 temp = KeyPort; // read row value if((temp & 0xF0) != 0xF0) // check key pressing status { keyhit = TRUE; for(j = 0; j < 4; j++) { if((temp & 0x10) == 0) { KeyCode = i + 4*j; break; } temp >>= 1; } break; } mask >>= 1; } //while((KeyPort & 0xF0) != 0xF0); // wait for key release return keyhit; }
#define SELECT_NONE 0xFF #byte Led7Select = getenv("SFR:PORTA") #byte Led7SelectTris = getenv("SFR:TRISA") #byte Led7Data = getenv("SFR:PORTD") #byte Led7DataTris = getenv("SFR:TRISD") volatile int1 KeyFound; int const Led7Code[18] = {0b11000000, //0 0b11111001, //1 0b10100100, //2 0b10110000, //3 0b10011001, //4 0b10010010, //5 0b10000010, //6 0b11111000, //7 0b10000000, //8 0b10010000, //9 0b10011100, // degree sign 10 0b11000110, // 'C' 11 0b11111111, // off 12 0b10000111, // 't' 13 0b10110111, // '=' 14 0b10100001, // 'd' 15 0b10100000, // 'a' 16 0b10010001 // 'y' 17 }; int const Led7Idx[6] = {0b11111110, 0b11111101, 0b11111011, 0b11110111, 0b11101111, 0b11011111}; volatile unsigned int Led7Buff[6] = {0, 1, 2, 3, 4, 5}; volatile unsigned int PointPosition, BlinkPosition; void led7_init(void) { Led7SelectTris = 0; Led7DataTris = 0; } void led7_scan(void) // point = 1: display number with point, point = 0: display number only { static int idx; static unsigned int blink_counter; static int1 enable; if(++blink_counter >= 6*12) { blink_counter = 0; enable ^= 1; } if(++idx >= 6) idx = 0; Led7Select = SELECT_NONE; // turn off all led7 first Led7Data = 0xFF; Led7DataTris = 0xF0; KeyFound = key_pressed(); Led7DataTris = 0; //if(bit_test(PointPosition, idx)) Led7Data = Led7Code[Led7Buff[idx]] & 0x7F; // number with point if((PointPosition | Led7Idx[idx]) == 0xFF) Led7Data = Led7Code[Led7Buff[idx]] & 0x7F; // number with point else Led7Data = Led7Code[Led7Buff[idx]]; if(((BlinkPosition | Led7Idx[idx]) == 0xFF) && !enable) Led7Data |= 0x7F; Led7Select = Led7Idx[idx]; }
#include <reg52.h> #include <stdio.h> unsigned int i,j; sbit hang_0=P0^4; sbit hang_1=P0^5; sbit hang_2=P0^6; sbit hang_3=P0^7; unsigned char m_hang[4]; unsigned char dem=0,hang; /* ham hien thi.Led A chung*/ void hienthiso(unsigned char tam) { switch(tam) { case 0:{P2=0xC0;break;} case 1:{P2=0xf9;break;} case 2:{P2=0xA4;break;} case 3:{P2=0xB0;break;} case 4:{P2=0x99;break;} case 5:{P2=0x92;break;} case 6:{P2=0x82;break;} case 7:{P2=0xf8;break;} case 8:{P2=0x80;break;} case 9:{P2=0x90;break;} case 10:{P2=0x88;break;} case 11:{P2=0x83;break;} case 12:{P2=0xc6;break;} case 13:{P2=0xa1;break;} case 14:{P2=0x86;break;} case 15:{P2=0x8e;break;} } } /* ham quet phim*/ void quetphim() { int n[4]={0xfe,0xfd,0xfb,0xf7}; for(i=0;i<4;i++) { P0 = n[i]; if(hang_0==0) { dem=0*4+i; hienthiso(dem); } else if(hang_1==0) { dem=1*4+i; hienthiso(dem); } else if(hang_2==0) { dem=2*4+i; hienthiso(dem); } else if(hang_3==0) { dem=3*4+i; hienthiso(dem); } else { } } } /* chuong trinh chinh*/ void main(void) { while(1) { quetphim(); } }
Comment