Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.
//The scan result of the button and the button satisfies the following relationship:
/ / button scan results (result) button scan results
//K100XE7K180XB7
//K110XEBK190XBB
//K120XEDK200XBD
//K130XEEK210XBE
//K140XD7K220X77
//K150XDBK230X7B
//K160XDDK240X7D
//K170XDEK250X7E
#include
__CONFIG(0x1832);
/ / Chip configuration word, watchdog off, power-on delay on, power-down detection off, low-voltage programming off, encryption, 4M crystal HS oscillation
Intresult;
Voiddelay();//delay function declaration
Voidinit();//I/O port initialization function declaration
voidsCAN();//Keystroke Scanner Declaration
Voiddisplay(intx);//Display function declaration
//------------------------------------------------ ---
/ / Main program
Voidmain()
{
While(1)//loop work
{
Init();//call initialization subroutine
Scan();//call button scan subroutine
Display(result);//call result display subroutine
}
}
//------------------------------------------------ ---
/ / initialization function
Voidinit()
{
ADCON1=0X07;//Set A port to normal I/O port
TRISA=0X0f; / / set the A port high 2 bits for the output, the lower 4 bits for the input
TRISC=0XF0; / / set C port high 4 bits for input, low 4 bits for output
TRISD=0X00; / / set D port as output
PORTA=0XFF;
PORTD=0XFF; / / clear all displays first
}
//------------------------------------------------ ---
/ / button scan program
Voidscan()
{
PORTC=0XF7; / / C3 output low level, the other three bits output high level
Asm("nop");//Insert a certain delay to ensure stable levels
Result=PORTC;//Read back C port high 4 results
Result=result&0xf0;//Clear the lower 4 bits
If (result! = 0xf0) / / determine whether the high 4 is all 1 (all 1 means no button press)?
{
Result=result|0x07;//No, plus the lower 4 bits 0x07, as a result of the key scan
}
Else / / Yes, change the low 4 bit output, re-determine whether there is a button press
{
PORTC=0XFb; / / C2 output low level, the other three bits output high level
Asm("nop");//Insert a certain delay to ensure stable levels
Result=PORTC;//Read back C port high 4 results
Result=result&0xf0;//Clear the lower 4 bits
If(result!=0xf0)//Check if the high 4 digits are all 1 (all 1 means no button press)
{
Result=result|0x0b;//No, plus the lower 4 bits 0xb, as a result of the key scan
}
Else / / Yes, change the low 4 bit output, rescan
{
PORTC=0XFd; / / C1 output low level, the other three bits output high level
Asm("nop");//Insert a certain delay to ensure stable levels
Result=PORTC;//Read back C port high 4 results
Result=result&0xf0;//Clear the lower 4 bits
If(result!=0xf0)//Check if the high 4 digits are all 1 (all 1 means no button press)
{
Result=result|0x0d;//No, plus the lower 4 bits 0x0d, as a result of the key scan
}
Else / / Yes, change the output of the lower 4 bits, rescan
{
PORTC=0XFe; / / C0 output low level, the other three bits output high level
Asm("nop");//Insert a certain delay to ensure stable levels
Result=PORTC;//Read back C port high 4 results
Result=result&0xf0;//Clear the lower 4 bits
If(result!=0xf0)//Check if the upper four digits are all 1 (all 1 means no button press)
{
Result=result|0x0e;//No, plus the lower 4 bits 0x0e, as a result of the key scan
}
Else / / Yes, all button scan ends, no button press, no button press flag
{
Result=0xff;//The scan result is 0xff, as a flag without button press
}
}
}
}
}
//------------------------------------------------ ----------
/ / Display program
Voiddisplay(intx)
{
Switch(result)
{
Case0xe7:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0xc0;PORTA=0X1F;delay();break;//K10
Case0xeb:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0xf9;PORTA=0X1F;delay();break;//K11
Case0xed:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0xa4;PORTA=0X1F;delay();break;//K12
Case0xee:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0xb0;PORTA=0X1F;delay();break;//K13
Case0xd7:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0x99;PORTA=0X1F;delay();break;//K14
Case0xdb:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0x92;PORTA=0X1F;delay();break;//K15
Case0xdd:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0X82;PORTA=0X1F;delay();break;//K16
Case0xde:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0XF8;PORTA=0X1F;delay();break;//K17
Case0xb7:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0X80;PORTA=0X1F;delay();break;//K18
Case0xbb:
PORTD=0xf9;PORTA=0X2F;delay();PORTD=0X90;PORTA=0X1F;delay();break;//K19
Case0xbd:
PORTD=0xa4;PORTA=0X2F;delay();PORTD=0xc0;PORTA=0X1F;delay();break;//K20
Case0xbe:
PORTD=0xa4;PORTA=0X2F;delay();PORTD=0xf9;PORTA=0X1F;delay();break;//K21
Case0x77:
PORTD=0xa4;PORTA=0X2F;delay();PORTD=0xa4;PORTA=0X1F;delay();break;//K22
Case0x7b:
PORTD=0xa4;PORTA=0X2F;delay();PORTD=0xb0;PORTA=0X1F;delay();break;//K23
Case0x7d:
PORTD=0xa4;PORTA=0X2F;delay();PORTD=0x99;PORTA=0X1F;delay();break;//K24
Case0x7e:
PORTD=0xa4;PORTA=0X2F;delay();PORTD=0x92;PORTA=0X1F;delay();break;//K25
Case0xff:
PORTD=0x8e;PORTA=0X2F;delay();PORTD=0x8e;PORTA=0X1F;delay();//no button press
}
}
//------------------------------------------------ ------------------
/ / delay program
Voiddelay()//delay program
{
Inti; / / define the shaping variable
For(i=0x100;i--;);//delay
}
November 16, 2024
September 18, 2023
June 28, 2024
June 28, 2024
이 업체에게 이메일로 보내기
November 16, 2024
September 18, 2023
June 28, 2024
June 28, 2024
Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.
Fill in more information so that we can get in touch with you faster
Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.